diff --git a/integration_tests/tests/auth_transfer/private.rs b/integration_tests/tests/auth_transfer/private.rs index 8136f9df..a472c260 100644 --- a/integration_tests/tests/auth_transfer/private.rs +++ b/integration_tests/tests/auth_transfer/private.rs @@ -81,7 +81,7 @@ async fn private_transfer_to_foreign_account() -> Result<()> { .context("Failed to get private account commitment for sender")?; let tx = fetch_privacy_preserving_tx(ctx.sequencer_client(), tx_hash).await; - assert_eq!(tx.message.new_commitments[0], new_commitment1); + assert!(tx.message.new_commitments.contains(&new_commitment1)); for commitment in tx.message.new_commitments { assert!(verify_commitment_is_in_state(commitment, ctx.sequencer_client()).await); @@ -169,7 +169,7 @@ async fn private_transfer_to_owned_account_using_claiming_path() -> Result<()> { .wallet() .get_private_account_commitment(from) .context("Failed to get private account commitment for sender")?; - assert_eq!(tx.message.new_commitments[0], sender_commitment); + assert!(tx.message.new_commitments.contains(&sender_commitment)); for commitment in tx.message.new_commitments { assert!(verify_commitment_is_in_state(commitment, ctx.sequencer_client()).await); @@ -245,13 +245,9 @@ async fn shielded_transfer_to_foreign_account() -> Result<()> { let acc_1_balance = account_balance(&ctx, from).await?; - assert!( - verify_commitment_is_in_state( - tx.message.new_commitments[0].clone(), - ctx.sequencer_client() - ) - .await - ); + for commitment in tx.message.new_commitments { + assert!(verify_commitment_is_in_state(commitment, ctx.sequencer_client()).await); + } assert_eq!(acc_1_balance, 9900); diff --git a/integration_tests/tests/keys.rs b/integration_tests/tests/keys.rs index f0a66e0e..fb958ec0 100644 --- a/integration_tests/tests/keys.rs +++ b/integration_tests/tests/keys.rs @@ -71,7 +71,7 @@ async fn sync_private_account_with_non_zero_chain_index() -> Result<()> { .wallet() .get_private_account_commitment(from) .context("Failed to get private account commitment for sender")?; - assert_eq!(tx.message.new_commitments[0], new_commitment1); + assert!(tx.message.new_commitments.contains(&new_commitment1)); for commitment in tx.message.new_commitments { assert!(verify_commitment_is_in_state(commitment, ctx.sequencer_client()).await); diff --git a/lee/state_machine/core/src/encryption/mod.rs b/lee/state_machine/core/src/encryption/mod.rs index 3b244b5c..13ad7f5e 100644 --- a/lee/state_machine/core/src/encryption/mod.rs +++ b/lee/state_machine/core/src/encryption/mod.rs @@ -246,11 +246,19 @@ mod tests { // Wrong shared secret must not decrypt correctly. let wrong_ss = SharedSecretKey([0_u8; 32]); - let bad = EncryptionScheme::decrypt(&ct, &wrong_ss, &nullifier); + let bad_via_ss = EncryptionScheme::decrypt(&ct, &wrong_ss, &nullifier); assert!( - bad.is_none() || bad.is_some_and(|(_, a)| a.balance != 999), + bad_via_ss.is_none() || bad_via_ss.is_some_and(|(_, a)| a.balance != 999), "wrong shared secret must not produce the correct plaintext" ); + + // Wrong nullifier must not decrypt correctly. + let wrong_nullifier = Nullifier::for_account_initialization(&AccountId::new([9; 32])); + let bad_via_nlf = EncryptionScheme::decrypt(&ct, &receiver_ss, &wrong_nullifier); + assert!( + bad_via_nlf.is_none() || bad_via_nlf.is_some_and(|(_, a)| a.balance != 999), + "wrong nullifier must not produce the correct plaintext" + ); } #[test] diff --git a/lee/state_machine/src/privacy_preserving_transaction/circuit/tests.rs b/lee/state_machine/src/privacy_preserving_transaction/circuit/tests.rs index 88494861..d5663b6d 100644 --- a/lee/state_machine/src/privacy_preserving_transaction/circuit/tests.rs +++ b/lee/state_machine/src/privacy_preserving_transaction/circuit/tests.rs @@ -218,22 +218,41 @@ fn prove_privacy_preserving_execution_circuit_fully_private() { assert!(proof.is_valid_for(&output)); assert!(output.public_pre_states.is_empty()); assert!(output.public_post_states.is_empty()); + let sender_nullifier = expected_new_nullifiers[0].0; + let recipient_nullifier = expected_new_nullifiers[1].0; + + let mut expected_new_commitments = expected_new_commitments; + expected_new_commitments.sort_unstable_by_key(Commitment::to_byte_array); assert_eq!(output.new_commitments, expected_new_commitments); + + let mut expected_new_nullifiers = expected_new_nullifiers; + expected_new_nullifiers.sort_unstable_by_key(|(nullifier, _)| nullifier.to_byte_array()); assert_eq!(output.new_nullifiers, expected_new_nullifiers); + assert_eq!(output.encrypted_private_post_states.len(), 2); + let sender_slot = output + .new_nullifiers + .iter() + .position(|(nullifier, _)| *nullifier == sender_nullifier) + .unwrap(); let (_identifier, sender_post) = EncryptionScheme::decrypt( - &output.encrypted_private_post_states[0].ciphertext, + &output.encrypted_private_post_states[sender_slot].ciphertext, &shared_secret_1, - &output.new_nullifiers[0].0, + &output.new_nullifiers[sender_slot].0, ) .unwrap(); assert_eq!(sender_post, expected_private_account_1); + let recipient_slot = output + .new_nullifiers + .iter() + .position(|(nullifier, _)| *nullifier == recipient_nullifier) + .unwrap(); let (_identifier, recipient_post) = EncryptionScheme::decrypt( - &output.encrypted_private_post_states[1].ciphertext, + &output.encrypted_private_post_states[recipient_slot].ciphertext, &shared_secret_2, - &output.new_nullifiers[1].0, + &output.new_nullifiers[recipient_slot].0, ) .unwrap(); assert_eq!(recipient_post, expected_private_account_2);