From 733b31681535aa2d0da5b98ea392136b78bb2b77 Mon Sep 17 00:00:00 2001 From: David Rusu Date: Sun, 11 Aug 2024 23:17:37 +0400 Subject: [PATCH] goas: clippy + print proof cycles --- .../atomic_asset_transfer/executor/src/lib.rs | 48 +++++++------------ .../executor/tests/atomic_transfer.rs | 22 ++++----- .../executor/tests/withdraw_ptx.rs | 7 ++- 3 files changed, 31 insertions(+), 46 deletions(-) diff --git a/goas/atomic_asset_transfer/executor/src/lib.rs b/goas/atomic_asset_transfer/executor/src/lib.rs index ca52f22..43a6655 100644 --- a/goas/atomic_asset_transfer/executor/src/lib.rs +++ b/goas/atomic_asset_transfer/executor/src/lib.rs @@ -1,11 +1,8 @@ use std::collections::BTreeMap; -use cl::{PartialTxInputWitness, PartialTxOutputWitness}; -use common::{BoundTx, IncludedTxWitness, StateRoots, StateWitness, Tx, ZoneMetadata}; +use common::{BoundTx, StateWitness, Tx, ZoneMetadata}; use goas_proof_statements::{ - user_note::{UserAtomicTransfer, UserIntent}, - zone_funds::SpendFundsPrivate, - zone_state::ZoneStatePrivate, + user_note::UserAtomicTransfer, zone_funds::SpendFundsPrivate, zone_state::ZoneStatePrivate, }; use rand_core::CryptoRngCore; @@ -153,7 +150,11 @@ pub fn prove_zone_stf( let prove_info = prover .prove_with_opts(env, goas_risc0_proofs::ZONE_STATE_ELF, &opts) .unwrap(); - println!("STARK 'zone_stf' prover time: {:.2?}", start_t.elapsed()); + println!( + "STARK 'zone_stf' prover time: {:.2?}, total_cycles: {}", + start_t.elapsed(), + prove_info.stats.total_cycles + ); let receipt = prove_info.receipt; ledger::DeathProof::from_risc0(goas_risc0_proofs::ZONE_STATE_ID, receipt) } @@ -183,34 +184,18 @@ pub fn prove_zone_fund_withdraw( let prove_info = prover .prove_with_opts(env, goas_risc0_proofs::SPEND_ZONE_FUNDS_ELF, &opts) .unwrap(); - println!("STARK 'zone_fund' prover time: {:.2?}", start_t.elapsed()); + println!( + "STARK 'zone_fund' prover time: {:.2?}, total_cycles: {}", + start_t.elapsed(), + prove_info.stats.total_cycles + ); let receipt = prove_info.receipt; ledger::DeathProof::from_risc0(goas_risc0_proofs::SPEND_ZONE_FUNDS_ID, receipt) } -pub fn prove_user_atomic_transfer( - user_note: PartialTxInputWitness, - user_intent: UserIntent, - zone_a: PartialTxOutputWitness, - zone_b: PartialTxOutputWitness, - zone_a_roots: StateRoots, - zone_b_roots: StateRoots, - withdraw_tx: IncludedTxWitness, - deposit_tx: IncludedTxWitness, -) -> ledger::DeathProof { - let private_inputs = UserAtomicTransfer { - user_note, - user_intent, - zone_a, - zone_b, - zone_a_roots, - zone_b_roots, - withdraw_tx, - deposit_tx, - }; - +pub fn prove_user_atomic_transfer(atomic_transfer: UserAtomicTransfer) -> ledger::DeathProof { let env = risc0_zkvm::ExecutorEnv::builder() - .write(&private_inputs) + .write(&atomic_transfer) .unwrap() .build() .unwrap(); @@ -224,8 +209,9 @@ pub fn prove_user_atomic_transfer( .prove_with_opts(env, goas_risc0_proofs::USER_ATOMIC_TRANSFER_ELF, &opts) .unwrap(); println!( - "STARK 'user atomic transfer' prover time: {:.2?}", - start_t.elapsed() + "STARK 'user atomic transfer' prover time: {:.2?}, total_cycles: {}", + start_t.elapsed(), + prove_info.stats.total_cycles ); let receipt = prove_info.receipt; ledger::DeathProof::from_risc0(goas_risc0_proofs::USER_ATOMIC_TRANSFER_ID, receipt) diff --git a/goas/atomic_asset_transfer/executor/tests/atomic_transfer.rs b/goas/atomic_asset_transfer/executor/tests/atomic_transfer.rs index f80a437..ca4888b 100644 --- a/goas/atomic_asset_transfer/executor/tests/atomic_transfer.rs +++ b/goas/atomic_asset_transfer/executor/tests/atomic_transfer.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; use cl::{BundleWitness, NoteWitness, NullifierNonce}; use common::{BoundTx, Deposit, Tx, Withdraw}; use executor::ZoneNotes; -use goas_proof_statements::user_note::UserIntent; +use goas_proof_statements::user_note::{UserAtomicTransfer, UserIntent}; #[test] fn test_atomic_transfer() { @@ -72,16 +72,16 @@ fn test_atomic_transfer() { let death_proofs = BTreeMap::from_iter([ ( alice_intent_in.nullifier(), - executor::prove_user_atomic_transfer( - atomic_transfer_ptx.input_witness(0), - alice_intent, - atomic_transfer_ptx.output_witness(0), - atomic_transfer_ptx.output_witness(2), - zone_a_end.state.state_roots(), - zone_b_end.state.state_roots(), - zone_a_end.state.included_tx_witness(0), - zone_b_end.state.included_tx_witness(0), - ), + executor::prove_user_atomic_transfer(UserAtomicTransfer { + user_note: atomic_transfer_ptx.input_witness(0), + user_intent: alice_intent, + zone_a: atomic_transfer_ptx.output_witness(0), + zone_b: atomic_transfer_ptx.output_witness(2), + zone_a_roots: zone_a_end.state.state_roots(), + zone_b_roots: zone_b_end.state.state_roots(), + withdraw_tx: zone_a_end.state.included_tx_witness(0), + deposit_tx: zone_b_end.state.included_tx_witness(0), + }), ), ( zone_a_start.state_input_witness().nullifier(), diff --git a/goas/atomic_asset_transfer/executor/tests/withdraw_ptx.rs b/goas/atomic_asset_transfer/executor/tests/withdraw_ptx.rs index 17de9c7..1c9d061 100644 --- a/goas/atomic_asset_transfer/executor/tests/withdraw_ptx.rs +++ b/goas/atomic_asset_transfer/executor/tests/withdraw_ptx.rs @@ -1,10 +1,9 @@ use std::collections::BTreeMap; -use cl::{NoteWitness, NullifierNonce, NullifierSecret}; -use common::{BoundTx, StateWitness, Tx, ZoneMetadata, ZONE_CL_FUNDS_UNIT}; +use cl::{NoteWitness, NullifierSecret}; +use common::{BoundTx, StateWitness, Tx, ZONE_CL_FUNDS_UNIT}; use executor::ZoneNotes; use ledger::death_constraint::DeathProof; -use rand_core::CryptoRngCore; #[test] fn test_withdrawal() { @@ -58,7 +57,7 @@ fn test_withdrawal() { executor::prove_zone_stf( zone_start.state.clone(), vec![BoundTx { - tx: Tx::Withdraw(withdraw.clone()), + tx: Tx::Withdraw(withdraw), bind: withdraw_ptx.input_witness(2), }], withdraw_ptx.input_witness(0), // input state note (input #0)