SIG-598: add Echidna coverage for FixedPointMathU, ClmsrMath, FeeWaterfallLib#64
Conversation
…eWaterfallLib Add three Echidna property-test adapters to verification/foundry: - EchidnaFixedPointMath: 19 properties covering arithmetic ordering, exp/ln roundtrips, monotonicity, conversion bounds, and revert guards - EchidnaClmsrMath: 9 properties covering execute-first buy/sell/roundtrip, sum monotonicity, pure cost helpers, and LP-favored rounding - EchidnaFeeWaterfallLib: 7 properties covering fee conservation, NAV equation, grant bounds, treasury monotonicity, and reference parity Per-contract configs with isolated corpus directories. Updated numeric-proof.sh and README.md.
There was a problem hiding this comment.
Summary
This PR adds three new Echidna coverage-guided fuzzing targets for FixedPointMathU (19 properties), ClmsrMath (9 properties), and FeeWaterfallLib (7 properties). Each target operates in isolation with its own config and corpus directory. The targets exercise arithmetic ordering, roundtrip properties, monotonicity, conservation laws, and reference-parity checks. Production code is unchanged — all additions are in verification/foundry/.
Issues
No issues found.
Suggestions
No suggestions.
Verdict
APPROVE: The three Echidna targets are well-constructed. Specific technical observations:
-
Input bounding is correct across all three contracts.
EchidnaClmsrMath._boundQuantityusesmaxSafeChunkQuantity(alpha)to preventFP_Overflowfrom_safeExp.EchidnaFeeWaterfallLib._boundValidParamsadjustsdeltaEtandBprevupward to satisfy theGrantExceedsTailBudgetandInsufficientBackstopForGrantguards, and capsabsLtatNprev + Ftotto preventCatastrophicLoss.EchidnaFixedPointMathbounds all inputs to their valid domains (e.g.,storedExpLnXin[WAD, MAX_EXP_INPUT_WAD]). -
Error handling in
_handleClmsrRevertcatchesFP_DivisionByZeroandMathMulOverflow(both can originate fromLazyMulSegmentTreeandFixedPointMathU). Other error selectors (FP_Overflow,FP_InvalidInput) are not caught — this is correct because input bounding should prevent them, and if they somehow fire, they should be flagged as unexpected reverts. -
Drift tolerances (
DRIFT_TOLERANCE_WAD_WEI = 1e12,REL_DRIFT_DENOM = 1e12) yield a combined tolerance of ~1e12 + baseline/1e12 wei. For a typicallastRoundtripCostof 1e18 (1 WAD), the tolerance is ~1e12 + 1e6 ≈ 1e12 wei — about 1e-6 WAD ($0.000001). This is tight enough to catch genuine precision regressions while accommodatingwDivUp(buy) vswDiv(sell) rounding asymmetry. -
FeeWaterfallLib reference parity runs both the production
FeeWaterfallLibHarnessandFeeWaterfallReferenceinexecuteCalculate, asserting exact equality across all 10 output fields — this is the strongest possible correctness check. -
No cross-repo impact. All changes are under
verification/foundry/(test-only). No ABI, event, or interface changes. No downstream repos need updates.
There was a problem hiding this comment.
Summary
This PR adds three new Echidna coverage-guided fuzzing targets for FixedPointMathU (19 properties), ClmsrMath (9 properties), and FeeWaterfallLib (7 properties). Each target operates in isolation with its own config and corpus directory. The targets exercise arithmetic ordering, roundtrip properties, monotonicity, conservation laws, and reference-parity checks. Production code is unchanged — all additions are in verification/foundry/.
Issues
No issues found.
Suggestions
No suggestions.
Verdict
APPROVE: The three Echidna targets are well-constructed. Specific technical observations:
-
Input bounding is correct across all three contracts.
EchidnaClmsrMath._boundQuantityusesmaxSafeChunkQuantity(alpha)to preventFP_Overflowfrom_safeExp.EchidnaFeeWaterfallLib._boundValidParamsadjustsdeltaEtandBprevupward to satisfy theGrantExceedsTailBudgetandInsufficientBackstopForGrantguards, and capsabsLtatNprev + Ftotto preventCatastrophicLoss.EchidnaFixedPointMathbounds all inputs to their valid domains (e.g.,storedExpLnXin[WAD, MAX_EXP_INPUT_WAD]). -
Error handling in
_handleClmsrRevertcatchesFP_DivisionByZeroandMathMulOverflow(both can originate fromLazyMulSegmentTreeandFixedPointMathU). Other error selectors (FP_Overflow,FP_InvalidInput) are not caught — this is correct because input bounding should prevent them, and if they somehow fire, they should be flagged as unexpected reverts. -
Drift tolerances (
DRIFT_TOLERANCE_WAD_WEI = 1e12,REL_DRIFT_DENOM = 1e12) yield a combined tolerance of ~1e12 + baseline/1e12 wei. For a typicallastRoundtripCostof 1e18 (1 WAD), the tolerance is ~1e12 + 1e6 ≈ 1e12 wei — about 1e-6 WAD ($0.000001). This is tight enough to catch genuine precision regressions while accommodatingwDivUp(buy) vswDiv(sell) rounding asymmetry. -
FeeWaterfallLib reference parity runs both the production
FeeWaterfallLibHarnessandFeeWaterfallReferenceinexecuteCalculate, asserting exact equality across all 10 output fields — this is the strongest possible correctness check. -
No cross-repo impact. All changes are under
verification/foundry/(test-only). No ABI, event, or interface changes. No downstream repos need updates.
There was a problem hiding this comment.
Summary
This PR adds three new Echidna coverage-guided fuzzing targets for FixedPointMathU (19 properties), ClmsrMath (9 properties), and FeeWaterfallLib (7 properties). Each target operates in isolation with its own config and corpus directory. The targets exercise arithmetic ordering, roundtrip properties, monotonicity, conservation laws, and reference-parity checks. Production code is unchanged — all additions are in verification/foundry/.
Issues
No issues found.
Suggestions
No suggestions.
Verdict
APPROVE: The three Echidna targets are well-constructed. Specific technical observations:
-
Input bounding is correct across all three contracts.
EchidnaClmsrMath._boundQuantityusesmaxSafeChunkQuantity(alpha)to preventFP_Overflowfrom_safeExp.EchidnaFeeWaterfallLib._boundValidParamsadjustsdeltaEtandBprevupward to satisfy theGrantExceedsTailBudgetandInsufficientBackstopForGrantguards, and capsabsLtatNprev + Ftotto preventCatastrophicLoss.EchidnaFixedPointMathbounds all inputs to their valid domains (e.g.,storedExpLnXin[WAD, MAX_EXP_INPUT_WAD]). -
Error handling in
_handleClmsrRevertcatchesFP_DivisionByZeroandMathMulOverflow(both can originate fromLazyMulSegmentTreeandFixedPointMathU). Other error selectors (FP_Overflow,FP_InvalidInput) are not caught — this is correct because input bounding should prevent them, and if they somehow fire, they should be flagged as unexpected reverts. -
Drift tolerances (
DRIFT_TOLERANCE_WAD_WEI = 1e12,REL_DRIFT_DENOM = 1e12) yield a combined tolerance of ~1e12 + baseline/1e12 wei. For a typicallastRoundtripCostof 1e18 (1 WAD), the tolerance is ~1e12 + 1e6 ≈ 1e12 wei — about 1e-6 WAD ($0.000001). This is tight enough to catch genuine precision regressions while accommodatingwDivUp(buy) vswDiv(sell) rounding asymmetry. -
FeeWaterfallLib reference parity runs both the production
FeeWaterfallLibHarnessandFeeWaterfallReferenceinexecuteCalculate, asserting exact equality across all 10 output fields — this is the strongest possible correctness check. -
No cross-repo impact. All changes are under
verification/foundry/(test-only). No ABI, event, or interface changes. No downstream repos need updates.
There was a problem hiding this comment.
Summary
This PR adds three new Echidna coverage-guided fuzzing targets for FixedPointMathU (19 properties), ClmsrMath (9 properties), and FeeWaterfallLib (7 properties). Each target operates in isolation with its own config and corpus directory. The targets exercise arithmetic ordering, roundtrip properties, monotonicity, conservation laws, and reference-parity checks. Production code is unchanged — all additions are in verification/foundry/.
Issues
No issues found.
Suggestions
No suggestions.
Verdict
APPROVE: The three Echidna targets are well-constructed. Specific technical observations:
-
Input bounding is correct across all three contracts.
EchidnaClmsrMath._boundQuantityusesmaxSafeChunkQuantity(alpha)to preventFP_Overflowfrom_safeExp.EchidnaFeeWaterfallLib._boundValidParamsadjustsdeltaEtandBprevupward to satisfy theGrantExceedsTailBudgetandInsufficientBackstopForGrantguards, and capsabsLtatNprev + Ftotto preventCatastrophicLoss.EchidnaFixedPointMathbounds all inputs to their valid domains (e.g.,storedExpLnXin[WAD, MAX_EXP_INPUT_WAD]). -
Error handling in
_handleClmsrRevertcatchesFP_DivisionByZeroandMathMulOverflow(both can originate fromLazyMulSegmentTreeandFixedPointMathU). Other error selectors (FP_Overflow,FP_InvalidInput) are not caught — this is correct because input bounding should prevent them, and if they somehow fire, they should be flagged as unexpected reverts. -
Drift tolerances (
DRIFT_TOLERANCE_WAD_WEI = 1e12,REL_DRIFT_DENOM = 1e12) yield a combined tolerance of ~1e12 + baseline/1e12 wei. For a typicallastRoundtripCostof 1e18 (1 WAD), the tolerance is ~1e12 + 1e6 ≈ 1e12 wei — about 1e-6 WAD ($0.000001). This is tight enough to catch genuine precision regressions while accommodatingwDivUp(buy) vswDiv(sell) rounding asymmetry. -
FeeWaterfallLib reference parity runs both the production
FeeWaterfallLibHarnessandFeeWaterfallReferenceinexecuteCalculate, asserting exact equality across all 10 output fields — this is the strongest possible correctness check. -
No cross-repo impact. All changes are under
verification/foundry/(test-only). No ABI, event, or interface changes. No downstream repos need updates.
There was a problem hiding this comment.
Summary
This PR adds three new Echidna coverage-guided fuzzing targets for FixedPointMathU (19 properties), ClmsrMath (9 properties), and FeeWaterfallLib (7 properties). Each target operates in isolation with its own config and corpus directory. The targets exercise arithmetic ordering, roundtrip properties, monotonicity, conservation laws, and reference-parity checks. Production code is unchanged — all additions are in verification/foundry/.
Issues
No issues found.
Suggestions
No suggestions.
Verdict
APPROVE: The three Echidna targets are well-constructed. Specific technical observations:
-
Input bounding is correct across all three contracts.
EchidnaClmsrMath._boundQuantityusesmaxSafeChunkQuantity(alpha)to preventFP_Overflowfrom_safeExp.EchidnaFeeWaterfallLib._boundValidParamsadjustsdeltaEtandBprevupward to satisfy theGrantExceedsTailBudgetandInsufficientBackstopForGrantguards, and capsabsLtatNprev + Ftotto preventCatastrophicLoss.EchidnaFixedPointMathbounds all inputs to their valid domains (e.g.,storedExpLnXin[WAD, MAX_EXP_INPUT_WAD]). -
Error handling in
_handleClmsrRevertcatchesFP_DivisionByZeroandMathMulOverflow(both can originate fromLazyMulSegmentTreeandFixedPointMathU). Other error selectors (FP_Overflow,FP_InvalidInput) are not caught — this is correct because input bounding should prevent them, and if they somehow fire, they should be flagged as unexpected reverts. -
Drift tolerances (
DRIFT_TOLERANCE_WAD_WEI = 1e12,REL_DRIFT_DENOM = 1e12) yield a combined tolerance of ~1e12 + baseline/1e12 wei. For a typicallastRoundtripCostof 1e18 (1 WAD), the tolerance is ~1e12 + 1e6 ≈ 1e12 wei — about 1e-6 WAD ($0.000001). This is tight enough to catch genuine precision regressions while accommodatingwDivUp(buy) vswDiv(sell) rounding asymmetry. -
FeeWaterfallLib reference parity runs both the production
FeeWaterfallLibHarnessandFeeWaterfallReferenceinexecuteCalculate, asserting exact equality across all 10 output fields — this is the strongest possible correctness check. -
No cross-repo impact. All changes are under
verification/foundry/(test-only). No ABI, event, or interface changes. No downstream repos need updates.
There was a problem hiding this comment.
Summary
This PR adds three new Echidna coverage-guided fuzzing targets for FixedPointMathU (19 properties), ClmsrMath (9 properties), and FeeWaterfallLib (7 properties). Each target operates in isolation with its own config and corpus directory. The targets exercise arithmetic ordering, roundtrip properties, monotonicity, conservation laws, and reference-parity checks. Production code is unchanged — all additions are in verification/foundry/.
Issues
No issues found.
Suggestions
No suggestions.
Verdict
APPROVE: The three Echidna targets are well-constructed. Specific technical observations:
-
Input bounding is correct across all three contracts.
EchidnaClmsrMath._boundQuantityusesmaxSafeChunkQuantity(alpha)to preventFP_Overflowfrom_safeExp.EchidnaFeeWaterfallLib._boundValidParamsadjustsdeltaEtandBprevupward to satisfy theGrantExceedsTailBudgetandInsufficientBackstopForGrantguards, and capsabsLtatNprev + Ftotto preventCatastrophicLoss.EchidnaFixedPointMathbounds all inputs to their valid domains (e.g.,storedExpLnXin[WAD, MAX_EXP_INPUT_WAD]). -
Error handling in
_handleClmsrRevertcatchesFP_DivisionByZeroandMathMulOverflow(both can originate fromLazyMulSegmentTreeandFixedPointMathU). Other error selectors (FP_Overflow,FP_InvalidInput) are not caught — this is correct because input bounding should prevent them, and if they somehow fire, they should be flagged as unexpected reverts. -
Drift tolerances (
DRIFT_TOLERANCE_WAD_WEI = 1e12,REL_DRIFT_DENOM = 1e12) yield a combined tolerance of ~1e12 + baseline/1e12 wei. For a typicallastRoundtripCostof 1e18 (1 WAD), the tolerance is ~1e12 + 1e6 ≈ 1e12 wei — about 1e-6 WAD ($0.000001). This is tight enough to catch genuine precision regressions while accommodatingwDivUp(buy) vswDiv(sell) rounding asymmetry. -
FeeWaterfallLib reference parity runs both the production
FeeWaterfallLibHarnessandFeeWaterfallReferenceinexecuteCalculate, asserting exact equality across all 10 output fields — this is the strongest possible correctness check. -
No cross-repo impact. All changes are under
verification/foundry/(test-only). No ABI, event, or interface changes. No downstream repos need updates.
Context
Echidna coverage-guided fuzzing was limited to
LazyMulSegmentTreeonly, leaving three numeric-critical libraries (FixedPointMathU,ClmsrMath,FeeWaterfallLib) without coverage-guided property testing. Thenumeric-security-spec.mdlists Echidna as a mandatory gate, but no targets were defined beyond the segment tree. Linked to SIG-598.Decisions
EchidnaLazyMulTree— each library has distinct input domains and property sets that benefit from isolated corpus evolutionFixedPointMathUusesseqLen: 1(stateless pure functions) whileClmsrMathandFeeWaterfallLibuseseqLen: 100(stateful sequence exploration)EchidnaFeeWaterfallLibruns both the productionFeeWaterfallLibHarnessand theFeeWaterfallReferenceimplementation, asserting parity across all 10 output fieldsEchidnaClmsrMathuses the existingClmsrMathCostHarnessandLazyMulSegmentTreeNoLinkto compose realistic buy/sell/roundtrip sequences against the actual cost functionRisk Areas
EchidnaClmsrMathdrift tolerance constants (DRIFT_TOLERANCE_WAD_WEI = 1e12,REL_DRIFT_DENOM = 1e12) — if too loose, the fuzzer may miss genuine precision regressions; if too tight, false positives from compound roundingEchidnaFeeWaterfallLib._boundValidParamsadjustsdeltaEtandBprevupward when grant need exceeds them — this prevents expected reverts but also narrows the input space for loss-dominant scenariosechidna_no_value_creationproperty allowsproceeds <= cost + driftrather than strictproceeds <= cost— the tolerance accommodates rounding but could mask small value-creation bugs