diff --git a/ethereum/light-client/benches/committee_change.rs b/ethereum/light-client/benches/committee_change.rs index 442358a5..ef4893a8 100644 --- a/ethereum/light-client/benches/committee_change.rs +++ b/ethereum/light-client/benches/committee_change.rs @@ -92,7 +92,7 @@ fn main() { let start_proving = Instant::now(); let proof = benchmark_assets .prover - .prove(inputs, mode) + .prove(&inputs, mode) .expect("Failed to prove committee change"); let proving_time = start_proving.elapsed(); diff --git a/ethereum/light-client/benches/inclusion.rs b/ethereum/light-client/benches/inclusion.rs index 7aaa2c31..3f6a0019 100644 --- a/ethereum/light-client/benches/inclusion.rs +++ b/ethereum/light-client/benches/inclusion.rs @@ -103,7 +103,7 @@ fn main() { let start_proving = Instant::now(); let proof = benchmark_assets .prover - .prove(inputs, mode) + .prove(&inputs, mode) .expect("Failed to prove storage inclusion"); let proving_time = start_proving.elapsed(); diff --git a/ethereum/light-client/src/bin/server_primary.rs b/ethereum/light-client/src/bin/server_primary.rs index 909cca84..eff0dcd8 100644 --- a/ethereum/light-client/src/bin/server_primary.rs +++ b/ethereum/light-client/src/bin/server_primary.rs @@ -54,7 +54,7 @@ async fn main() -> Result<()> { info!("Start proving"); let proof_handle = spawn_blocking(move || { let (proving_mode, inputs) = *boxed; - committee_prover.prove(inputs, proving_mode) + committee_prover.prove(&inputs, proving_mode) }); let proof = proof_handle.await??; info!("Proof generated. Serializing"); diff --git a/ethereum/light-client/src/bin/server_secondary.rs b/ethereum/light-client/src/bin/server_secondary.rs index 8a3c47ed..64f622da 100644 --- a/ethereum/light-client/src/bin/server_secondary.rs +++ b/ethereum/light-client/src/bin/server_secondary.rs @@ -49,7 +49,7 @@ async fn main() -> Result<()> { info!("Start proving"); let proof_handle = spawn_blocking(move || { let (proving_mode, inputs) = *boxed; - inclusion_prover.prove(inputs, proving_mode) + inclusion_prover.prove(&inputs, proving_mode) }); let proof = proof_handle.await??; info!("Proof generated. Serializing"); diff --git a/ethereum/light-client/src/proofs/committee_change.rs b/ethereum/light-client/src/proofs/committee_change.rs index 9ea90520..eb52b11b 100644 --- a/ethereum/light-client/src/proofs/committee_change.rs +++ b/ethereum/light-client/src/proofs/committee_change.rs @@ -162,7 +162,7 @@ impl Prover for CommitteeChangeProver { type StdIn = CommitteeChangeIn; type StdOut = CommitteeChangeOut; - fn generate_sphinx_stdin(&self, inputs: Self::StdIn) -> Result { + fn generate_sphinx_stdin(&self, inputs: &Self::StdIn) -> Result { let mut stdin = SphinxStdin::new(); stdin.write( &inputs @@ -179,7 +179,7 @@ impl Prover for CommitteeChangeProver { Ok(stdin) } - fn execute(&self, inputs: Self::StdIn) -> Result { + fn execute(&self, inputs: &Self::StdIn) -> Result { sphinx_sdk::utils::setup_logger(); let stdin = self.generate_sphinx_stdin(inputs)?; @@ -193,7 +193,7 @@ impl Prover for CommitteeChangeProver { Ok(CommitteeChangeOut::from(&mut public_values)) } - fn prove(&self, inputs: Self::StdIn, mode: ProvingMode) -> Result { + fn prove(&self, inputs: &Self::StdIn, mode: ProvingMode) -> Result { let stdin = self.generate_sphinx_stdin(inputs)?; match mode { @@ -257,7 +257,7 @@ mod test { update: test_assets.update_new_period.clone(), }; - let new_period_output = prover.execute(new_period_inputs).unwrap(); + let new_period_output = prover.execute(&new_period_inputs).unwrap(); assert_eq!( &new_period_output.finalized_block_height, @@ -317,7 +317,9 @@ mod test { println!("Starting STARK proving for sync committee change..."); let start = Instant::now(); - let _ = prover.prove(new_period_inputs, ProvingMode::STARK).unwrap(); + let _ = prover + .prove(&new_period_inputs, ProvingMode::STARK) + .unwrap(); println!("Proving took {:?}", start.elapsed()); } @@ -343,7 +345,9 @@ mod test { println!("Starting SNARK proving for sync committee change..."); let start = Instant::now(); - let _ = prover.prove(new_period_inputs, ProvingMode::SNARK).unwrap(); + let _ = prover + .prove(&new_period_inputs, ProvingMode::SNARK) + .unwrap(); println!("Proving took {:?}", start.elapsed()); } } diff --git a/ethereum/light-client/src/proofs/inclusion.rs b/ethereum/light-client/src/proofs/inclusion.rs index bfaf6980..5be53109 100644 --- a/ethereum/light-client/src/proofs/inclusion.rs +++ b/ethereum/light-client/src/proofs/inclusion.rs @@ -211,29 +211,30 @@ impl Prover for StorageInclusionProver { type StdIn = StorageInclusionIn; type StdOut = StorageInclusionOut; - fn generate_sphinx_stdin(&self, inputs: Self::StdIn) -> Result { + fn generate_sphinx_stdin(&self, inputs: &Self::StdIn) -> Result { let mut stdin = SphinxStdin::new(); let update_sig_period = calc_sync_period(inputs.update.signature_slot()); let store_period = calc_sync_period(inputs.store.finalized_header().beacon().slot()); let finalized_beacon_slot = *inputs.store.finalized_header().beacon().slot(); - let correct_sync_committee = if update_sig_period == store_period { - inputs.store.into_current_sync_committee() - } else { - inputs - .store - .into_next_sync_committee() - .ok_or_else(|| ProverError::SphinxInput { - source: "Expected next sync committee".into(), + let correct_sync_committee = + if update_sig_period == store_period { + inputs.store.current_sync_committee() + } else { + inputs.store.next_sync_committee().as_ref().ok_or_else(|| { + ProverError::SphinxInput { + source: "Expected next sync committee".into(), + } })? - }; + }; stdin.write( - &CompactStore::new(finalized_beacon_slot, correct_sync_committee).to_ssz_bytes(), + &CompactStore::new(finalized_beacon_slot, correct_sync_committee.clone()) + .to_ssz_bytes(), ); stdin.write( - &CompactUpdate::from(inputs.update) + &CompactUpdate::from(inputs.update.clone()) .to_ssz_bytes() .map_err(|err| ProverError::SphinxInput { source: err.into() })?, ); @@ -241,7 +242,7 @@ impl Prover for StorageInclusionProver { Ok(stdin) } - fn execute(&self, inputs: Self::StdIn) -> Result { + fn execute(&self, inputs: &Self::StdIn) -> Result { sphinx_sdk::utils::setup_logger(); let stdin = self.generate_sphinx_stdin(inputs)?; @@ -255,7 +256,7 @@ impl Prover for StorageInclusionProver { Ok(StorageInclusionOut::from(&mut public_values)) } - fn prove(&self, inputs: Self::StdIn, mode: ProvingMode) -> Result { + fn prove(&self, inputs: &Self::StdIn, mode: ProvingMode) -> Result { let stdin = self.generate_sphinx_stdin(inputs)?; match mode { @@ -315,7 +316,7 @@ mod test { eip1186_proof: test_assets.eip1186_proof().clone(), }; - let inclusion_output = prover.execute(inclusion_input).unwrap(); + let inclusion_output = prover.execute(&inclusion_input).unwrap(); assert_eq!( inclusion_output.sync_committee_hash, @@ -366,10 +367,10 @@ mod test { eip1186_proof: test_assets.eip1186_proof().clone(), }; - println!("Starting STARK proving for sync committee change..."); + println!("Starting STARK proving for storage inclusion..."); let start = Instant::now(); - let _ = prover.prove(inclusion_inputs, ProvingMode::STARK).unwrap(); + let _ = prover.prove(&inclusion_inputs, ProvingMode::STARK).unwrap(); println!("Proving took {:?}", start.elapsed()); } @@ -388,10 +389,10 @@ mod test { eip1186_proof: test_assets.eip1186_proof().clone(), }; - println!("Starting SNARK proving for sync committee change..."); + println!("Starting SNARK proving for storage inclusion..."); let start = Instant::now(); - let _ = prover.prove(inclusion_inputs, ProvingMode::SNARK).unwrap(); + let _ = prover.prove(&inclusion_inputs, ProvingMode::SNARK).unwrap(); println!("Proving took {:?}", start.elapsed()); } } diff --git a/ethereum/light-client/src/proofs/mod.rs b/ethereum/light-client/src/proofs/mod.rs index 51418e99..3777c33e 100644 --- a/ethereum/light-client/src/proofs/mod.rs +++ b/ethereum/light-client/src/proofs/mod.rs @@ -208,7 +208,7 @@ pub trait Prover { /// # Returns /// /// The Sphinx stdin. - fn generate_sphinx_stdin(&self, inputs: Self::StdIn) -> Result; + fn generate_sphinx_stdin(&self, inputs: &Self::StdIn) -> Result; /// Execute the program, useful to get the cycles that the program will take. /// @@ -219,7 +219,7 @@ pub trait Prover { /// # Returns /// /// The output of the prover. - fn execute(&self, inputs: Self::StdIn) -> Result; + fn execute(&self, inputs: &Self::StdIn) -> Result; /// Generate a proof for the program. The proof can either be a STARK or a SNARK proof. /// @@ -231,7 +231,7 @@ pub trait Prover { /// # Returns /// /// The proof. - fn prove(&self, inputs: Self::StdIn, mode: ProvingMode) -> Result; + fn prove(&self, inputs: &Self::StdIn, mode: ProvingMode) -> Result; /// Verify a proof for the program. /// diff --git a/fixture-generator/src/bin/main.rs b/fixture-generator/src/bin/main.rs index 7da19b38..111a9654 100644 --- a/fixture-generator/src/bin/main.rs +++ b/fixture-generator/src/bin/main.rs @@ -133,7 +133,7 @@ fn generate_fixture_inclusion_ethereum_lc() { test_assets.finality_update().clone().into(), test_assets.eip1186_proof().clone(), ); - let proof = match prover.prove(input, ProvingMode::SNARK).unwrap() { + let proof = match prover.prove(&input, ProvingMode::SNARK).unwrap() { ProofType::SNARK(inner_proof) => inner_proof, _ => { panic!("Unexpected proof") @@ -225,7 +225,10 @@ fn generate_fixture_epoch_change_ethereum_lc() { let new_period_inputs = CommitteeChangeIn::new(test_assets.store, test_assets.update_new_period); let prover = CommitteeChangeProver::new(); - let proof = match prover.prove(new_period_inputs, ProvingMode::SNARK).unwrap() { + let proof = match prover + .prove(&new_period_inputs, ProvingMode::SNARK) + .unwrap() + { ProofType::SNARK(inner_proof) => inner_proof, _ => { panic!("Unexpected proof")