Skip to content

feat: improve randomize_state field coverage for fork transition testing#4594

Closed
richardgreg wants to merge 1 commit intoethereum:masterfrom
richardgreg:feat/state-field-randomization-improvement
Closed

feat: improve randomize_state field coverage for fork transition testing#4594
richardgreg wants to merge 1 commit intoethereum:masterfrom
richardgreg:feat/state-field-randomization-improvement

Conversation

@richardgreg
Copy link

@richardgreg richardgreg commented Sep 16, 2025

feat: improve randomize_state field coverage for fork transition testing

Description

  • This PR improves the randomize_state function to populate beacon state fields with realistic non-default values during testing.
  • Currently, when clients forget to copy fields during upgrades, tests don't catch these
    bugs because 0 == 0 assertions still pass, as demonstrated in the issue description with the Teku client. By using realistic test values, missing field copies now cause test failures
  • randomize_state field population now extended to all forks

Relations

Fixes #4535

Co-authored by Claude

@richardgreg richardgreg force-pushed the feat/state-field-randomization-improvement branch from a20cf1d to a2b434a Compare September 16, 2025 21:23
@richardgreg
Copy link
Author

@jtraglia, do you think it is necessary to populate the fields for previous forks?

@jtraglia
Copy link
Member

@jtraglia, do you think it is necessary to populate the fields for previous forks?

Yes, it would be valuable to do this. Please complete the TODO items you've stated in the functions.

Sorry I just haven't had enough time to properly review your PR. Given that this change will affect lots tests for several forks, it will require a more extensive review. In the mean time, I've started the CI checks for this.

I would like for @leolara to review it too. He's in charge of testing here.

@jtraglia jtraglia requested a review from leolara September 19, 2025 14:58
@jtraglia jtraglia added the testing CI, actions, tests, testing infra label Sep 19, 2025
@richardgreg richardgreg force-pushed the feat/state-field-randomization-improvement branch 2 times, most recently from 5c00326 to 537e0d0 Compare September 26, 2025 18:24
@richardgreg
Copy link
Author

Hi @leolara, what are your thoughts?


def _randomize_phase0_fields(spec, state):
"""Set Phase0-specific fields to realistic non-default values."""
if is_post_altair(spec):
Copy link
Member

Choose a reason for hiding this comment

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

@richardgreg I think this ìf` either should not be here or throw an exception. Like it should not be allowed to call this function in the phase that is not supposed to be used. I search our code base and there are no examples like this, I think.

What do you think?

Copy link
Author

Choose a reason for hiding this comment

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

You're right, Leo. It's a counterproductive measure

@leolara
Copy link
Member

leolara commented Oct 8, 2025

@richardgreg richardgreg force-pushed the feat/state-field-randomization-improvement branch 2 times, most recently from 741a30e to 1f7da1b Compare October 9, 2025 07:48
@leolara
Copy link
Member

leolara commented Oct 9, 2025

@richardgreg let me know if I should try to run the tests again

@richardgreg richardgreg force-pushed the feat/state-field-randomization-improvement branch from 1f7da1b to ca9f91e Compare October 10, 2025 10:06
@richardgreg
Copy link
Author

richardgreg commented Oct 10, 2025

@richardgreg let me know if I should try to run the tests again

@leolara sure. You can go ahead and do it. My branch is up-to-date and it generates the reftests locally. I'm hoping that will fix any conflict arising in the CI

@leolara
Copy link
Member

leolara commented Oct 28, 2025

@leolara
Copy link
Member

leolara commented Nov 1, 2025

@richardgreg the reference tests are failing in this branch, please check the logs there https://github.com/ethereum/consensus-specs/actions/runs/18891974203 and see if you can fix it

@richardgreg
Copy link
Author

https://github.com/ethereum/consensus-specs/actions/runs/18891974203

Right, Leo. I'm investigating it

* Add Electra churn field randomization
* Add withdrawal field randomization for Capella+ forks
* Add finality checkpoint randomization with safety checks
* Add pending operations randomization
* Randomize fields for all forks transitioning from phase0 to Electra
@richardgreg richardgreg force-pushed the feat/state-field-randomization-improvement branch from ca9f91e to b6f3115 Compare November 3, 2025 21:51
@richardgreg
Copy link
Author

richardgreg commented Nov 4, 2025

@leolara In this latest push, Altair now inherits Phase 0's fields. The bug was likely due to BLS signature verification failing. Altair not inheriting Phase 0 fields including randao_mixes most likely contributed to that. It's hard to confirm ref tests pass locally because of the amount of time it takes 😅

So I went quite all in this issue without much external input. From what you've seen so far, what are your thoughts on the fields chosen to be randomized for each fork?

@leolara
Copy link
Member

leolara commented Jan 10, 2026

I am closing this, but let me know if you think we should reopen it

@leolara leolara closed this Jan 10, 2026
@richardgreg
Copy link
Author

Hi @leolara, okay. I'll let you know when to reopen it for review. My initial solution was kinda rushed, so I'm taking a new approach. I'm putting together a system design for the problem based on the learnings from my initial attempt. I'd love for you to help me review it when I'm done before I put it into code.

I'd also appreciate it if you could confirm that the correct test command for spotting the bug in my initial solution is make reftests k=test_randomized_11. Just gathering intel. Any other tips you can provide, like relevant links in the eth2book, would be appreciated

Happy New Year

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

Labels

testing CI, actions, tests, testing infra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fully populate state fields in randomize_state

3 participants