Skip to content

fix(tests,fw,specs): Make the staking precompile (0x1000) warm - #71

Open
Baltoli wants to merge 1 commit into
monad-developers:forks/monad_ninefrom
Baltoli:fix/staking-precompile-warm
Open

Baltoli wants to merge 1 commit into
monad-developers:forks/monad_ninefrom
Baltoli:fix/staking-precompile-warm

Conversation

@Baltoli

@Baltoli Baltoli commented Nov 20, 2026 •

Copy link
Copy Markdown

Description

Monad's staking contract at 0x1000 has been a precompile, and therefore warm, since MONAD_FOUR (monad: staking_active() in category/vm/evm/traits.hpp, is_precompile in category/execution/monad/monad_precompiles.cpp). Neither layer here treated it as one:

  • Testing framework: MONAD_EIGHT.precompiles() did not list it, so precompile_range_boundaries() produced 0x1000 as the cold neighbour of the reserve balance precompile at 0x1001.
  • Spec: PRE_COMPILED_CONTRACTS had no STAKING_ADDRESS entry. The pre-warmed set comes from that mapping, so the t8n treated 0x1000 as cold, empty code.

As a result, tests-monad@v1.3.0 is wrong for berlin/eip2929_gas_cost_increases/test_call.py::test_call_precompile_range_boundaries[...address_0x…1000-warm_False] on MONAD_NINE, MONAD_TEN and MONAD_NEXT_AMSTERDAM, for all four call opcodes:

Slot 0 (gas) Slot 1 (success)
Fixture expects 0x2789 (cold) 1
monad produces 0x79 (warm) 0

This PR:

  • Adds Address(0x1000, label="STAKING") to MONAD_EIGHT.precompiles(). NINE, TEN and NEXT_AMSTERDAM inherit it.
  • Registers a fallback-only staking stub in PRE_COMPILED_CONTRACTS for monad_eight, monad_nine, monad_ten and monad_next_amsterdam. It matches monad's behaviour for unsupported methods (precompile_dispatch / precompile_fallback in staking_contract.cpp):
    • A call other than CALL fails, consuming all gas.
    • A CALL charges 40000 gas (PRECOMPILE_STAKING_FALLBACK), runs out of gas if it has less, and otherwise reverts with "method not supported", consuming all gas.
    • The staking methods themselves (delegate, getValidator, ...) are not modelled. A test calling them would revert in the spec but succeed in monad.
  • Removes the two "staking precompile not implemented yet" skips in tests/frontier/precompiles/, and adds 0x1000 to the precompiles that reject empty input in test_touched_account_emptiness.py.

Verification, with the release fill parameters (-m blockchain_test --from=MONAD_EIGHT --until=MONAD_NEXT_AMSTERDAM --chain-id=143 -k "not invalid_header"):

  • test_call_precompile_range_boundaries: 248 passed. 0x1000 is now probed as warm (slot 0 = 0x79, call fails), with 0x0fff and 0x1000 | 1<<152 probed as cold.
  • Full Monad fill over tests/: 82660 passed, 0 failed.
  • test_precompiles.py, test_precompile_absence.py and test_touched_account_emptiness.py: 570 passed on the Monad forks. test_precompile_absence.py also passes on Prague.

Downstream, category-labs/monad#2751 temporarily excludes call_precompile_range_boundaries.json for MONAD_NINE, MONAD_TEN and MONAD_NEXT_AMSTERDAM. Those exclusions can be dropped once a release with this fix (e.g. tests-monad@v1.3.1) is cut.

Open question for maintainers: whether this fix should also be backported to other fork branches.

Related Issues or PRs

Related: #17, a draft with a much fuller staking precompile model and tests. This PR is the minimal piece needed to fix the fixtures; #17's model could later replace the fallback-only staking.py in the same files.

Checklist

  • Ran fast static checks to avoid CI fails, see Code Standards & Verifying Changes: just static
  • PR title has the form <type>(<area>): <description>, where <type> and <area> come from an appropriate C-<type>, respectively A-<area>, label. The title should match the target squash commit message.

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

RetriggerView in GreptileConfidence Score: 4/5

The PR appears safe to merge, with a non-blocking request for focused fallback tests.

Fix All in Claude CodeFindings

  1. P2 Fallback boundaries lack tests ▶
Fix with agent prompt
### Issue 1
src/ethereum/forks/monad_eight/vm/precompiled_contracts/staking.py:58-63
The new fallback has no focused test for its 40,000-gas cutoff or returned error bytes. Existing tests check call success or whether the gas difference is nonzero. Because failure burns all forwarded gas, another charge below 50,000 could pass those checks and produce incorrect fixtures.

Add cases for `CALL` with 39,999, 40,000, and 40,001 gas. Check returned bytes and remaining gas, including `b"method not supported"` when the charge succeeds. Also check that the other call opcodes return no bytes. This is non-blocking test coverage feedback.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Makes 0x1000 warm in the testing framework and specification for the four supported Monad forks.

  • Monad transactions now treat 0x1000 as a warm staking precompile.

Acknowledged scope: Baltoli explicitly defers supported staking methods to a fuller model related to #17. Their absence is intentional and is not reported.

Reviews (1) · Last reviewed commit: "fix(tests,fw,specs): Make the staking pr..." · Reviewed by Greptile

Monad's staking contract at 0x1000 has been a precompile, and so warm,
since MONAD_FOUR. Neither the testing framework nor the spec treated it
as one: the framework left it out of `precompiles()`, and the spec left
it out of `PRE_COMPILED_CONTRACTS`. So fixtures probed 0x1000 as a cold,
empty neighbour of the reserve balance precompile, and
`test_call_precompile_range_boundaries` expected a cold, successful call
where monad performs a warm, failing one.

List 0x1000 in `MONAD_EIGHT.precompiles()` and register a fallback-only
staking stub in every Monad fork. The stub matches monad's behaviour
for unsupported methods: a call other than CALL fails, and a CALL
charges 40000 gas and reverts with "method not supported", consuming
all gas. The staking methods themselves are not modelled.

Drop the test skips that excluded 0x1000 as not yet implemented, and
count it among the precompiles that reject empty input.
Comment on lines +58 to +63
# GAS
charge_gas(evm, GasCosts.PRECOMPILE_STAKING_FALLBACK)

# OPERATION
evm.output = b"method not supported"
raise RevertInMonadPrecompile

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Fallback boundaries lack tests

The new fallback has no focused test for its 40,000-gas cutoff or returned error bytes. Existing tests check call success or whether the gas difference is nonzero. Because failure burns all forwarded gas, another charge below 50,000 could pass those checks and produce incorrect fixtures.

Add cases for CALL with 39,999, 40,000, and 40,001 gas. Check returned bytes and remaining gas, including b"method not supported" when the charge succeeds. Also check that the other call opcodes return no bytes. This is non-blocking test coverage feedback.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/ethereum/forks/monad_eight/vm/precompiled_contracts/staking.py
Line: 58-63

Comment:
**Fallback boundaries lack tests**

The new fallback has no focused test for its 40,000-gas cutoff or returned error bytes. Existing tests check call success or whether the gas difference is nonzero. Because failure burns all forwarded gas, another charge below 50,000 could pass those checks and produce incorrect fixtures.

Add cases for `CALL` with 39,999, 40,000, and 40,001 gas. Check returned bytes and remaining gas, including `b"method not supported"` when the charge succeeds. Also check that the other call opcodes return no bytes. This is non-blocking test coverage feedback.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant