Skip to content

Conversation

@unnawut
Copy link
Contributor

@unnawut unnawut commented Jul 31, 2025

What was wrong?

As part of #670, this PR brings in the 3SF-mini implementation in rust at https://github.com/ReamLabs/rust-3sf into ream repo under ream-consensus-lean crate.

This PR modified the 3SF-mini code only enough so that the build passes, so that we can start parallelize more work e.g. #671, etc. Reason being there're more changes needed to complete #670, e.g.

  • VariableList does not support item removal but we need it for tracking justifications.
  • Removing Options that are not supported by SSZ
  • Lots of error handling that wasn't needed in the flat PoC code but required for runtime

How was it fixed?

  • Moved https://github.com/ReamLabs/rust-3sf over into ream repo as-is
  • Modified the code only enough so that the build passes e.g. skipping return handling, static time, removing network simulation, etc.
  • Plus:
    • Move Staker from common/consensus/lean to common/lean_chain
    • Reimplement justifications: HashMap<Hash, Vec<bool>> as a flat BitList
    • Add #[derive(Encode, Decode, TreeHash)] to all containers
    • Use anyhow for error handling
  • TODOs for next PR(s):
    • Add some unit tests for peace of mind
  • What else is needed for pqdevnet?
    • Plugging into runtime
    • Networking service
    • Gossipsub for Block and Vote
    • Req/Resp for BlockByRoot
  • Other observations
    • The State is super heavy. It's storing historical_block_hashes and justified_slots for the entire chain history. Can it be trimmed? (maybe not yet for devnet-0)

To-Do

@unnawut unnawut changed the title 3SF for lean pqdevnet feat: 3SF for lean pqdevnet Jul 31, 2025
@unnawut unnawut marked this pull request as ready for review July 31, 2025 09:01
@unnawut unnawut requested review from jihoonsong and syjn99 July 31, 2025 09:01
Copy link
Member

@syjn99 syjn99 left a comment

Choose a reason for hiding this comment

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

Finished initial review!

@unnawut
Copy link
Contributor Author

unnawut commented Jul 31, 2025

Converting back to draft to address Jun's comments when I wake up.

@unnawut unnawut marked this pull request as draft July 31, 2025 15:59
@KolbyML
Copy link
Contributor

KolbyML commented Aug 1, 2025

If you are using usize for zkVM's as it would be a u32, we still shouldn't use usize we should use u32 and define it in the leanSpecs

Copy link
Contributor

@KolbyML KolbyML left a comment

Choose a reason for hiding this comment

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

Left some feedback

Comment on lines 26 to 31
impl Vote {
pub fn compute_hash(&self) -> B256 {
let serialized = serde_json::to_string(self).unwrap();
B256::from_slice(&hash(serialized.as_bytes()))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The hash of Vote is computed by calling .tree_root_hash() on the object like how it is done in the beacon chain right?, I don't think we need this function

Copy link
Member

Choose a reason for hiding this comment

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

I guess this is a ported function from the original code (by Vitalik). Of course it will be deleted after using SSZ here.

https://github.com/ethereum/research/blob/d225a6775a9b184b5c1fd6c830cc58a375d9535f/3sf-mini/consensus.py#L46-L50

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've resolved all issues with SSZ compatibility and so replaced compute_hash() with TreeHash now.

@KolbyML
Copy link
Contributor

KolbyML commented Aug 1, 2025

Generally make lint should be done before reviews are done, but eh, I think it is fine to give some light direction rn

@unnawut unnawut marked this pull request as ready for review August 1, 2025 11:03
@unnawut unnawut requested review from KolbyML and syjn99 August 1, 2025 11:04
Copy link
Member

@syjn99 syjn99 left a comment

Choose a reason for hiding this comment

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

Some nits and concerns! Thanks

Copy link
Contributor

@KolbyML KolbyML left a comment

Choose a reason for hiding this comment

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

Could we remove the rest of the unwrap()'s as well, although I think we should just use anyhow, as it isn't much work

@unnawut
Copy link
Contributor Author

unnawut commented Aug 4, 2025

Remaining: move to anyhow

@unnawut unnawut requested review from KolbyML and syjn99 August 4, 2025 18:11
@unnawut
Copy link
Contributor Author

unnawut commented Aug 4, 2025

Could we remove the rest of the unwrap()'s as well, although I think we should just use anyhow, as it isn't much work

@KolbyML I tried moving unwrap() and expect() entirely to anyhow, it was quite a bit of change so not sure if I'm doing the right way...

Copy link
Member

@syjn99 syjn99 left a comment

Choose a reason for hiding this comment

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

I only have some code styling concerns, and am mostly happy with the content here. Thanks O!

Approved proactively from my side

@unnawut unnawut added this pull request to the merge queue Aug 5, 2025
Merged via the queue into ReamLabs:master with commit 0164625 Aug 5, 2025
14 checks passed
@unnawut unnawut deleted the lean-3sf branch August 6, 2025 10:00
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.

3 participants