TS math: minCharmWadAt / maxCharmWadAt missing ref==0 guard that the contract has (#61/#73 parity gap) #109
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#109
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
P3-low parity gap:
frontend/src/lib/timeCurveMath.tsminCharmWadAt,maxCharmWadAt,minCharmWadAtFloat, andmaxCharmWadAtFloatdivide bycharmEnvelopeRefWadwithout theref == 0defensive guard thatTimeCurve._charmBoundshas. A 0n input throwsRangeError: Division by zeroin JS, where the contract returns(CHARM_MIN_BASE_WAD, CHARM_MAX_BASE_WAD)defensively per #61 and #73.The contract guard
contracts/src/TimeCurve.sol:348-358:The TS mirrors
frontend/src/lib/timeCurveMath.ts:56-69:Same missing guard in
minCharmWadAtFloat(line 115) andmaxCharmWadAtFloat(line 124).Why it does not currently crash users
External callers wrap in
try/catch. ExampleTimeCurveSimplePage.tsx:131-148:The bare
catchsilently swallows theRangeErrorand falls back to a non-throwing path. So no current user impact — but:frontend/src/lib/timeCurveMath.test.tsdoes not exercise theref === 0npath.Suggested fix
Add the
ref === 0nguard at the top of all four functions, mirroring the contract:Add regression tests:
Severity
P3-low. Not user-facing today (try/catch saves us). Defensive parity gap with documented contract behavior. Per 4/29 standing rule on aggressive filing.
Acceptance
minCharmWadAt,maxCharmWadAt,minCharmWadAtFloat,maxCharmWadAtFloat) guard againstcharmEnvelopeRefWad === 0nand return the staticCHARM_*_BASE_WADconstants.ref === 0npath for each function.cc @PlasticDigits
mentioned in commit
28d6c8f50amentioned in commit
f6d907ffedImplemented GitLab #109 on
main(commitdb00da4mergesfix/gl109-ts-charm-bounds-ref-zero).What changed
frontend/src/lib/timeCurveMath.ts:minCharmWadAt,maxCharmWadAt,minCharmWadAtFloat,maxCharmWadAtFloatreturnCHARM_MIN_BASE_WAD/CHARM_MAX_BASE_WADwhencharmEnvelopeRefWad === 0n, matchingTimeCurve._charmBoundsfor degenerateinitialMinBuy(#61 / #73).frontend/src/lib/timeCurveMath.test.ts: four regression tests (one per helper).#ts-charm-envelope-ref-zero-issue-109indocs/testing/invariants-and-business-logic.md; contributor guardrails item 19 extended; player skills crosslinks inskills/README.mdandskills/script-with-timecurve-local/SKILL.md.Verification checklist for @brouie
cd frontend && npx vitest run src/lib/timeCurveMath.test.ts— all 8 tests pass (includes new ref-zero block).minCharmWadAt/maxCharmWadAt/*Float— early return on0nmatches contract base envelope constants.docs/testing/invariants-and-business-logic.md#ts-charm-envelope-ref-zero-issue-109.0nref in a quick REPL — noRangeError: Division by zero.Leaving issue open for your sign-off.
Verification PASS on
db00da4All acceptance items verified.
Items
[✓] Test suite passes —
npx vitest run src/lib/timeCurveMath.test.ts→ 8/8 PASS in 4ms (matches expected count: 4 new ref-zero tests + existing).[✓] Source-side parity confirmed — All 4 helpers in
frontend/src/lib/timeCurveMath.tsearly-return oncharmEnvelopeRefWad === 0n:minCharmWadAt(line 56) — guard at line 62, returnsCHARM_MIN_BASE_WADmaxCharmWadAt(line 69) — guard at line 74, returnsCHARM_MAX_BASE_WADminCharmWadAtFloat(line 122) — guard at line 127, returnsCHARM_MIN_BASE_WADmaxCharmWadAtFloat(line 134) — guard at line 139, returnsCHARM_MAX_BASE_WADComment at line 61 explicitly cites parity with
TimeCurve._charmBoundsand #61 / #73. Each function returns the static base constant, nomulDiv/ division reached on the zero path. JSRangeError: Division by zerono longer reachable.[✓] Doc anchor resolves —
docs/testing/invariants-and-business-logic.mdline 463 has anchor<a id="ts-charm-envelope-ref-zero-issue-109">plus full invariant row cross-linking_charmBoundsparity (#61 / #73) and ERC1967 proxy reminder.[✓] Skip REPL — guard behavior is deterministic from source read; tests already exercise the
0npath for all 4 helpers.cc @PlasticDigits