fix(arena): accrue epoch CRED pool on buyWithCred buys (#311) #479
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!479
Loading…
Reference in a new issue
No description provided.
Delete branch "local1/311-verify-cred-pool-accrue"
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 zerocodeHash) so each CRED buy adds 35 CRED (CRED_PER_BUY) toepochCredPool[lastBuyEpoch]while still burning player CRED.pending_credpreview counts all epoch buys (DOUB + CRED); frontend optimistic preview aligned.INV-TIME-ARENA-CRED-NO-POOLwithINV-TIME-ARENA-CRED-POOL-ACCRUE; updated product docs, play skill, and Anvil smoke (verify-cred-buy-anvil.sh).Acceptance checklist
buyWithCredadds 35 CRED toepochCredPool[epoch]forge test --match-test test_buy_with_credforge test --match-test test_xp_buy_with_cred_same_as_doubclaimCredpro-rata fair for mixed DOUB/CRED buyersforge test --match-test test_buyWithCred_mixed_pro_rata_with_doubCRED-NO-POOLremoveddocs/testing/invariants-and-business-logic.md→INV-TIME-ARENA-CRED-POOL-ACCRUEtest_buy_with_cred,test_cred_only_buyer_fair_shareverify-cred-buy-anvil.shbash scripts/verify-cred-buy-anvil.shforge test --match-test test_cred_accrue_on_doub_buycd indexer && cargo test arena_wallet_statstest_cred_only_buyer_fair_sharetest_buyWithCred_at_epoch_boundarytest_claimCred_cannot_double_claimTest plan
changed the description
changed the description
Security review — MR !479
Commit reviewed:
7d862aafa1db0a44eb185681f39753d39694c0d5Scope:
buyWithCred→_accrueCharmAndCred(epoch CRED pool accrual), related Forge tests, indexerpending_cred/epoch_buy_count, frontend optimistic CRED preview,verify-cred-buy-anvil.sh, docs/skills.Outcome: FINDINGS: 0 medium+
Summary
Reviewed the on-chain CRED pool economics, claim path, reentrancy/ordering, and off-chain preview/indexer changes introduced by this diff. No prior security-review threads on this MR.
On-chain (
TimeArena._buyCred):buyWithCredstill burnscredBurn = mulDiv(charmWad, CRED_PER_CHARM_WAD, WAD)before state updates, passesbytes32(0)(no referral mint path), and remainsnonReentrant. Pool accrual is a fixedCRED_PER_BUY(35e18) per buy intoepochCredPool[lastBuyEpoch];claimCredmints pro-rata byepochCharmWad / epochCharmTotalwith one-shot weight zeroing (unchanged). For a sole 1 CHARM CRED buyer, max pro-rata recovery is 35 CRED against a 100 CRED burn; mixed-epoch and CRED-only fair-share cases are covered by new Forge tests (test_cred_only_buyer_fair_share,test_buyWithCred_mixed_pro_rata_with_doub,test_buyWithCred_at_epoch_boundary). No plausible path to mint more than fair pool share, double-claim, or reenter viaPlayCred(non-transferable, no hooks).Off-chain (indexer + frontend): SQL still parameterized;
epoch_buyscount change only affectspending_credpreview/display, not claim execution (on-chainclaimCred/pendingCredare authoritative). No injection, authz, SSRF, or XSS surface in the modified paths.Inline threads: none (no medium+ findings).
Security review: no medium+ findings on this diff.
added 61 commits
main6dda9097- Merge origin/main into local1/311-verify-cred-pool-accrueCompare with previous version
Resolved merge conflicts with
main(merge commit6dda9097).Conflicts resolved
TimeArena.sol— kept main's_applyBuyWarBowBpsignature (prevDsBuyer/prevDsStreakfor #310 ambush BP).TimeArena.t.sol— merged CRED pool test coverage from both branches (accrue, mixed pro-rata, epoch roll, hard-reset boundary, fair-share claim).INV-TIME-ARENA-CRED-POOL-ACCRUEwith combined test list; keptFIRST_BUY_CRED_BONUS = 1100e18from main (#299).verify-cred-buy-anvil.sh— keptcast_u256helper; main's pool-delta assertion message.Sanity checks
forge test --match-contract TimeArenaTest— 102 passedcargo test arena_wallet_stats— passednpm run typecheck+arenaWalletXpOptimistic.test.ts— passedchanged the description
Security review — MR !479
Commit reviewed:
6dda90975b2407b117817eb5deb65a49ddb378c2Scope: Re-review after merge with
main. Current diff vs03a43d4a: Forge test consolidation, indexerepoch_buys/pending_credpreview, frontend optimistic CRED preview (arenaWalletXpOptimistic.ts), docs/invariants,verify-cred-buy-anvil.sh. On-chainbuyWithCred→_accrueCharmAndCred(epoch pool +35 CRED per buy) is already onmainviafix/311-cred-buy-epoch-pool; verified at HEAD inTimeArena._buyCred.Outcome: FINDINGS: 0 medium+
Summary
Re-reviewed prior thread (
7d862aaf) against post-merge HEAD. No new attack surface in the incremental diff; on-chain economics at HEAD unchanged in intent from the earlier review.On-chain (
TimeArena._buyCred):buyWithCredburnscredBurn = mulDiv(charmWad, CRED_PER_CHARM_WAD, WAD)before_accrueCharmAndCred, passesbytes32(0)(no referral mint), and remainsnonReentrant. Pool accrual is fixedCRED_PER_BUY(35e18) intoepochCredPool[lastBuyEpoch];claimCredpro-rata mint is unchanged (mulDiv(pool, weight, total)with one-shot weight zeroing). A sole 1 CHARM CRED buyer recovers at most 35 CRED against a 100 CRED burn; mixed DOUB/CRED pro-rata, epoch-boundary pool routing, and fair-share bounds are covered by Forge tests (test_cred_only_buyer_fair_share,test_buyWithCred_mixed_pro_rata_with_doub,test_buyWithCred_at_epoch_boundary).PlayCredis non-transferable ERC20 with minter-only burn/mint — no external hooks or reentrancy sink. This change closes the pre-#311 asymmetry where CRED buyers accrued CHARM weight without adding toepochCredPool(diluting DOUB-funded claims); no path to over-mint pool share, double-claim, or referral abuse.Off-chain (indexer + frontend): SQL remains parameterized (
$1wallet,$2epoch);COUNT(*)onidx_arena_buyonly affectspending_cred_accrualdisplay/preview — claim execution stays on-chain (claimCred/pendingCred). No injection, authz bypass, SSRF, or XSS in modified paths.Inline threads: none (no medium+ findings).
Security review: no medium+ findings on this diff.
approved this merge request
mentioned in commit
08492fd892