mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-02 13:23:10 +00:00
Merge branch 'main' into Pravdyvy/wallet-privacy-preserving-transactions
This commit is contained in:
commit
8d9e7764aa
@ -14,11 +14,34 @@ pub struct Account {
|
||||
pub nonce: Nonce,
|
||||
}
|
||||
|
||||
/// A fingerprint of the owner of an account. This can be, for example, an `Address` in case the account
|
||||
/// is public, or a `NullifierPublicKey` in case the account is private.
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(any(feature = "host", test), derive(Debug))]
|
||||
pub struct AccountId([u8; 32]);
|
||||
impl AccountId {
|
||||
pub fn new(value: [u8; 32]) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(any(feature = "host", test), derive(Debug, PartialEq, Eq))]
|
||||
pub struct AccountWithMetadata {
|
||||
pub account: Account,
|
||||
pub is_authorized: bool,
|
||||
pub account_id: AccountId,
|
||||
}
|
||||
|
||||
#[cfg(feature = "host")]
|
||||
impl AccountWithMetadata {
|
||||
pub fn new(account: Account, is_authorized: bool, account_id: impl Into<AccountId>) -> Self {
|
||||
Self {
|
||||
account,
|
||||
is_authorized,
|
||||
account_id: account_id.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -54,4 +77,21 @@ mod tests {
|
||||
|
||||
assert_eq!(new_acc.program_owner, DEFAULT_PROGRAM_ID);
|
||||
}
|
||||
|
||||
#[cfg(feature = "host")]
|
||||
#[test]
|
||||
fn test_account_with_metadata_constructor() {
|
||||
let account = Account {
|
||||
program_owner: [1, 2, 3, 4, 5, 6, 7, 8],
|
||||
balance: 1337,
|
||||
data: b"testing_account_with_metadata_constructor".to_vec(),
|
||||
nonce: 0xdeadbeef,
|
||||
};
|
||||
let fingerprint = AccountId::new([8; 32]);
|
||||
let new_acc_with_metadata =
|
||||
AccountWithMetadata::new(account.clone(), true, fingerprint.clone());
|
||||
assert_eq!(new_acc_with_metadata.account, account);
|
||||
assert!(new_acc_with_metadata.is_authorized);
|
||||
assert_eq!(new_acc_with_metadata.account_id, fingerprint);
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
Commitment, Nullifier, NullifierPublicKey,
|
||||
account::{Account, AccountWithMetadata},
|
||||
account::{Account, AccountId, AccountWithMetadata},
|
||||
};
|
||||
use risc0_zkvm::serde::from_slice;
|
||||
|
||||
@ -49,24 +49,26 @@ mod tests {
|
||||
fn test_privacy_preserving_circuit_output_to_bytes_is_compatible_with_from_slice() {
|
||||
let output = PrivacyPreservingCircuitOutput {
|
||||
public_pre_states: vec![
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: [1, 2, 3, 4, 5, 6, 7, 8],
|
||||
balance: 12345678901234567890,
|
||||
data: b"test data".to_vec(),
|
||||
nonce: 18446744073709551614,
|
||||
},
|
||||
is_authorized: true,
|
||||
},
|
||||
AccountWithMetadata {
|
||||
account: Account {
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
),
|
||||
AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: [9, 9, 9, 8, 8, 8, 7, 7],
|
||||
balance: 123123123456456567112,
|
||||
data: b"test data".to_vec(),
|
||||
nonce: 9999999999999999999999,
|
||||
},
|
||||
is_authorized: false,
|
||||
},
|
||||
false,
|
||||
AccountId::new([1; 32]),
|
||||
),
|
||||
],
|
||||
public_post_states: vec![Account {
|
||||
program_owner: [1, 2, 3, 4, 5, 6, 7, 8],
|
||||
|
||||
@ -1,12 +1,23 @@
|
||||
use risc0_zkvm::sha::{Impl, Sha256};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::Commitment;
|
||||
use crate::{Commitment, account::AccountId};
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[cfg_attr(any(feature = "host", test), derive(Debug, Clone, Hash))]
|
||||
pub struct NullifierPublicKey(pub [u8; 32]);
|
||||
|
||||
impl From<&NullifierPublicKey> for AccountId {
|
||||
fn from(value: &NullifierPublicKey) -> Self {
|
||||
const PRIVATE_ACCOUNT_ID_PREFIX: &[u8; 32] = b"/NSSA/v0.1/AccountId/Private/\x00\x00\x00";
|
||||
|
||||
let mut bytes = [0; 64];
|
||||
bytes[0..32].copy_from_slice(PRIVATE_ACCOUNT_ID_PREFIX);
|
||||
bytes[32..].copy_from_slice(&value.0);
|
||||
AccountId::new(Impl::hash_bytes(&bytes).as_bytes().try_into().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<[u8]> for NullifierPublicKey {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
self.0.as_slice()
|
||||
@ -71,4 +82,21 @@ mod tests {
|
||||
let npk = NullifierPublicKey::from(&nsk);
|
||||
assert_eq!(npk, expected_npk);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_account_id_from_nullifier_public_key() {
|
||||
let nsk = [
|
||||
57, 5, 64, 115, 153, 56, 184, 51, 207, 238, 99, 165, 147, 214, 213, 151, 30, 251, 30,
|
||||
196, 134, 22, 224, 211, 237, 120, 136, 225, 188, 220, 249, 28,
|
||||
];
|
||||
let npk = NullifierPublicKey::from(&nsk);
|
||||
let expected_account_id = AccountId::new([
|
||||
69, 160, 50, 67, 12, 56, 150, 116, 62, 145, 17, 161, 17, 45, 24, 53, 33, 167, 83, 178,
|
||||
47, 114, 111, 233, 251, 30, 54, 244, 184, 22, 100, 236,
|
||||
]);
|
||||
|
||||
let account_id = AccountId::from(&npk);
|
||||
|
||||
assert_eq!(account_id, expected_account_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,8 +21,8 @@ pub struct ProgramOutput {
|
||||
|
||||
pub fn read_nssa_inputs<T: DeserializeOwned>() -> ProgramInput<T> {
|
||||
let pre_states: Vec<AccountWithMetadata> = env::read();
|
||||
let words: InstructionData = env::read();
|
||||
let instruction = T::deserialize(&mut Deserializer::new(words.as_ref())).unwrap();
|
||||
let instruction_words: InstructionData = env::read();
|
||||
let instruction = T::deserialize(&mut Deserializer::new(instruction_words.as_ref())).unwrap();
|
||||
ProgramInput {
|
||||
pre_states,
|
||||
instruction,
|
||||
|
||||
@ -1,12 +1,7 @@
|
||||
use risc0_zkvm::{guest::env, serde::to_vec};
|
||||
|
||||
use nssa_core::{
|
||||
account::{Account, AccountWithMetadata},
|
||||
compute_digest_for_path,
|
||||
encryption::Ciphertext,
|
||||
program::{validate_execution, ProgramOutput, DEFAULT_PROGRAM_ID},
|
||||
Commitment, CommitmentSetDigest, EncryptionScheme, Nullifier, NullifierPublicKey,
|
||||
PrivacyPreservingCircuitInput, PrivacyPreservingCircuitOutput,
|
||||
account::{Account, AccountWithMetadata, AccountId}, compute_digest_for_path, encryption::Ciphertext, program::{validate_execution, ProgramOutput, DEFAULT_PROGRAM_ID}, Commitment, CommitmentSetDigest, EncryptionScheme, Nullifier, NullifierPublicKey, PrivacyPreservingCircuitInput, PrivacyPreservingCircuitOutput
|
||||
};
|
||||
|
||||
fn main() {
|
||||
@ -74,6 +69,10 @@ fn main() {
|
||||
let new_nonce = private_nonces_iter.next().expect("Missing private nonce");
|
||||
let (npk, shared_secret) = private_keys_iter.next().expect("Missing keys");
|
||||
|
||||
if AccountId::from(npk) != pre_states[i].account_id {
|
||||
panic!("AccountId mismatch");
|
||||
}
|
||||
|
||||
if visibility_mask[i] == 1 {
|
||||
// Private account with authentication
|
||||
let (nsk, membership_proof) =
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use nssa_core::account::AccountId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use crate::signature::PublicKey;
|
||||
|
||||
@ -81,8 +83,21 @@ impl<'de> Deserialize<'de> for Address {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Address> for AccountId {
|
||||
fn from(address: &Address) -> Self {
|
||||
const PUBLIC_ACCOUNT_ID_PREFIX: &[u8; 32] = b"/NSSA/v0.1/AccountId/Public/\x00\x00\x00\x00";
|
||||
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(PUBLIC_ACCOUNT_ID_PREFIX);
|
||||
hasher.update(address.value);
|
||||
AccountId::new(hasher.finalize().into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use nssa_core::account::AccountId;
|
||||
|
||||
use crate::{Address, address::AddressError};
|
||||
|
||||
#[test]
|
||||
@ -112,4 +127,17 @@ mod tests {
|
||||
let result = hex_str.parse::<Address>().unwrap_err();
|
||||
assert!(matches!(result, AddressError::InvalidLength(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_account_id_from_address() {
|
||||
let address: Address = "37".repeat(32).parse().unwrap();
|
||||
let expected_account_id = AccountId::new([
|
||||
93, 223, 66, 245, 78, 230, 157, 188, 110, 161, 134, 255, 137, 177, 220, 88, 37, 44,
|
||||
243, 91, 236, 4, 36, 147, 185, 112, 21, 49, 234, 4, 107, 185,
|
||||
]);
|
||||
|
||||
let account_id = AccountId::from(&address);
|
||||
|
||||
assert_eq!(account_id, expected_account_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ impl Proof {
|
||||
mod tests {
|
||||
use nssa_core::{
|
||||
Commitment, EncryptionScheme, Nullifier,
|
||||
account::{Account, AccountWithMetadata},
|
||||
account::{Account, AccountId, AccountWithMetadata},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@ -108,20 +108,23 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn prove_privacy_preserving_execution_circuit_public_and_private_pre_accounts() {
|
||||
let recipient_keys = test_private_account_keys_1();
|
||||
let program = Program::authenticated_transfer_program();
|
||||
let sender = AccountWithMetadata {
|
||||
account: Account {
|
||||
let sender = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
|
||||
let recipient = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
};
|
||||
let recipient = AccountWithMetadata::new(
|
||||
Account::default(),
|
||||
false,
|
||||
AccountId::from(&recipient_keys.npk()),
|
||||
);
|
||||
|
||||
let balance_to_move: u128 = 37;
|
||||
|
||||
@ -140,7 +143,6 @@ mod tests {
|
||||
};
|
||||
|
||||
let expected_sender_pre = sender.clone();
|
||||
let recipient_keys = test_private_account_keys_1();
|
||||
|
||||
let esk = [3; 32];
|
||||
let shared_secret = SharedSecretKey::new(&esk, &recipient_keys.ivk());
|
||||
@ -179,23 +181,26 @@ mod tests {
|
||||
#[test]
|
||||
fn prove_privacy_preserving_execution_circuit_fully_private() {
|
||||
let program = Program::authenticated_transfer_program();
|
||||
let sender_pre = AccountWithMetadata {
|
||||
account: Account {
|
||||
let sender_keys = test_private_account_keys_1();
|
||||
let recipient_keys = test_private_account_keys_2();
|
||||
|
||||
let sender_pre = AccountWithMetadata::new(
|
||||
Account {
|
||||
balance: 100,
|
||||
nonce: 0xdeadbeef,
|
||||
program_owner: program.id(),
|
||||
data: vec![],
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let sender_keys = test_private_account_keys_1();
|
||||
let recipient_keys = test_private_account_keys_2();
|
||||
true,
|
||||
AccountId::from(&sender_keys.npk()),
|
||||
);
|
||||
let commitment_sender = Commitment::new(&sender_keys.npk(), &sender_pre.account);
|
||||
|
||||
let recipient = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
};
|
||||
let recipient = AccountWithMetadata::new(
|
||||
Account::default(),
|
||||
false,
|
||||
AccountId::from(&recipient_keys.npk()),
|
||||
);
|
||||
let balance_to_move: u128 = 37;
|
||||
|
||||
let mut commitment_set = CommitmentSet::with_capacity(2);
|
||||
|
||||
@ -90,9 +90,12 @@ impl PrivacyPreservingTransaction {
|
||||
let public_pre_states: Vec<_> = message
|
||||
.public_addresses
|
||||
.iter()
|
||||
.map(|address| AccountWithMetadata {
|
||||
account: state.get_account_by_address(address),
|
||||
is_authorized: signer_addresses.contains(address),
|
||||
.map(|address| {
|
||||
AccountWithMetadata::new(
|
||||
state.get_account_by_address(address),
|
||||
signer_addresses.contains(address),
|
||||
address,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
||||
@ -89,7 +89,7 @@ impl Program {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use nssa_core::account::{Account, AccountWithMetadata};
|
||||
use nssa_core::account::{Account, AccountId, AccountWithMetadata};
|
||||
|
||||
use crate::program::Program;
|
||||
|
||||
@ -180,17 +180,16 @@ mod tests {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let balance_to_move: u128 = 11223344556677;
|
||||
let instruction_data = Program::serialize_instruction(balance_to_move).unwrap();
|
||||
let sender = AccountWithMetadata {
|
||||
account: Account {
|
||||
let sender = AccountWithMetadata::new(
|
||||
Account {
|
||||
balance: 77665544332211,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: false,
|
||||
};
|
||||
let recipient = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let recipient =
|
||||
AccountWithMetadata::new(Account::default(), false, AccountId::new([1; 32]));
|
||||
|
||||
let expected_sender_post = Account {
|
||||
balance: 77665544332211 - balance_to_move,
|
||||
|
||||
@ -91,9 +91,12 @@ impl PublicTransaction {
|
||||
let pre_states: Vec<_> = message
|
||||
.addresses
|
||||
.iter()
|
||||
.map(|address| AccountWithMetadata {
|
||||
account: state.get_account_by_address(address),
|
||||
is_authorized: signer_addresses.contains(address),
|
||||
.map(|address| {
|
||||
AccountWithMetadata::new(
|
||||
state.get_account_by_address(address),
|
||||
signer_addresses.contains(address),
|
||||
address,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
||||
@ -248,7 +248,7 @@ pub mod tests {
|
||||
|
||||
use nssa_core::{
|
||||
Commitment, Nullifier, NullifierPublicKey, NullifierSecretKey, SharedSecretKey,
|
||||
account::{Account, AccountWithMetadata, Nonce},
|
||||
account::{Account, AccountId, AccountWithMetadata, Nonce},
|
||||
encryption::{EphemeralPublicKey, IncomingViewingPublicKey, Scalar},
|
||||
};
|
||||
|
||||
@ -802,17 +802,15 @@ pub mod tests {
|
||||
balance_to_move: u128,
|
||||
state: &V01State,
|
||||
) -> PrivacyPreservingTransaction {
|
||||
let sender = AccountWithMetadata {
|
||||
account: state.get_account_by_address(&sender_keys.address()),
|
||||
is_authorized: true,
|
||||
};
|
||||
let sender = AccountWithMetadata::new(
|
||||
state.get_account_by_address(&sender_keys.address()),
|
||||
true,
|
||||
&sender_keys.address(),
|
||||
);
|
||||
|
||||
let sender_nonce = sender.account.nonce;
|
||||
|
||||
let recipient = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
};
|
||||
let recipient = AccountWithMetadata::new(Account::default(), false, &recipient_keys.npk());
|
||||
|
||||
let esk = [3; 32];
|
||||
let shared_secret = SharedSecretKey::new(&esk, &recipient_keys.ivk());
|
||||
@ -851,14 +849,10 @@ pub mod tests {
|
||||
) -> PrivacyPreservingTransaction {
|
||||
let program = Program::authenticated_transfer_program();
|
||||
let sender_commitment = Commitment::new(&sender_keys.npk(), sender_private_account);
|
||||
let sender_pre = AccountWithMetadata {
|
||||
account: sender_private_account.clone(),
|
||||
is_authorized: true,
|
||||
};
|
||||
let recipient_pre = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
};
|
||||
let sender_pre =
|
||||
AccountWithMetadata::new(sender_private_account.clone(), true, &sender_keys.npk());
|
||||
let recipient_pre =
|
||||
AccountWithMetadata::new(Account::default(), false, &recipient_keys.npk());
|
||||
|
||||
let esk_1 = [3; 32];
|
||||
let shared_secret_1 = SharedSecretKey::new(&esk_1, &sender_keys.ivk());
|
||||
@ -911,14 +905,13 @@ pub mod tests {
|
||||
) -> PrivacyPreservingTransaction {
|
||||
let program = Program::authenticated_transfer_program();
|
||||
let sender_commitment = Commitment::new(&sender_keys.npk(), sender_private_account);
|
||||
let sender_pre = AccountWithMetadata {
|
||||
account: sender_private_account.clone(),
|
||||
is_authorized: true,
|
||||
};
|
||||
let recipient_pre = AccountWithMetadata {
|
||||
account: state.get_account_by_address(recipient_address),
|
||||
is_authorized: false,
|
||||
};
|
||||
let sender_pre =
|
||||
AccountWithMetadata::new(sender_private_account.clone(), true, &sender_keys.npk());
|
||||
let recipient_pre = AccountWithMetadata::new(
|
||||
state.get_account_by_address(recipient_address),
|
||||
false,
|
||||
recipient_address,
|
||||
);
|
||||
|
||||
let esk = [3; 32];
|
||||
let shared_secret = SharedSecretKey::new(&esk, &sender_keys.ivk());
|
||||
@ -1127,14 +1120,15 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_burner_program_should_fail_in_privacy_preserving_circuit() {
|
||||
let program = Program::burner();
|
||||
let public_account = AccountWithMetadata {
|
||||
account: Account {
|
||||
let public_account = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
|
||||
let result = execute_and_prove(
|
||||
&[public_account],
|
||||
@ -1152,14 +1146,15 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_minter_program_should_fail_in_privacy_preserving_circuit() {
|
||||
let program = Program::minter();
|
||||
let public_account = AccountWithMetadata {
|
||||
account: Account {
|
||||
let public_account = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 0,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
|
||||
let result = execute_and_prove(
|
||||
&[public_account],
|
||||
@ -1177,14 +1172,15 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_nonce_changer_program_should_fail_in_privacy_preserving_circuit() {
|
||||
let program = Program::nonce_changer_program();
|
||||
let public_account = AccountWithMetadata {
|
||||
account: Account {
|
||||
let public_account = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 0,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
|
||||
let result = execute_and_prove(
|
||||
&[public_account],
|
||||
@ -1202,14 +1198,15 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_data_changer_program_should_fail_for_non_owned_account_in_privacy_preserving_circuit() {
|
||||
let program = Program::data_changer();
|
||||
let public_account = AccountWithMetadata {
|
||||
account: Account {
|
||||
let public_account = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: [0, 1, 2, 3, 4, 5, 6, 7],
|
||||
balance: 0,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
|
||||
let result = execute_and_prove(
|
||||
&[public_account],
|
||||
@ -1227,14 +1224,15 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_extra_output_program_should_fail_in_privacy_preserving_circuit() {
|
||||
let program = Program::extra_output_program();
|
||||
let public_account = AccountWithMetadata {
|
||||
account: Account {
|
||||
let public_account = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 0,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
|
||||
let result = execute_and_prove(
|
||||
&[public_account],
|
||||
@ -1252,22 +1250,24 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_missing_output_program_should_fail_in_privacy_preserving_circuit() {
|
||||
let program = Program::missing_output_program();
|
||||
let public_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let public_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 0,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let public_account_2 = AccountWithMetadata {
|
||||
account: Account {
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let public_account_2 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 0,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
true,
|
||||
AccountId::new([1; 32]),
|
||||
);
|
||||
|
||||
let result = execute_and_prove(
|
||||
&[public_account_1, public_account_2],
|
||||
@ -1285,14 +1285,15 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_program_owner_changer_should_fail_in_privacy_preserving_circuit() {
|
||||
let program = Program::program_owner_changer();
|
||||
let public_account = AccountWithMetadata {
|
||||
account: Account {
|
||||
let public_account = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 0,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
|
||||
let result = execute_and_prove(
|
||||
&[public_account],
|
||||
@ -1310,22 +1311,24 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_transfer_from_non_owned_account_should_fail_in_privacy_preserving_circuit() {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let public_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let public_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: [0, 1, 2, 3, 4, 5, 6, 7],
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let public_account_2 = AccountWithMetadata {
|
||||
account: Account {
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let public_account_2 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 0,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
true,
|
||||
AccountId::new([1; 32]),
|
||||
);
|
||||
|
||||
let result = execute_and_prove(
|
||||
&[public_account_1, public_account_2],
|
||||
@ -1343,22 +1346,24 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_circuit_fails_if_visibility_masks_have_incorrect_lenght() {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let public_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let public_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let public_account_2 = AccountWithMetadata {
|
||||
account: Account {
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let public_account_2 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 0,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
true,
|
||||
AccountId::new([1; 32]),
|
||||
);
|
||||
|
||||
// Setting only one visibility mask for a circuit execution with two pre_state accounts.
|
||||
let visibility_mask = [0];
|
||||
@ -1380,18 +1385,17 @@ pub mod tests {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let sender_keys = test_private_account_keys_1();
|
||||
let recipient_keys = test_private_account_keys_2();
|
||||
let private_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let private_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let private_account_2 = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let private_account_2 =
|
||||
AccountWithMetadata::new(Account::default(), false, AccountId::new([1; 32]));
|
||||
|
||||
// Setting only one nonce for an execution with two private accounts.
|
||||
let private_account_nonces = [0xdeadbeef1];
|
||||
@ -1421,18 +1425,17 @@ pub mod tests {
|
||||
fn test_circuit_fails_if_insufficient_keys_are_provided() {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let sender_keys = test_private_account_keys_1();
|
||||
let private_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let private_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let private_account_2 = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let private_account_2 =
|
||||
AccountWithMetadata::new(Account::default(), false, AccountId::new([1; 32]));
|
||||
|
||||
// Setting only one key for an execution with two private accounts.
|
||||
let private_account_keys = [(
|
||||
@ -1457,18 +1460,17 @@ pub mod tests {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let sender_keys = test_private_account_keys_1();
|
||||
let recipient_keys = test_private_account_keys_2();
|
||||
let private_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let private_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let private_account_2 = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let private_account_2 =
|
||||
AccountWithMetadata::new(Account::default(), false, AccountId::new([1; 32]));
|
||||
|
||||
// Setting no auth key for an execution with one non default private accounts.
|
||||
let private_account_auth = [];
|
||||
@ -1499,18 +1501,17 @@ pub mod tests {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let sender_keys = test_private_account_keys_1();
|
||||
let recipient_keys = test_private_account_keys_2();
|
||||
let private_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let private_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let private_account_2 = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let private_account_2 =
|
||||
AccountWithMetadata::new(Account::default(), false, AccountId::new([1; 32]));
|
||||
|
||||
let private_account_keys = [
|
||||
// First private account is the sender
|
||||
@ -1548,22 +1549,24 @@ pub mod tests {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let sender_keys = test_private_account_keys_1();
|
||||
let recipient_keys = test_private_account_keys_2();
|
||||
let private_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let private_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let private_account_2 = AccountWithMetadata {
|
||||
account: Account {
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let private_account_2 = AccountWithMetadata::new(
|
||||
Account {
|
||||
// Non default balance
|
||||
balance: 1,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: false,
|
||||
};
|
||||
false,
|
||||
AccountId::new([1; 32]),
|
||||
);
|
||||
|
||||
let result = execute_and_prove(
|
||||
&[private_account_1, private_account_2],
|
||||
@ -1593,22 +1596,24 @@ pub mod tests {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let sender_keys = test_private_account_keys_1();
|
||||
let recipient_keys = test_private_account_keys_2();
|
||||
let private_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let private_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let private_account_2 = AccountWithMetadata {
|
||||
account: Account {
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let private_account_2 = AccountWithMetadata::new(
|
||||
Account {
|
||||
// Non default program_owner
|
||||
program_owner: [0, 1, 2, 3, 4, 5, 6, 7],
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: false,
|
||||
};
|
||||
false,
|
||||
AccountId::new([1; 32]),
|
||||
);
|
||||
|
||||
let result = execute_and_prove(
|
||||
&[private_account_1, private_account_2],
|
||||
@ -1637,22 +1642,24 @@ pub mod tests {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let sender_keys = test_private_account_keys_1();
|
||||
let recipient_keys = test_private_account_keys_2();
|
||||
let private_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let private_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let private_account_2 = AccountWithMetadata {
|
||||
account: Account {
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let private_account_2 = AccountWithMetadata::new(
|
||||
Account {
|
||||
// Non default data
|
||||
data: b"hola mundo".to_vec(),
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: false,
|
||||
};
|
||||
false,
|
||||
AccountId::new([1; 32]),
|
||||
);
|
||||
|
||||
let result = execute_and_prove(
|
||||
&[private_account_1, private_account_2],
|
||||
@ -1681,22 +1688,24 @@ pub mod tests {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let sender_keys = test_private_account_keys_1();
|
||||
let recipient_keys = test_private_account_keys_2();
|
||||
let private_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let private_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let private_account_2 = AccountWithMetadata {
|
||||
account: Account {
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let private_account_2 = AccountWithMetadata::new(
|
||||
Account {
|
||||
// Non default nonce
|
||||
nonce: 0xdeadbeef,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: false,
|
||||
};
|
||||
false,
|
||||
AccountId::new([1; 32]),
|
||||
);
|
||||
|
||||
let result = execute_and_prove(
|
||||
&[private_account_1, private_account_2],
|
||||
@ -1726,19 +1735,21 @@ pub mod tests {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let sender_keys = test_private_account_keys_1();
|
||||
let recipient_keys = test_private_account_keys_2();
|
||||
let private_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let private_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let private_account_2 = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let private_account_2 = AccountWithMetadata::new(
|
||||
Account::default(),
|
||||
// This should be set to false in normal circumstances
|
||||
is_authorized: true,
|
||||
};
|
||||
true,
|
||||
AccountId::new([1; 32]),
|
||||
);
|
||||
|
||||
let result = execute_and_prove(
|
||||
&[private_account_1, private_account_2],
|
||||
@ -1765,18 +1776,17 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_circuit_should_fail_with_invalid_visibility_mask_value() {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let public_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let public_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let public_account_2 = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let public_account_2 =
|
||||
AccountWithMetadata::new(Account::default(), false, AccountId::new([1; 32]));
|
||||
|
||||
let visibility_mask = [0, 3];
|
||||
let result = execute_and_prove(
|
||||
@ -1797,18 +1807,17 @@ pub mod tests {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let sender_keys = test_private_account_keys_1();
|
||||
let recipient_keys = test_private_account_keys_2();
|
||||
let private_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let private_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let private_account_2 = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let private_account_2 =
|
||||
AccountWithMetadata::new(Account::default(), false, AccountId::new([1; 32]));
|
||||
|
||||
// Setting three new private account nonces for a circuit execution with only two private
|
||||
// accounts.
|
||||
@ -1840,18 +1849,17 @@ pub mod tests {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let sender_keys = test_private_account_keys_1();
|
||||
let recipient_keys = test_private_account_keys_2();
|
||||
let private_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let private_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let private_account_2 = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let private_account_2 =
|
||||
AccountWithMetadata::new(Account::default(), false, AccountId::new([1; 32]));
|
||||
|
||||
// Setting three private account keys for a circuit execution with only two private
|
||||
// accounts.
|
||||
@ -1887,18 +1895,17 @@ pub mod tests {
|
||||
let program = Program::simple_balance_transfer();
|
||||
let sender_keys = test_private_account_keys_1();
|
||||
let recipient_keys = test_private_account_keys_2();
|
||||
let private_account_1 = AccountWithMetadata {
|
||||
account: Account {
|
||||
let private_account_1 = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
};
|
||||
let private_account_2 = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
};
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let private_account_2 =
|
||||
AccountWithMetadata::new(Account::default(), false, AccountId::new([1; 32]));
|
||||
|
||||
// Setting two private account keys for a circuit execution with only one non default
|
||||
// private account (visibility mask equal to 1 means that auth keys are expected).
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user