Skip to content

feat: pass machine explicitly everywhere applicable#2753

Merged
tamirhemo merged 10 commits into
mainfrom
powdr-labs/pass-machine-everywhere
May 1, 2026
Merged

feat: pass machine explicitly everywhere applicable#2753
tamirhemo merged 10 commits into
mainfrom
powdr-labs/pass-machine-everywhere

Conversation

@Schaeff

@Schaeff Schaeff commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

The machine to be proven is currently always the same instance of Machine created with RiscvAir::machine().
As a result, many places in the code just rebuild it on the fly instead of passing it around.
In the context of APCs however, not all Machine instances are the same, as they get created dynamically with some autoprecompile chips.
Therefore, pass the machine around everywhere applicable, in preparation for APCs.

This PR has no APC specific code, it's just a generalisation.

Comment thread crates/prover/scripts/build_recursion_vks.rs Outdated
gate: super::ProveShardGate<A, W>,
minimal_executor_cache: Option<MinimalExecutorCache>,
cycle_limit: Option<u64>,
_machine: Machine<SP1Field, RiscvAir<SP1Field>>,

@Schaeff Schaeff Apr 27, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is not used now, because we do not customize the executor using the machine so that APCs are executed instead of the software path. The change that introduces the customization is in #2738

@Schaeff Schaeff force-pushed the powdr-labs/pass-machine-everywhere branch from 137be28 to 06f0fa0 Compare April 28, 2026 09:58
Co-authored-by: qwang98 <qian.wang.wg24@wharton.upenn.edu>
Co-authored-by: Georg Wiese <georgwiese@gmail.com>
@Schaeff Schaeff force-pushed the powdr-labs/pass-machine-everywhere branch from 06f0fa0 to 2ef46aa Compare April 28, 2026 11:33
@github-actions

github-actions Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor
Test Old New Diff
bn_test_bn_test_fq_inverse_100 834818 834818 0.0000 %
sha_test_sha2_v0_10_9_expected_digest_lte_100_times 1766118 1761946 -0.2362 %
sha_test_sha2_v0_9_9_expected_digest_lte_100_times 1259299 1260962 0.1321 %
curve25519_dalek_test_decompressed_expected_value 4583404 4503211 -1.7496 %
sha_test_sha3_expected_digest_lte_100_times 1609172 1609419 0.0153 %
bls12_381_tests_test_bls_add_100 10502109 10502109 0.0000 %
k256_test_recover_pubkey_infinity 98275 98275 0.0000 %
rust_crypto_rsa_test_pkcs_verify_100 28892337 28605528 -0.9927 %
keccack_test_expected_digest_lte_100 1715984 1716736 0.0438 %
p256_test_recover_rand_lte_100 15978634 15978214 -0.0026 %
curve25519_dalek_ng_test_zero_msm 125561 125561 0.0000 %
bn_test_bn_test_g1_add_100 986824 986810 -0.0014 %
k256_test_schnorr_verify 5744361 5743331 -0.0179 %
rustcrypto_bigint_test_bigint_mul_mod_special 1753919 1753919 0.0000 %
p256_test_verify_rand_lte_100 11896349 11915839 0.1638 %
bn_test_bn_test_fq_partial_ord 184121 184121 0.0000 %
secp256k1_program_test_verify_rand_lte_100 17137590 17155463 0.1043 %
p256_test_recover_high_hash_high_recid 4632227 5701867 23.0913 %
bls12_381_tests_test_inverse_fp2_100 2766659 2766659 0.0000 %
curve25519_dalek_test_ed25519_verify 13289658 13290933 0.0096 %
bn_test_bn_test_g1_msm_edge 406722 406722 0.0000 %
bn_test_bn_test_fr_inverse_100 851818 851818 0.0000 %
bls12_381_tests_test_sqrt_fp2_100 1807772 1807605 -0.0092 %
k256_test_recover_rand_lte_100 4444001 4460516 0.3716 %
k256_test_verify_rand_lte_100 11867724 11901439 0.2841 %
curve25519_dalek_test_decompressed_noncanonical 7661 7661 0.0000 %
secp256k1_program_test_recover_rand_lte_100 5488658 5489740 0.0197 %
bls12_381_tests_test_sqrt_fp_100 1085117 1024355 -5.5996 %
bls12_381_tests_test_bls_double_100 6348822 6348822 0.0000 %
curve25519_dalek_test_zero_mul 72087 72087 0.0000 %
curve25519_dalek_ng_test_add_then_multiply 4146015 4706348 13.5150 %
p256_test_recover_pubkey_infinity 102291 102291 0.0000 %
bn_test_bn_test_fq_sqrt_100 833218 833218 0.0000 %
curve25519_dalek_ng_test_zero_mul 108070 108070 0.0000 %
secp256k1_program_test_verify_v0_30_0_rand_lte_100 17151072 17133517 -0.1024 %
bn_test_bn_test_g1_mul_zero 46126 46126 0.0000 %
secp256k1_program_test_recover_v0_30_0_rand_lte_100 5488281 5493478 0.0947 %
k256_test_point_ops_edge_cases 33844 33844 0.0000 %
curve25519_dalek_test_add_then_multiply 2895411 2856902 -1.3300 %
sha_test_sha2_v0_10_6_expected_digest_lte_100_times 1767545 1765089 -0.1389 %
bls12_381_tests_test_inverse_fp_100 1416559 1416559 0.0000 %
curve25519_dalek_ng_test_decompressed_noncanonical 195591 195591 0.0000 %
k256_test_recover_high_hash_high_recid 2081146 2222844 6.8087 %
bn_test_bn_test_g1_double_100 727517 727496 -0.0029 %
bn_test_bn_test_g1_add_neg 306880 306880 0.0000 %
curve25519_dalek_test_zero_msm 83637 83637 0.0000 %
rustcrypto_bigint_test_bigint_mul_add_residue 1736512 1736472 -0.0023 %
sha_test_sha2_v0_10_8_expected_digest_lte_100_times 1767142 1770130 0.1691 %

struct ConnectionCtx {
pk_cache: HashMap<[u8; 32], CachedProgram>,
prover: Arc<SP1LocalNode>,
prover: tokio::sync::OnceCell<Arc<SP1LocalNode>>,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We only know the machine at setup time, therefore we can't create a prover before that.

@Schaeff Schaeff marked this pull request as ready for review April 28, 2026 15:38
num_deferred_proofs,
cycle_limit,
context: context.clone(),
// TODO: is this expensive?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shouldn't be since chips are references

@tamirhemo tamirhemo merged commit 94ecac2 into main May 1, 2026
11 checks passed
@tamirhemo tamirhemo deleted the powdr-labs/pass-machine-everywhere branch May 1, 2026 01:48
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.

2 participants