-
Notifications
You must be signed in to change notification settings - Fork 30
fix(crypto): run every proof on one dedicated prover thread #641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+194
β65
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,3 +23,4 @@ shadow-integration = [] | |
|
|
||
| [dev-dependencies] | ||
| hex.workspace = true | ||
| zk_alloc.workspace = true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| //! The arena's memory bound under ethlambda's threading. | ||
| //! | ||
| //! leanVM's arena gives each thread that allocates during a proof its own slab and keeps | ||
| //! it for the life of the process; the slab that fills is the one of the thread driving | ||
| //! the proof. ethlambda asks for proofs from threads that come and go (tokio's blocking | ||
| //! pool, the actors), so proving on the asking thread would pin one slab per thread ever | ||
| //! used, which is how aggregators on `--prover-arena` were OOM-killed. | ||
| //! | ||
| //! Its own test binary, and so its own process: the arena engages process-wide and the | ||
| //! slab count is process-wide, so another test proving alongside would move it. | ||
|
|
||
| mod common; | ||
|
|
||
| use std::thread; | ||
|
|
||
| use common::keypair_and_signature; | ||
| use ethlambda_crypto::{aggregate_signatures, init_leanvm}; | ||
| use ethlambda_types::primitives::H256; | ||
|
|
||
| #[test] | ||
| #[ignore = "too slow"] | ||
| fn proving_from_fresh_threads_claims_no_new_slabs() { | ||
| init_leanvm(true); | ||
|
|
||
| let message = H256::from([7u8; 32]); | ||
| let slot = 10u32; | ||
| let (pk, sig) = keypair_and_signature(1, 5, slot, &message); | ||
| let prove_from_a_fresh_thread = || { | ||
| let (pk, sig) = (pk.clone(), sig.clone()); | ||
| thread::spawn(move || aggregate_signatures(vec![pk], vec![sig], &message, slot)) | ||
| .join() | ||
| .expect("asking thread") | ||
| .expect("aggregation on the arena"); | ||
| }; | ||
|
|
||
| prove_from_a_fresh_thread(); | ||
| let slabs = zk_alloc::stats().threads; | ||
| // Zero would mean this test reads another copy of the arena than leanvm's. | ||
| assert!(slabs > 0, "the first proof claimed no slab"); | ||
|
|
||
| for _ in 0..4 { | ||
| prove_from_a_fresh_thread(); | ||
| } | ||
| assert_eq!( | ||
| zk_alloc::stats().threads, | ||
| slabs, | ||
| "proving from new threads claimed new slabs" | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //! Helpers shared by the integration tests. | ||
|
|
||
| use ethlambda_crypto::signature::{ValidatorPublicKey, ValidatorSignature}; | ||
| use ethlambda_types::primitives::H256; | ||
| use leanvm::xmss::{self, Encode as _, key_gen_from_seed}; | ||
|
|
||
| /// Mirrors the lib tests' helper: a small slot range keeps key generation fast. | ||
| pub fn keypair_and_signature( | ||
| seed: u64, | ||
| first_slot: u32, | ||
| signing_slot: u32, | ||
| message: &H256, | ||
| ) -> (ValidatorPublicKey, ValidatorSignature) { | ||
| let mut seed_bytes = [0u8; 32]; | ||
| seed_bytes[..8].copy_from_slice(&seed.to_le_bytes()); | ||
|
|
||
| let (sk, pk) = | ||
| key_gen_from_seed(seed_bytes, first_slot, first_slot + 63).expect("valid slot range"); | ||
| let sig = xmss::sign(&sk, &message.0, signing_slot).expect("sign"); | ||
|
|
||
| ( | ||
| ValidatorPublicKey::from_bytes(&pk.as_ssz_bytes()).unwrap(), | ||
| ValidatorSignature::from_bytes(&sig.as_ssz_bytes()).unwrap(), | ||
| ) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small note on the stack: 2 MiB matches the tokio threads the node proved on, but not every caller.
ethlambda benchmarkruns synchronously on the main thread (bin/ethlambda/src/main.rs:72, 8 MiB stack), so its proofs (benchmark/corpus.rs:155plus the block building it drives) now drop to 2 MiB. Same for the actor's proofs undershadow-integration, where the runtime iscurrent_threadon main.Probably fine since production already proves on 2 MiB, but since aggregation has hit stack overflows before (the reason tests run under
release-fast), maybe set an explicit.stack_size(...)here, or at least soften the "the size tokio gives its own threads" wording in the doc comment and PR body?