[Flow EVM] Add proper meter and gas limit checks for EVM dry operations#8416
[Flow EVM] Add proper meter and gas limit checks for EVM dry operations#8416
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
📝 WalkthroughWalkthroughThese changes add comprehensive tests for EVM dry-run and dry-call operations with gas metering validation, and modify the EVM handler to enforce gas pre-checks, disable metering during execution, and measure gas consumption post-call. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
fvm/evm/evm_test.go (2)
3104-3195: Clarify the loop count comment and consider documenting expected computation breakdown.The Cadence loop
while i <= iterationsexecutesiterations + 1times, soiterations=5yields 6 calls anditerations=15yields 16 calls. The comment on line 3174 ("Triple to number of times EVM.dryRun is called") is slightly imprecise — the iteration parameter is tripled (5 → 15), but the actual call count goes from 6 to 16, which is not exactly 3×.Also, the hardcoded expected values (
40and102) are brittle — they'll break ifMainnetExecutionEffortWeightsor EVM gas costs change. A brief inline comment explaining how these values are derived (e.g.,6 iterations × gasConsumed × weight(3) + Cadence overhead) would aid future maintainability.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@fvm/evm/evm_test.go` around lines 3104 - 3195, The test's comment and hardcoded expectations are misleading because the Cadence loop `while i <= iterations` calls EVM.dryRun iterations+1 times (so iterations=5 → 6 calls, iterations=15 → 16 calls); update the inline comment near the `iterations` setup and the "Triple to number..." line to state that the iteration parameter is tripled but call count goes 6→16, and either replace the hardcoded asserts for `output.ComputationUsed` with a computed expected value based on (iterations+1) × per-call cost × weight retrieved from MainnetExecutionEffortWeights (or add a clear explanatory comment showing the derivation e.g., "(iterations+1) × per-call-cost + Cadence overhead = 40/102"), referencing the test function and variables `iterations`, `EVM.dryRun`, and the two `assert.Equal(t, uint64(...), output.ComputationUsed)` assertions so future changes to weights/gas don't silently break the test.
3643-3740: Same comment as the dryRun metering test — loop count nuance and brittle hardcoded values.Same observation applies:
iterations=5→ 6 calls,iterations=15→ 16 calls, and53/139are exact computation assertions that will break with weight changes. This is consistent with the dryRun metering test structure.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@fvm/evm/evm_test.go` around lines 3643 - 3740, The test "test EVM.dryCall is properly metered" uses an inclusive loop (iterations N produces N+1 calls) and asserts brittle hardcoded computation values (53/139); update the test to compute the expected computation dynamically: determine calls := iterations.Value + 1, capture computationUsed for a baseline iterations (e.g., 5) and compute perCall cost from that run (or compute expected as baseCost + calls*perCall), then replace hardcoded asserts on output.ComputationUsed with a comparison against the calculated expected value (or a tolerant range) using the variables iterations and output.ComputationUsed; adjust references to iterations, output.ComputationUsed and the transaction build in the test to use the computed expectations rather than literals.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@fvm/evm/evm_test.go`:
- Around line 3104-3195: The test's comment and hardcoded expectations are
misleading because the Cadence loop `while i <= iterations` calls EVM.dryRun
iterations+1 times (so iterations=5 → 6 calls, iterations=15 → 16 calls); update
the inline comment near the `iterations` setup and the "Triple to number..."
line to state that the iteration parameter is tripled but call count goes 6→16,
and either replace the hardcoded asserts for `output.ComputationUsed` with a
computed expected value based on (iterations+1) × per-call cost × weight
retrieved from MainnetExecutionEffortWeights (or add a clear explanatory comment
showing the derivation e.g., "(iterations+1) × per-call-cost + Cadence overhead
= 40/102"), referencing the test function and variables `iterations`,
`EVM.dryRun`, and the two `assert.Equal(t, uint64(...), output.ComputationUsed)`
assertions so future changes to weights/gas don't silently break the test.
- Around line 3643-3740: The test "test EVM.dryCall is properly metered" uses an
inclusive loop (iterations N produces N+1 calls) and asserts brittle hardcoded
computation values (53/139); update the test to compute the expected computation
dynamically: determine calls := iterations.Value + 1, capture computationUsed
for a baseline iterations (e.g., 5) and compute perCall cost from that run (or
compute expected as baseCost + calls*perCall), then replace hardcoded asserts on
output.ComputationUsed with a comparison against the calculated expected value
(or a tolerant range) using the variables iterations and output.ComputationUsed;
adjust references to iterations, output.ComputationUsed and the transaction
build in the test to use the computed expectations rather than literals.
858438b to
c929c66
Compare
Closes: https://github.com/onflow/flow-go-internal/issues/7159
Summary by CodeRabbit
Bug Fixes
Tests