Fix buyWithCred epoch CRED pool accrual (#311) #491
No reviewers
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:open_issues
agents
agent:security_audit
agent:verify
area
timecurve
arena
arena-v2
audit
block:feature_review
block:security
bug
contracts
design
devops
docs
documentation
enhancement
epic
feature
frontend
indexer
low priority
megaeth
operations
ops
performance
QA
qa checklist
referrals
removal
security
smart-contracts
tech-debt
testing
time-arena
timecurve
visual-qa
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
code/yieldomega!491
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/issue-311-buywithcred-epoch-pool"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
buyWithCrednow calls_accrueCharmAndCred(with zero referral hash) so each CRED buy addsCRED_PER_BUY(35e18) toepochCredPool[epoch], matching DOUB buy economics._accrueCharmOnly; CHARM weight accrual unchanged in intent.INV-TIME-ARENA-CRED-NO-POOLwithINV-TIME-ARENA-CRED-POOL-ACCRUEin invariants doc.verify-cred-buy-anvil.shwith on-chainepochCredPoolassertion (+35 CRED after firstbuyWithCred); corrected starter-buy level expectation (10 CHARM → level 2).Verification checklist
buyWithCredadds 35 CRED toepochCredPool[epoch]forge test --match-test test_buy_with_credpoolBefore + 35e18forge test --match-test cred(19 tests)claimCredpro-rata fair for mixed DOUB/CRED buyersforge test --match-test test_cred_pro_rata_mixed_doub_and_cred_buyersCRED-NO-POOLreviseddocs/testing/invariants-and-business-logic.mdINV-TIME-ARENA-CRED-POOL-ACCRUEbuyWithCredforge test --match-test "cred|buy_with_cred|buyWithCred"verify-cred-buy-anvil.shbash scripts/verify-cred-buy-anvil.sh=== verify-cred-buy-anvil: OK ===)forge test --match-test test_cred_accrue_on_doub_buytest_cred_pro_rata_mixed_doub_and_cred_buyerstest_buyWithCred_epoch_boundary_credits_correct_poolforge test --match-test test_claimCred_cannot_double_claimcd indexer && cargo testepochCredPoolchanged the description
changed the description
Security review —
34c8c13dScope: MR !491 —
buyWithCredepoch CRED pool accrual (#311). Reviewed diff inTimeArena.sol(_buyCred→_accrueCharmAndCred), new Forge tests, invariants doc, andverify-cred-buy-anvil.sh.Method: Traced attacker-controlled inputs (
charmWad, buyer address, epoch) through_buyCred→_accrueCharmAndCred→epochCredPool/epochCharmWad→claimCred(playCred.mint). Compared against DOUB path (_buyDoub). Re-checked referral branch (bytes32(0)skips mint), reentrancy (nonReentrant, burn-before-accrue, mint-after-zeroing), epoch-boundary pool assignment, and mixed-buyer pro-rata economics.Outcome: FINDINGS: 0 medium+
Security review: no medium+ findings on this diff.
Notes (informational, below threshold):
buyWithCredaccrued epoch CHARM weight without addingCRED_PER_BUYtoepochCredPool, letting CRED buyers dilute DOUB-funded pro-rata claims. The fix aligns CRED accrual with the DOUB path;claimCredstill mints from a virtual pool with per-epoch weight accounting and double-claim guards unchanged.bytes32(0)referral hash correctly prevents self-service referral CRED mint on the CRED rail.Inline threads: none
added 100 commits
main7fffda61- Merge origin/main into fix/issue-311-buywithcred-epoch-poolCompare with previous version
Resolved merge conflicts with
mainin 4 files:contracts/src/arena/TimeArena.sol— kept main's_applyBuyWarBowBpsignature (prevDsBuyer/prevDsStreakfor defended-streak WarBow BP).contracts/test/TimeArena.t.sol— kept main's expanded #311 test suite (pool accrual, mixed pro-rata, epoch-boundary, fair-share).docs/testing/invariants-and-business-logic.md— alignedINV-TIME-ARENA-CRED-POOL-ACCRUEevidence list with main.scripts/verify-cred-buy-anvil.sh— kept delta-basedepochCredPoolassertion; dropped duplicate absolute pool check.Sanity:
forge test --match-test "cred|buy_with_cred|buyWithCred"— 25 passed.changed the description
Security review —
7fffda6109c7252debe41fa5437b1e6ebe725358Scope: MR !491 —
buyWithCredepoch CRED pool accrual (#311). Re-reviewed after merge withmain(7fffda61). Focused diff:TimeArena._buyCrednow calls_accrueCharmAndCred(buyer, charmWad, bytes32(0))(removes_accrueCharmOnly), plus Forge tests, invariants doc, andverify-cred-buy-anvil.shpool-delta assertion.Method: Traced attacker-controlled inputs (
charmWad,msg.sender,lastBuyEpoch) through_buyCred→playCred.burn→_accrueCharmAndCred→epochCredPool/epochCharmWad→claimCred(playCred.mint). Compared parity with DOUB_buyDoubpath. Re-checked post-merge conflict resolution inTimeArena.sol(WarBow BP signature unchanged; pool accrual line preserved). Verified referral branch (codeHash == 0skips mint), reentrancy (nonReentrant, burn-before-accrue, claim zeroes weight before mint), epoch-boundary pool assignment (_accrueCharmAndCredbefore_finishBuyhard-reset — same ordering as DOUB), and mixed-buyer / CRED-only pro-rata economics (test_cred_pro_rata_mixed_doub_and_cred_buyers,test_cred_only_buyer_fair_share).Outcome: FINDINGS: 0 medium+
Security review: no medium+ findings on this diff.
Notes (informational, below threshold):
buyWithCredaccrued epoch CHARM weight without creditingepochCredPool, allowing CRED buyers to dilute DOUB-funded pro-rata claims. The fix mirrors DOUB economics (CRED_PER_BUYper buy);claimCredmint authority and double-claim guards are unchanged.bytes32(0)referral hash correctly prevents unsolicited referral CRED mint on the CRED rail.Inline threads: none
mentioned in commit
1b4f62603a