refactor(circuit): borrow account_identities

This commit is contained in:
Artem Gureev 2026-06-30 12:09:14 +00:00 committed by agureev
parent 84df5252c0
commit 327f44fce3
2 changed files with 23 additions and 29 deletions

View File

@ -17,7 +17,7 @@ fn main() {
program_outputs, program_outputs,
); );
let output = output::compute_circuit_output(execution_state, account_identities); let output = output::compute_circuit_output(execution_state, &account_identities);
env::commit(&output); env::commit(&output);
} }

View File

@ -11,7 +11,7 @@ use crate::execution_state::ExecutionState;
pub fn compute_circuit_output( pub fn compute_circuit_output(
execution_state: ExecutionState, execution_state: ExecutionState,
account_identities: Vec<InputAccountIdentity>, account_identities: &[InputAccountIdentity],
) -> PrivacyPreservingCircuitOutput { ) -> PrivacyPreservingCircuitOutput {
let (block_validity_window, timestamp_validity_window, pda_seed_by_position, states_iter) = let (block_validity_window, timestamp_validity_window, pda_seed_by_position, states_iter) =
execution_state.into_parts(); execution_state.into_parts();
@ -33,7 +33,7 @@ pub fn compute_circuit_output(
let mut output_index = 0; let mut output_index = 0;
for (pos, (account_identity, (pre_state, post_state))) in for (pos, (account_identity, (pre_state, post_state))) in
account_identities.into_iter().zip(states_iter).enumerate() account_identities.iter().zip(states_iter).enumerate()
{ {
match account_identity { match account_identity {
InputAccountIdentity::Public => { InputAccountIdentity::Public => {
@ -47,7 +47,7 @@ pub fn compute_circuit_output(
identifier, identifier,
} => { } => {
let address = let address =
PrivateAddressPlaintext::new(NullifierPublicKey::from(&nsk), &vpk, identifier); PrivateAddressPlaintext::new(NullifierPublicKey::from(nsk), vpk, *identifier);
let account_id = address.account_id(); let account_id = address.account_id();
assert_eq!(account_id, pre_state.account_id, "AccountId mismatch"); assert_eq!(account_id, pre_state.account_id, "AccountId mismatch");
@ -75,7 +75,7 @@ pub fn compute_circuit_output(
&PrivateAccountKind::Regular(address.identifier), &PrivateAccountKind::Regular(address.identifier),
&address.npk, &address.npk,
address.vpk, address.vpk,
&random_seed, random_seed,
new_nullifier, new_nullifier,
new_nonce, new_nonce,
); );
@ -88,7 +88,7 @@ pub fn compute_circuit_output(
identifier, identifier,
} => { } => {
let address = let address =
PrivateAddressPlaintext::new(NullifierPublicKey::from(&nsk), &vpk, identifier); PrivateAddressPlaintext::new(NullifierPublicKey::from(nsk), vpk, *identifier);
let account_id = address.account_id(); let account_id = address.account_id();
assert_eq!(account_id, pre_state.account_id, "AccountId mismatch"); assert_eq!(account_id, pre_state.account_id, "AccountId mismatch");
@ -98,15 +98,12 @@ pub fn compute_circuit_output(
); );
let new_nullifier = compute_update_nullifier_and_set_digest( let new_nullifier = compute_update_nullifier_and_set_digest(
&membership_proof, membership_proof,
&pre_state.account, &pre_state.account,
&account_id, &account_id,
&nsk, nsk,
); );
let new_nonce = pre_state let new_nonce = pre_state.account.nonce.private_account_nonce_increment(nsk);
.account
.nonce
.private_account_nonce_increment(&nsk);
emit_private_output( emit_private_output(
&mut output, &mut output,
@ -116,7 +113,7 @@ pub fn compute_circuit_output(
&PrivateAccountKind::Regular(address.identifier), &PrivateAccountKind::Regular(address.identifier),
&address.npk, &address.npk,
address.vpk, address.vpk,
&random_seed, random_seed,
new_nullifier, new_nullifier,
new_nonce, new_nonce,
); );
@ -127,7 +124,7 @@ pub fn compute_circuit_output(
npk, npk,
identifier, identifier,
} => { } => {
let address = PrivateAddressPlaintext::new(npk, &vpk, identifier); let address = PrivateAddressPlaintext::new(*npk, vpk, *identifier);
let account_id = address.account_id(); let account_id = address.account_id();
assert_eq!(account_id, pre_state.account_id, "AccountId mismatch"); assert_eq!(account_id, pre_state.account_id, "AccountId mismatch");
@ -155,7 +152,7 @@ pub fn compute_circuit_output(
&PrivateAccountKind::Regular(address.identifier), &PrivateAccountKind::Regular(address.identifier),
&address.npk, &address.npk,
address.vpk, address.vpk,
&random_seed, random_seed,
new_nullifier, new_nullifier,
new_nonce, new_nonce,
); );
@ -200,11 +197,11 @@ pub fn compute_circuit_output(
&PrivateAccountKind::Pda { &PrivateAccountKind::Pda {
program_id: *authority_program_id, program_id: *authority_program_id,
seed: *seed, seed: *seed,
identifier, identifier: *identifier,
}, },
&npk, npk,
&vpk, vpk,
&random_seed, random_seed,
new_nullifier, new_nullifier,
new_nonce, new_nonce,
); );
@ -228,18 +225,15 @@ pub fn compute_circuit_output(
); );
let new_nullifier = compute_update_nullifier_and_set_digest( let new_nullifier = compute_update_nullifier_and_set_digest(
&membership_proof, membership_proof,
&pre_state.account, &pre_state.account,
&pre_state.account_id, &pre_state.account_id,
&nsk, nsk,
); );
let new_nonce = pre_state let new_nonce = pre_state.account.nonce.private_account_nonce_increment(nsk);
.account
.nonce
.private_account_nonce_increment(&nsk);
let account_id = pre_state.account_id; let account_id = pre_state.account_id;
let npk = NullifierPublicKey::from(&nsk); let npk = NullifierPublicKey::from(nsk);
let (authority_program_id, seed) = pda_seed_by_position let (authority_program_id, seed) = pda_seed_by_position
.get(&pos) .get(&pos)
.expect("PrivatePdaUpdate position must be in pda_seed_by_position"); .expect("PrivatePdaUpdate position must be in pda_seed_by_position");
@ -251,11 +245,11 @@ pub fn compute_circuit_output(
&PrivateAccountKind::Pda { &PrivateAccountKind::Pda {
program_id: *authority_program_id, program_id: *authority_program_id,
seed: *seed, seed: *seed,
identifier, identifier: *identifier,
}, },
&npk, &npk,
&vpk, vpk,
&random_seed, random_seed,
new_nullifier, new_nullifier,
new_nonce, new_nonce,
); );