diff --git a/common/src/transaction.rs b/common/src/transaction.rs index 622f9da1..1862dcc8 100644 --- a/common/src/transaction.rs +++ b/common/src/transaction.rs @@ -1,6 +1,6 @@ use borsh::{BorshDeserialize, BorshSerialize}; use log::warn; -use nssa::{AccountId, V02State}; +use nssa::{AccountId, V03State}; use serde::{Deserialize, Serialize}; use crate::{HashType, block::BlockId}; @@ -67,7 +67,7 @@ impl NSSATransaction { pub fn execute_check_on_state( self, - state: &mut V02State, + state: &mut V03State, block_id: BlockId, ) -> Result { match &self { diff --git a/indexer/core/src/block_store.rs b/indexer/core/src/block_store.rs index a1428373..e4534f76 100644 --- a/indexer/core/src/block_store.rs +++ b/indexer/core/src/block_store.rs @@ -6,14 +6,14 @@ use common::{ block::{BedrockStatus, Block, BlockId}, transaction::NSSATransaction, }; -use nssa::{Account, AccountId, V02State}; +use nssa::{Account, AccountId, V03State}; use storage::indexer::RocksDBIO; use tokio::sync::RwLock; #[derive(Clone)] pub struct IndexerStore { dbio: Arc, - current_state: Arc>, + current_state: Arc>, } impl IndexerStore { @@ -24,7 +24,7 @@ impl IndexerStore { pub fn open_db_with_genesis( location: &Path, genesis_block: &Block, - initial_state: &V02State, + initial_state: &V03State, ) -> Result { let dbio = RocksDBIO::open_or_create(location, genesis_block, initial_state)?; let current_state = dbio.final_state()?; @@ -98,14 +98,14 @@ impl IndexerStore { .expect("Must be set at the DB startup") } - pub fn get_state_at_block(&self, block_id: u64) -> Result { + pub fn get_state_at_block(&self, block_id: u64) -> Result { Ok(self.dbio.calculate_state_for_id(block_id)?) } /// Recalculation of final state directly from DB. /// /// Used for indexer healthcheck. - pub fn recalculate_final_state(&self) -> Result { + pub fn recalculate_final_state(&self) -> Result { Ok(self.dbio.final_state()?) } @@ -172,7 +172,7 @@ mod tests { let storage = IndexerStore::open_db_with_genesis( home.as_ref(), &genesis_block(), - &nssa::V02State::new_with_genesis_accounts(&[(acc1(), 10000), (acc2(), 20000)], &[]), + &nssa::V03State::new_with_genesis_accounts(&[(acc1(), 10000), (acc2(), 20000)], &[]), ) .unwrap(); @@ -190,7 +190,7 @@ mod tests { let storage = IndexerStore::open_db_with_genesis( home.as_ref(), &genesis_block(), - &nssa::V02State::new_with_genesis_accounts(&[(acc1(), 10000), (acc2(), 20000)], &[]), + &nssa::V03State::new_with_genesis_accounts(&[(acc1(), 10000), (acc2(), 20000)], &[]), ) .unwrap(); diff --git a/indexer/core/src/lib.rs b/indexer/core/src/lib.rs index 6c96821e..16cd7ac9 100644 --- a/indexer/core/src/lib.rs +++ b/indexer/core/src/lib.rs @@ -80,7 +80,7 @@ impl IndexerCore { .map(|acc_data| (acc_data.account_id, acc_data.balance)) .collect(); - let mut state = nssa::V02State::new_with_genesis_accounts(&init_accs, &initial_commitments); + let mut state = nssa::V03State::new_with_genesis_accounts(&init_accs, &initial_commitments); // ToDo: Remove after testnet state.add_pinata_program(PINATA_BASE58.parse().unwrap()); diff --git a/nssa/core/src/commitment.rs b/nssa/core/src/commitment.rs index 36730dd0..24d5de87 100644 --- a/nssa/core/src/commitment.rs +++ b/nssa/core/src/commitment.rs @@ -12,8 +12,8 @@ use crate::{NullifierPublicKey, account::Account}; /// DUMMY_COMMITMENT = hasher.digest() /// ``` pub const DUMMY_COMMITMENT: Commitment = Commitment([ - 130, 75, 48, 230, 171, 101, 121, 141, 159, 118, 21, 74, 135, 248, 16, 255, 238, 156, 61, 24, - 165, 33, 34, 172, 227, 30, 215, 20, 85, 47, 230, 29, + 55, 228, 215, 207, 112, 221, 239, 49, 238, 79, 71, 135, 155, 15, 184, 45, 104, 74, 51, 211, + 238, 42, 160, 243, 15, 124, 253, 62, 3, 229, 90, 27, ]); /// The hash of the dummy commitment. @@ -24,8 +24,8 @@ pub const DUMMY_COMMITMENT: Commitment = Commitment([ /// DUMMY_COMMITMENT_HASH = hasher.digest() /// ``` pub const DUMMY_COMMITMENT_HASH: [u8; 32] = [ - 170, 10, 217, 228, 20, 35, 189, 177, 238, 235, 97, 129, 132, 89, 96, 247, 86, 91, 222, 214, 38, - 194, 216, 67, 56, 251, 208, 226, 0, 117, 149, 39, + 250, 237, 192, 113, 155, 101, 119, 30, 235, 183, 20, 84, 26, 32, 196, 229, 154, 74, 254, 249, + 129, 241, 118, 39, 41, 253, 141, 171, 184, 71, 8, 41, ]; #[derive(Serialize, Deserialize, BorshSerialize, BorshDeserialize)] @@ -50,10 +50,14 @@ impl std::fmt::Debug for Commitment { impl Commitment { /// Generates the commitment to a private account owned by user for npk: - /// SHA256(npk || `program_owner` || balance || nonce || SHA256(data)). + /// SHA256( `Comm_DS` || npk || `program_owner` || balance || nonce || SHA256(data)). #[must_use] pub fn new(npk: &NullifierPublicKey, account: &Account) -> Self { + const COMMITMENT_PREFIX: &[u8; 32] = + b"/LEE/v0.3/Commitment/\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; + let mut bytes = Vec::new(); + bytes.extend_from_slice(COMMITMENT_PREFIX); bytes.extend_from_slice(&npk.to_byte_array()); let account_bytes_with_hashed_data = { let mut this = Vec::new(); diff --git a/nssa/core/src/nullifier.rs b/nssa/core/src/nullifier.rs index 6ba59860..bb11cb4b 100644 --- a/nssa/core/src/nullifier.rs +++ b/nssa/core/src/nullifier.rs @@ -76,7 +76,7 @@ impl Nullifier { /// Computes a nullifier for an account update. #[must_use] pub fn for_account_update(commitment: &Commitment, nsk: &NullifierSecretKey) -> Self { - const UPDATE_PREFIX: &[u8; 32] = b"/NSSA/v0.2/Nullifier/Update/\x00\x00\x00\x00"; + const UPDATE_PREFIX: &[u8; 32] = b"/LEE/v0.3/Nullifier/Update/\x00\x00\x00\x00\x00"; let mut bytes = UPDATE_PREFIX.to_vec(); bytes.extend_from_slice(&commitment.to_byte_array()); bytes.extend_from_slice(nsk); @@ -86,7 +86,7 @@ impl Nullifier { /// Computes a nullifier for an account initialization. #[must_use] pub fn for_account_initialization(npk: &NullifierPublicKey) -> Self { - const INIT_PREFIX: &[u8; 32] = b"/NSSA/v0.2/Nullifier/Initialize/"; + const INIT_PREFIX: &[u8; 32] = b"/LEE/v0.3/Nullifier/Initialize/\x00"; let mut bytes = INIT_PREFIX.to_vec(); bytes.extend_from_slice(&npk.to_byte_array()); Self(Impl::hash_bytes(&bytes).as_bytes().try_into().unwrap()) @@ -102,8 +102,8 @@ mod tests { let commitment = Commitment((0..32_u8).collect::>().try_into().unwrap()); let nsk = [0x42; 32]; let expected_nullifier = Nullifier([ - 148, 243, 116, 209, 140, 231, 211, 61, 35, 62, 114, 110, 143, 224, 82, 201, 221, 34, - 53, 80, 185, 48, 174, 28, 203, 43, 94, 187, 85, 199, 115, 81, + 70, 162, 122, 15, 33, 237, 244, 216, 89, 223, 90, 50, 94, 184, 210, 144, 174, 64, 189, + 254, 62, 255, 5, 1, 139, 227, 194, 185, 16, 30, 55, 48, ]); let nullifier = Nullifier::for_account_update(&commitment, &nsk); assert_eq!(nullifier, expected_nullifier); @@ -116,8 +116,8 @@ mod tests { 255, 29, 105, 42, 186, 43, 11, 157, 168, 132, 225, 17, 163, ]); let expected_nullifier = Nullifier([ - 1, 6, 59, 168, 16, 146, 65, 252, 255, 91, 48, 85, 116, 189, 110, 218, 110, 136, 163, - 193, 245, 103, 51, 27, 235, 170, 215, 115, 97, 144, 36, 238, + 149, 59, 95, 181, 2, 194, 20, 143, 72, 233, 104, 243, 59, 70, 67, 243, 110, 77, 109, + 132, 139, 111, 51, 125, 128, 92, 107, 46, 252, 4, 20, 149, ]); let nullifier = Nullifier::for_account_initialization(&npk); assert_eq!(nullifier, expected_nullifier); diff --git a/nssa/src/lib.rs b/nssa/src/lib.rs index bc7cf121..ce958354 100644 --- a/nssa/src/lib.rs +++ b/nssa/src/lib.rs @@ -16,7 +16,7 @@ pub use program_deployment_transaction::ProgramDeploymentTransaction; pub use program_methods::PRIVACY_PRESERVING_CIRCUIT_ID; pub use public_transaction::PublicTransaction; pub use signature::{PrivateKey, PublicKey, Signature}; -pub use state::V02State; +pub use state::V03State; pub mod encoding; pub mod error; diff --git a/nssa/src/privacy_preserving_transaction/message.rs b/nssa/src/privacy_preserving_transaction/message.rs index 251bd874..755b54f3 100644 --- a/nssa/src/privacy_preserving_transaction/message.rs +++ b/nssa/src/privacy_preserving_transaction/message.rs @@ -33,11 +33,11 @@ impl EncryptedAccountData { } } - /// Computes the tag as the first byte of SHA256("/NSSA/v0.2/ViewTag/" || Npk || vpk). + /// Computes the tag as the first byte of SHA256("/LEE/v0.3/ViewTag/" || Npk || vpk). #[must_use] pub fn compute_view_tag(npk: &NullifierPublicKey, vpk: &ViewingPublicKey) -> ViewTag { let mut hasher = Sha256::new(); - hasher.update(b"/NSSA/v0.2/ViewTag/"); + hasher.update(b"/LEE/v0.3/ViewTag/"); hasher.update(npk.to_byte_array()); hasher.update(vpk.to_bytes()); let digest: [u8; 32] = hasher.finalize().into(); @@ -184,7 +184,7 @@ pub mod tests { let expected_view_tag = { let mut hasher = Sha256::new(); - hasher.update(b"/NSSA/v0.2/ViewTag/"); + hasher.update(b"/LEE/v0.3/ViewTag/"); hasher.update(npk.to_byte_array()); hasher.update(vpk.to_bytes()); let digest: [u8; 32] = hasher.finalize().into(); diff --git a/nssa/src/privacy_preserving_transaction/transaction.rs b/nssa/src/privacy_preserving_transaction/transaction.rs index 1766af23..b1c30109 100644 --- a/nssa/src/privacy_preserving_transaction/transaction.rs +++ b/nssa/src/privacy_preserving_transaction/transaction.rs @@ -13,7 +13,7 @@ use sha2::{Digest as _, digest::FixedOutput as _}; use super::{message::Message, witness_set::WitnessSet}; use crate::{ - AccountId, V02State, + AccountId, V03State, error::NssaError, privacy_preserving_transaction::{circuit::Proof, message::EncryptedAccountData}, }; @@ -35,7 +35,7 @@ impl PrivacyPreservingTransaction { pub(crate) fn validate_and_produce_public_state_diff( &self, - state: &V02State, + state: &V03State, block_id: BlockId, ) -> Result, NssaError> { let message = &self.message; diff --git a/nssa/src/program_deployment_transaction/transaction.rs b/nssa/src/program_deployment_transaction/transaction.rs index 1e53388d..90387fe6 100644 --- a/nssa/src/program_deployment_transaction/transaction.rs +++ b/nssa/src/program_deployment_transaction/transaction.rs @@ -3,7 +3,7 @@ use nssa_core::account::AccountId; use sha2::{Digest as _, digest::FixedOutput as _}; use crate::{ - V02State, error::NssaError, program::Program, program_deployment_transaction::message::Message, + V03State, error::NssaError, program::Program, program_deployment_transaction::message::Message, }; #[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)] @@ -24,7 +24,7 @@ impl ProgramDeploymentTransaction { pub(crate) fn validate_and_produce_public_state_diff( &self, - state: &V02State, + state: &V03State, ) -> Result { // TODO: remove clone let program = Program::new(self.message.bytecode.clone())?; diff --git a/nssa/src/public_transaction/transaction.rs b/nssa/src/public_transaction/transaction.rs index d0ffc99a..8aaf039e 100644 --- a/nssa/src/public_transaction/transaction.rs +++ b/nssa/src/public_transaction/transaction.rs @@ -9,7 +9,7 @@ use nssa_core::{ use sha2::{Digest as _, digest::FixedOutput as _}; use crate::{ - V02State, ensure, + V03State, ensure, error::NssaError, public_transaction::{Message, WitnessSet}, state::MAX_NUMBER_CHAINED_CALLS, @@ -69,7 +69,7 @@ impl PublicTransaction { pub(crate) fn validate_and_produce_public_state_diff( &self, - state: &V02State, + state: &V03State, block_id: BlockId, ) -> Result, NssaError> { let message = self.message(); @@ -256,7 +256,7 @@ pub mod tests { use sha2::{Digest as _, digest::FixedOutput as _}; use crate::{ - AccountId, PrivateKey, PublicKey, PublicTransaction, Signature, V02State, + AccountId, PrivateKey, PublicKey, PublicTransaction, Signature, V03State, error::NssaError, program::Program, public_transaction::{Message, WitnessSet}, @@ -270,10 +270,10 @@ pub mod tests { (key1, key2, addr1, addr2) } - fn state_for_tests() -> V02State { + fn state_for_tests() -> V03State { let (_, _, addr1, addr2) = keys_for_tests(); let initial_data = [(addr1, 10000), (addr2, 20000)]; - V02State::new_with_genesis_accounts(&initial_data, &[]) + V03State::new_with_genesis_accounts(&initial_data, &[]) } fn transaction_for_tests() -> PublicTransaction { diff --git a/nssa/src/state.rs b/nssa/src/state.rs index e94eea2f..7f2a0ec8 100644 --- a/nssa/src/state.rs +++ b/nssa/src/state.rs @@ -107,13 +107,13 @@ impl BorshDeserialize for NullifierSet { #[derive(Clone, BorshSerialize, BorshDeserialize)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] -pub struct V02State { +pub struct V03State { public_state: HashMap, private_state: (CommitmentSet, NullifierSet), programs: HashMap, } -impl V02State { +impl V03State { #[must_use] pub fn new_with_genesis_accounts( initial_data: &[(AccountId, u128)], @@ -288,7 +288,7 @@ impl V02State { } // TODO: Testnet only. Refactor to prevent compilation on mainnet. -impl V02State { +impl V03State { pub fn add_pinata_program(&mut self, account_id: AccountId) { self.insert_program(Program::pinata()); @@ -320,7 +320,7 @@ impl V02State { } #[cfg(any(test, feature = "test-utils"))] -impl V02State { +impl V03State { pub fn force_insert_account(&mut self, account_id: AccountId, account: Account) { self.public_state.insert(account_id, account); } @@ -344,7 +344,7 @@ pub mod tests { }; use crate::{ - PublicKey, PublicTransaction, V02State, + PublicKey, PublicTransaction, V03State, error::NssaError, execute_and_prove, privacy_preserving_transaction::{ @@ -359,7 +359,7 @@ pub mod tests { state::MAX_NUMBER_CHAINED_CALLS, }; - impl V02State { + impl V03State { /// Include test programs in the builtin programs map. #[must_use] pub fn with_test_programs(mut self) -> Self { @@ -507,7 +507,7 @@ pub mod tests { this }; - let state = V02State::new_with_genesis_accounts(&initial_data, &[]); + let state = V03State::new_with_genesis_accounts(&initial_data, &[]); assert_eq!(state.public_state, expected_public_state); assert_eq!(state.programs, expected_builtin_programs); @@ -515,7 +515,7 @@ pub mod tests { #[test] fn insert_program() { - let mut state = V02State::new_with_genesis_accounts(&[], &[]); + let mut state = V03State::new_with_genesis_accounts(&[], &[]); let program_to_insert = Program::simple_balance_transfer(); let program_id = program_to_insert.id(); assert!(!state.programs.contains_key(&program_id)); @@ -530,7 +530,7 @@ pub mod tests { let key = PrivateKey::try_new([1; 32]).unwrap(); let account_id = AccountId::from(&PublicKey::new_from_private_key(&key)); let initial_data = [(account_id, 100_u128)]; - let state = V02State::new_with_genesis_accounts(&initial_data, &[]); + let state = V03State::new_with_genesis_accounts(&initial_data, &[]); let expected_account = &state.public_state[&account_id]; let account = state.get_account_by_id(account_id); @@ -541,7 +541,7 @@ pub mod tests { #[test] fn get_account_by_account_id_default_account() { let addr2 = AccountId::new([0; 32]); - let state = V02State::new_with_genesis_accounts(&[], &[]); + let state = V03State::new_with_genesis_accounts(&[], &[]); let expected_account = Account::default(); let account = state.get_account_by_id(addr2); @@ -551,7 +551,7 @@ pub mod tests { #[test] fn builtin_programs_getter() { - let state = V02State::new_with_genesis_accounts(&[], &[]); + let state = V03State::new_with_genesis_accounts(&[], &[]); let builtin_programs = state.programs(); @@ -563,7 +563,7 @@ pub mod tests { let key = PrivateKey::try_new([1; 32]).unwrap(); let account_id = AccountId::from(&PublicKey::new_from_private_key(&key)); let initial_data = [(account_id, 100)]; - let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]); + let mut state = V03State::new_with_genesis_accounts(&initial_data, &[]); let from = account_id; let to = AccountId::new([2; 32]); assert_eq!(state.get_account_by_id(to), Account::default()); @@ -583,7 +583,7 @@ pub mod tests { let key = PrivateKey::try_new([1; 32]).unwrap(); let account_id = AccountId::from(&PublicKey::new_from_private_key(&key)); let initial_data = [(account_id, 100)]; - let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]); + let mut state = V03State::new_with_genesis_accounts(&initial_data, &[]); let from = account_id; let from_key = key; let to = AccountId::new([2; 32]); @@ -607,7 +607,7 @@ pub mod tests { let account_id1 = AccountId::from(&PublicKey::new_from_private_key(&key1)); let account_id2 = AccountId::from(&PublicKey::new_from_private_key(&key2)); let initial_data = [(account_id1, 100), (account_id2, 200)]; - let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]); + let mut state = V03State::new_with_genesis_accounts(&initial_data, &[]); let from = account_id2; let from_key = key2; let to = account_id1; @@ -630,7 +630,7 @@ pub mod tests { let key2 = PrivateKey::try_new([2; 32]).unwrap(); let account_id2 = AccountId::from(&PublicKey::new_from_private_key(&key2)); let initial_data = [(account_id1, 100)]; - let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]); + let mut state = V03State::new_with_genesis_accounts(&initial_data, &[]); let account_id3 = AccountId::new([3; 32]); let balance_to_move = 5; @@ -652,7 +652,7 @@ pub mod tests { fn program_should_fail_if_modifies_nonces() { let initial_data = [(AccountId::new([1; 32]), 100)]; let mut state = - V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); + V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let account_ids = vec![AccountId::new([1; 32])]; let program_id = Program::nonce_changer_program().id(); let message = @@ -669,7 +669,7 @@ pub mod tests { fn program_should_fail_if_output_accounts_exceed_inputs() { let initial_data = [(AccountId::new([1; 32]), 100)]; let mut state = - V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); + V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let account_ids = vec![AccountId::new([1; 32])]; let program_id = Program::extra_output_program().id(); let message = @@ -686,7 +686,7 @@ pub mod tests { fn program_should_fail_with_missing_output_accounts() { let initial_data = [(AccountId::new([1; 32]), 100)]; let mut state = - V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); + V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let account_ids = vec![AccountId::new([1; 32]), AccountId::new([2; 32])]; let program_id = Program::missing_output_program().id(); let message = @@ -703,7 +703,7 @@ pub mod tests { fn program_should_fail_if_modifies_program_owner_with_only_non_default_program_owner() { let initial_data = [(AccountId::new([1; 32]), 0)]; let mut state = - V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); + V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let account_id = AccountId::new([1; 32]); let account = state.get_account_by_id(account_id); // Assert the target account only differs from the default account in the program owner @@ -726,7 +726,7 @@ pub mod tests { #[test] fn program_should_fail_if_modifies_program_owner_with_only_non_default_balance() { let initial_data = []; - let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]) + let mut state = V03State::new_with_genesis_accounts(&initial_data, &[]) .with_test_programs() .with_non_default_accounts_but_default_program_owners(); let account_id = AccountId::new([255; 32]); @@ -750,7 +750,7 @@ pub mod tests { #[test] fn program_should_fail_if_modifies_program_owner_with_only_non_default_nonce() { let initial_data = []; - let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]) + let mut state = V03State::new_with_genesis_accounts(&initial_data, &[]) .with_test_programs() .with_non_default_accounts_but_default_program_owners(); let account_id = AccountId::new([254; 32]); @@ -774,7 +774,7 @@ pub mod tests { #[test] fn program_should_fail_if_modifies_program_owner_with_only_non_default_data() { let initial_data = []; - let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]) + let mut state = V03State::new_with_genesis_accounts(&initial_data, &[]) .with_test_programs() .with_non_default_accounts_but_default_program_owners(); let account_id = AccountId::new([253; 32]); @@ -799,7 +799,7 @@ pub mod tests { fn program_should_fail_if_transfers_balance_from_non_owned_account() { let initial_data = [(AccountId::new([1; 32]), 100)]; let mut state = - V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); + V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let sender_account_id = AccountId::new([1; 32]); let receiver_account_id = AccountId::new([2; 32]); let balance_to_move: u128 = 1; @@ -826,7 +826,7 @@ pub mod tests { #[test] fn program_should_fail_if_modifies_data_of_non_owned_account() { let initial_data = []; - let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]) + let mut state = V03State::new_with_genesis_accounts(&initial_data, &[]) .with_test_programs() .with_non_default_accounts_but_default_program_owners(); let account_id = AccountId::new([255; 32]); @@ -852,7 +852,7 @@ pub mod tests { fn program_should_fail_if_does_not_preserve_total_balance_by_minting() { let initial_data = []; let mut state = - V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); + V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let account_id = AccountId::new([1; 32]); let program_id = Program::minter().id(); @@ -869,7 +869,7 @@ pub mod tests { #[test] fn program_should_fail_if_does_not_preserve_total_balance_by_burning() { let initial_data = []; - let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]) + let mut state = V03State::new_with_genesis_accounts(&initial_data, &[]) .with_test_programs() .with_account_owned_by_burner_program(); let program_id = Program::burner().id(); @@ -919,7 +919,7 @@ pub mod tests { sender_keys: &TestPublicKeys, recipient_keys: &TestPrivateKeys, balance_to_move: u128, - state: &V02State, + state: &V03State, ) -> PrivacyPreservingTransaction { let sender = AccountWithMetadata::new( state.get_account_by_id(sender_keys.account_id()), @@ -963,7 +963,7 @@ pub mod tests { sender_private_account: &Account, recipient_keys: &TestPrivateKeys, balance_to_move: u128, - state: &V02State, + state: &V03State, ) -> PrivacyPreservingTransaction { let program = Program::authenticated_transfer_program(); let sender_commitment = Commitment::new(&sender_keys.npk(), sender_private_account); @@ -1015,7 +1015,7 @@ pub mod tests { sender_private_account: &Account, recipient_account_id: &AccountId, balance_to_move: u128, - state: &V02State, + state: &V03State, ) -> PrivacyPreservingTransaction { let program = Program::authenticated_transfer_program(); let sender_commitment = Commitment::new(&sender_keys.npk(), sender_private_account); @@ -1061,7 +1061,7 @@ pub mod tests { let recipient_keys = test_private_account_keys_1(); let mut state = - V02State::new_with_genesis_accounts(&[(sender_keys.account_id(), 200)], &[]); + V03State::new_with_genesis_accounts(&[(sender_keys.account_id(), 200)], &[]); let balance_to_move = 37; @@ -1109,7 +1109,7 @@ pub mod tests { }; let recipient_keys = test_private_account_keys_2(); - let mut state = V02State::new_with_genesis_accounts(&[], &[]) + let mut state = V03State::new_with_genesis_accounts(&[], &[]) .with_private_account(&sender_keys, &sender_private_account); let balance_to_move = 37; @@ -1176,7 +1176,7 @@ pub mod tests { }; let recipient_keys = test_public_account_keys_1(); let recipient_initial_balance = 400; - let mut state = V02State::new_with_genesis_accounts( + let mut state = V03State::new_with_genesis_accounts( &[(recipient_keys.account_id(), recipient_initial_balance)], &[], ) @@ -2130,7 +2130,7 @@ pub mod tests { }; let recipient_keys = test_private_account_keys_2(); - let mut state = V02State::new_with_genesis_accounts(&[], &[]) + let mut state = V03State::new_with_genesis_accounts(&[], &[]) .with_private_account(&sender_keys, &sender_private_account); let balance_to_move = 37; @@ -2215,7 +2215,7 @@ pub mod tests { let initial_balance = 100; let initial_data = [(account_id, initial_balance)]; let mut state = - V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); + V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let from = account_id; let from_key = key; let to = AccountId::new([2; 32]); @@ -2256,7 +2256,7 @@ pub mod tests { let initial_balance = 1000; let initial_data = [(from, initial_balance), (to, 0)]; let mut state = - V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); + V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let from_key = key; let amount: u128 = 37; let instruction: (u128, ProgramId, u32, Option) = ( @@ -2301,7 +2301,7 @@ pub mod tests { let initial_balance = 100; let initial_data = [(from, initial_balance), (to, 0)]; let mut state = - V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); + V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let from_key = key; let amount: u128 = 0; let instruction: (u128, ProgramId, u32, Option) = ( @@ -2339,7 +2339,7 @@ pub mod tests { let initial_balance = 1000; let initial_data = [(from, initial_balance), (to, 0)]; let mut state = - V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); + V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let amount: u128 = 58; let instruction: (u128, ProgramId, u32, Option) = ( amount, @@ -2385,7 +2385,7 @@ pub mod tests { let initial_balance = 100; let initial_data = [(account_id, initial_balance)]; let mut state = - V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); + V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let from = account_id; let from_key = key; let to = AccountId::new([2; 32]); @@ -2457,7 +2457,7 @@ pub mod tests { let from_commitment = Commitment::new(&from_keys.npk(), &from_account.account); let to_commitment = Commitment::new(&to_keys.npk(), &to_account.account); - let mut state = V02State::new_with_genesis_accounts( + let mut state = V03State::new_with_genesis_accounts( &[], &[from_commitment.clone(), to_commitment.clone()], ) @@ -2566,7 +2566,7 @@ pub mod tests { ..Account::default() }; - let mut state = V02State::new_with_genesis_accounts(&[], &[]); + let mut state = V03State::new_with_genesis_accounts(&[], &[]); state.add_pinata_token_program(pinata_definition_id); // Execution of the token program to create new token for the pinata token @@ -2627,7 +2627,7 @@ pub mod tests { #[test] fn claiming_mechanism_cannot_claim_initialied_accounts() { let claimer = Program::claimer(); - let mut state = V02State::new_with_genesis_accounts(&[], &[]).with_test_programs(); + let mut state = V03State::new_with_genesis_accounts(&[], &[]).with_test_programs(); let account_id = AccountId::new([2; 32]); // Insert an account with non-default program owner @@ -2662,7 +2662,7 @@ pub mod tests { let recipient_id = AccountId::from(&PublicKey::new_from_private_key(&recipient_key)); let recipient_init_balance: u128 = 10; - let mut state = V02State::new_with_genesis_accounts( + let mut state = V03State::new_with_genesis_accounts( &[ (sender_id, sender_init_balance), (recipient_id, recipient_init_balance), @@ -2717,7 +2717,7 @@ pub mod tests { #[test] fn private_authorized_uninitialized_account() { - let mut state = V02State::new_with_genesis_accounts(&[], &[]); + let mut state = V03State::new_with_genesis_accounts(&[], &[]); // Set up keys for the authorized private account let private_keys = test_private_account_keys_1(); @@ -2769,7 +2769,7 @@ pub mod tests { #[test] fn private_account_claimed_then_used_without_init_flag_should_fail() { - let mut state = V02State::new_with_genesis_accounts(&[], &[]).with_test_programs(); + let mut state = V03State::new_with_genesis_accounts(&[], &[]).with_test_programs(); // Set up keys for the private account let private_keys = test_private_account_keys_1(); @@ -2850,7 +2850,7 @@ pub mod tests { fn public_changer_claimer_no_data_change_no_claim_succeeds() { let initial_data = []; let mut state = - V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); + V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let account_id = AccountId::new([1; 32]); let program_id = Program::changer_claimer().id(); // Don't change data (None) and don't claim (false) @@ -2874,7 +2874,7 @@ pub mod tests { fn public_changer_claimer_data_change_no_claim_fails() { let initial_data = []; let mut state = - V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); + V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let account_id = AccountId::new([1; 32]); let program_id = Program::changer_claimer().id(); // Change data but don't claim (false) - should fail @@ -2968,7 +2968,7 @@ pub mod tests { let recipient_commitment = Commitment::new(&recipient_keys.npk(), &recipient_account.account); - let state = V02State::new_with_genesis_accounts( + let state = V03State::new_with_genesis_accounts( &[(sender_account.account_id, sender_account.account.balance)], std::slice::from_ref(&recipient_commitment), ) @@ -3019,7 +3019,7 @@ pub mod tests { let validity_window_program = Program::validity_window(); let account_keys = test_public_account_keys_1(); let pre = AccountWithMetadata::new(Account::default(), false, account_keys.account_id()); - let mut state = V02State::new_with_genesis_accounts(&[], &[]).with_test_programs(); + let mut state = V03State::new_with_genesis_accounts(&[], &[]).with_test_programs(); let tx = { let account_ids = vec![pre.account_id]; let nonces = vec![]; @@ -3068,7 +3068,7 @@ pub mod tests { let validity_window_program = Program::validity_window(); let account_keys = test_private_account_keys_1(); let pre = AccountWithMetadata::new(Account::default(), false, &account_keys.npk()); - let mut state = V02State::new_with_genesis_accounts(&[], &[]).with_test_programs(); + let mut state = V03State::new_with_genesis_accounts(&[], &[]).with_test_programs(); let tx = { let esk = [3; 32]; let shared_secret = SharedSecretKey::new(&esk, &account_keys.vpk()); @@ -3115,9 +3115,9 @@ pub mod tests { let account_id_1 = AccountId::new([1; 32]); let account_id_2 = AccountId::new([2; 32]); let initial_data = [(account_id_1, 100_u128), (account_id_2, 151_u128)]; - let state = V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); + let state = V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let bytes = borsh::to_vec(&state).unwrap(); - let state_from_bytes: V02State = borsh::from_slice(&bytes).unwrap(); + let state_from_bytes: V03State = borsh::from_slice(&bytes).unwrap(); assert_eq!(state, state_from_bytes); } } diff --git a/programs/amm/src/tests.rs b/programs/amm/src/tests.rs index 0ec7c3de..86fdb4ff 100644 --- a/programs/amm/src/tests.rs +++ b/programs/amm/src/tests.rs @@ -5,7 +5,7 @@ use amm_core::{ compute_pool_pda, compute_vault_pda, compute_vault_pda_seed, }; use nssa::{ - PrivateKey, PublicKey, PublicTransaction, V02State, program::Program, public_transaction, + PrivateKey, PublicKey, PublicTransaction, V03State, program::Program, public_transaction, }; use nssa_core::{ account::{Account, AccountId, AccountWithMetadata, Data}, @@ -2636,9 +2636,9 @@ fn new_definition_lp_symmetric_amounts() { assert_eq!(chained_call_lp, expected_lp_call); } -fn state_for_amm_tests() -> V02State { +fn state_for_amm_tests() -> V03State { let initial_data = []; - let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]); + let mut state = V03State::new_with_genesis_accounts(&initial_data, &[]); state.force_insert_account( IdForExeTests::pool_definition_id(), AccountsForExeTests::pool_definition_init(), @@ -2679,9 +2679,9 @@ fn state_for_amm_tests() -> V02State { state } -fn state_for_amm_tests_with_new_def() -> V02State { +fn state_for_amm_tests_with_new_def() -> V03State { let initial_data = []; - let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]); + let mut state = V03State::new_with_genesis_accounts(&initial_data, &[]); state.force_insert_account( IdForExeTests::token_a_definition_id(), AccountsForExeTests::token_a_definition_account(), diff --git a/sequencer/core/src/block_store.rs b/sequencer/core/src/block_store.rs index 7a226d45..9c4c875a 100644 --- a/sequencer/core/src/block_store.rs +++ b/sequencer/core/src/block_store.rs @@ -6,7 +6,7 @@ use common::{ block::{Block, BlockMeta, MantleMsgId}, transaction::NSSATransaction, }; -use nssa::V02State; +use nssa::V03State; use storage::{error::DbError, sequencer::RocksDBIO}; pub struct SequencerStore { @@ -92,7 +92,7 @@ impl SequencerStore { &mut self, block: &Block, msg_id: MantleMsgId, - state: &V02State, + state: &V03State, ) -> Result<()> { let new_transactions_map = block_to_transactions_map(block); self.dbio.atomic_update(block, msg_id, state)?; @@ -100,7 +100,7 @@ impl SequencerStore { Ok(()) } - pub fn get_nssa_state(&self) -> Option { + pub fn get_nssa_state(&self) -> Option { self.dbio.get_nssa_state().ok() } } @@ -150,7 +150,7 @@ mod tests { let retrieved_tx = node_store.get_transaction_by_hash(tx.hash()); assert_eq!(None, retrieved_tx); // Add the block with the transaction - let dummy_state = V02State::new_with_genesis_accounts(&[], &[]); + let dummy_state = V03State::new_with_genesis_accounts(&[], &[]); node_store.update(&block, [1; 32], &dummy_state).unwrap(); // Try again let retrieved_tx = node_store.get_transaction_by_hash(tx.hash()); @@ -209,7 +209,7 @@ mod tests { let block_hash = block.header.hash; let block_msg_id = [1; 32]; - let dummy_state = V02State::new_with_genesis_accounts(&[], &[]); + let dummy_state = V03State::new_with_genesis_accounts(&[], &[]); node_store .update(&block, block_msg_id, &dummy_state) .unwrap(); @@ -244,7 +244,7 @@ mod tests { let block = common::test_utils::produce_dummy_block(1, None, vec![tx]); let block_id = block.header.block_id; - let dummy_state = V02State::new_with_genesis_accounts(&[], &[]); + let dummy_state = V03State::new_with_genesis_accounts(&[], &[]); node_store.update(&block, [1; 32], &dummy_state).unwrap(); // Verify initial status is Pending diff --git a/sequencer/core/src/lib.rs b/sequencer/core/src/lib.rs index 1e015edb..cd20467b 100644 --- a/sequencer/core/src/lib.rs +++ b/sequencer/core/src/lib.rs @@ -35,7 +35,7 @@ pub struct SequencerCore< BC: BlockSettlementClientTrait = BlockSettlementClient, IC: IndexerClientTrait = IndexerClient, > { - state: nssa::V02State, + state: nssa::V03State, store: SequencerStore, mempool: MemPool, sequencer_config: SequencerConfig, @@ -121,7 +121,7 @@ impl SequencerCore SequencerCore &nssa::V02State { + pub const fn state(&self) -> &nssa::V03State { &self.state } diff --git a/storage/src/indexer.rs b/storage/src/indexer.rs index d285c333..07ceba8a 100644 --- a/storage/src/indexer.rs +++ b/storage/src/indexer.rs @@ -4,7 +4,7 @@ use common::{ block::{Block, BlockId}, transaction::NSSATransaction, }; -use nssa::V02State; +use nssa::V03State; use rocksdb::{ BoundColumnFamily, ColumnFamilyDescriptor, DBWithThreadMode, MultiThreaded, Options, WriteBatch, }; @@ -63,7 +63,7 @@ impl RocksDBIO { pub fn open_or_create( path: &Path, genesis_block: &Block, - initial_state: &V02State, + initial_state: &V03State, ) -> DbResult { let mut cf_opts = Options::default(); cf_opts.set_max_write_buffer_number(16); @@ -594,7 +594,7 @@ impl RocksDBIO { // State - pub fn put_breakpoint(&self, br_id: u64, breakpoint: &V02State) -> DbResult<()> { + pub fn put_breakpoint(&self, br_id: u64, breakpoint: &V03State) -> DbResult<()> { let cf_br = self.breakpoint_column(); self.db @@ -616,7 +616,7 @@ impl RocksDBIO { .map_err(|rerr| DbError::rocksdb_cast_message(rerr, None)) } - fn get_breakpoint(&self, br_id: u64) -> DbResult { + pub fn get_breakpoint(&self, br_id: u64) -> DbResult { let cf_br = self.breakpoint_column(); let res = self .db @@ -632,7 +632,7 @@ impl RocksDBIO { .map_err(|rerr| DbError::rocksdb_cast_message(rerr, None))?; if let Some(data) = res { - Ok(borsh::from_slice::(&data).map_err(|serr| { + Ok(borsh::from_slice::(&data).map_err(|serr| { DbError::borsh_cast_message( serr, Some("Failed to deserialize breakpoint data".to_owned()), @@ -647,7 +647,7 @@ impl RocksDBIO { } } - pub fn calculate_state_for_id(&self, block_id: u64) -> DbResult { + pub fn calculate_state_for_id(&self, block_id: u64) -> DbResult { let last_block = self.get_meta_last_block_in_db()?; if block_id <= last_block { @@ -694,7 +694,7 @@ impl RocksDBIO { } } - pub fn final_state(&self) -> DbResult { + pub fn final_state(&self) -> DbResult { self.calculate_state_for_id(self.get_meta_last_block_in_db()?) } @@ -989,8 +989,8 @@ mod tests { nssa::PrivateKey::try_new([2; 32]).unwrap() } - fn initial_state() -> V02State { - nssa::V02State::new_with_genesis_accounts(&[(acc1(), 10000), (acc2(), 20000)], &[]) + fn initial_state() -> V03State { + nssa::V03State::new_with_genesis_accounts(&[(acc1(), 10000), (acc2(), 20000)], &[]) } fn transfer(amount: u128, nonce: u128, direction: bool) -> NSSATransaction { diff --git a/storage/src/sequencer.rs b/storage/src/sequencer.rs index 143b96ce..17d0e73e 100644 --- a/storage/src/sequencer.rs +++ b/storage/src/sequencer.rs @@ -1,7 +1,7 @@ use std::{path::Path, sync::Arc}; use common::block::{BedrockStatus, Block, BlockMeta, MantleMsgId}; -use nssa::V02State; +use nssa::V03State; use rocksdb::{ BoundColumnFamily, ColumnFamilyDescriptor, DBWithThreadMode, MultiThreaded, Options, WriteBatch, }; @@ -195,7 +195,7 @@ impl RocksDBIO { Ok(res.is_some()) } - pub fn put_nssa_state_in_db(&self, state: &V02State, batch: &mut WriteBatch) -> DbResult<()> { + pub fn put_nssa_state_in_db(&self, state: &V03State, batch: &mut WriteBatch) -> DbResult<()> { let cf_nssa_state = self.nssa_state_column(); batch.put_cf( &cf_nssa_state, @@ -469,7 +469,7 @@ impl RocksDBIO { } } - pub fn get_nssa_state(&self) -> DbResult { + pub fn get_nssa_state(&self) -> DbResult { let cf_nssa_state = self.nssa_state_column(); let res = self .db @@ -485,7 +485,7 @@ impl RocksDBIO { .map_err(|rerr| DbError::rocksdb_cast_message(rerr, None))?; if let Some(data) = res { - Ok(borsh::from_slice::(&data).map_err(|serr| { + Ok(borsh::from_slice::(&data).map_err(|serr| { DbError::borsh_cast_message( serr, Some("Failed to deserialize block data".to_owned()), @@ -580,7 +580,7 @@ impl RocksDBIO { &self, block: &Block, msg_id: MantleMsgId, - state: &V02State, + state: &V03State, ) -> DbResult<()> { let block_id = block.header.block_id; let mut batch = WriteBatch::default();