mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-08 00:03:09 +00:00
rename V01State to V02State
This commit is contained in:
parent
f3fbae66b5
commit
19215ee009
@ -18,4 +18,4 @@ pub use public_transaction::PublicTransaction;
|
||||
pub use signature::PrivateKey;
|
||||
pub use signature::PublicKey;
|
||||
pub use signature::Signature;
|
||||
pub use state::V01State;
|
||||
pub use state::V02State;
|
||||
|
||||
@ -8,7 +8,7 @@ use nssa_core::{
|
||||
use crate::error::NssaError;
|
||||
use crate::privacy_preserving_transaction::circuit::Proof;
|
||||
use crate::privacy_preserving_transaction::message::EncryptedAccountData;
|
||||
use crate::{Address, V01State};
|
||||
use crate::{Address, V02State};
|
||||
|
||||
use super::message::Message;
|
||||
use super::witness_set::WitnessSet;
|
||||
@ -29,7 +29,7 @@ impl PrivacyPreservingTransaction {
|
||||
|
||||
pub(crate) fn validate_and_produce_public_state_diff(
|
||||
&self,
|
||||
state: &V01State,
|
||||
state: &V02State,
|
||||
) -> Result<HashMap<Address, Account>, NssaError> {
|
||||
let message = &self.message;
|
||||
let witness_set = &self.witness_set;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
V01State, error::NssaError, program::Program, program_deployment_transaction::message::Message,
|
||||
V02State, error::NssaError, program::Program, program_deployment_transaction::message::Message,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@ -14,7 +14,7 @@ impl ProgramDeploymentTransaction {
|
||||
|
||||
pub(crate) fn validate_and_produce_public_state_diff(
|
||||
&self,
|
||||
state: &V01State,
|
||||
state: &V02State,
|
||||
) -> Result<Program, NssaError> {
|
||||
// TODO: remove clone
|
||||
let program = Program::new(self.message.bytecode.clone())?;
|
||||
|
||||
@ -8,7 +8,7 @@ use nssa_core::{
|
||||
use sha2::{Digest, digest::FixedOutput};
|
||||
|
||||
use crate::{
|
||||
V01State,
|
||||
V02State,
|
||||
error::NssaError,
|
||||
public_transaction::{Message, WitnessSet},
|
||||
};
|
||||
@ -52,7 +52,7 @@ impl PublicTransaction {
|
||||
|
||||
pub(crate) fn validate_and_produce_public_state_diff(
|
||||
&self,
|
||||
state: &V01State,
|
||||
state: &V02State,
|
||||
) -> Result<HashMap<Address, Account>, NssaError> {
|
||||
let message = self.message();
|
||||
let witness_set = self.witness_set();
|
||||
@ -123,7 +123,7 @@ pub mod tests {
|
||||
use sha2::{Digest, digest::FixedOutput};
|
||||
|
||||
use crate::{
|
||||
Address, PrivateKey, PublicKey, PublicTransaction, Signature, V01State,
|
||||
Address, PrivateKey, PublicKey, PublicTransaction, Signature, V02State,
|
||||
error::NssaError,
|
||||
program::Program,
|
||||
public_transaction::{Message, WitnessSet},
|
||||
@ -137,10 +137,10 @@ pub mod tests {
|
||||
(key1, key2, addr1, addr2)
|
||||
}
|
||||
|
||||
fn state_for_tests() -> V01State {
|
||||
fn state_for_tests() -> V02State {
|
||||
let (_, _, addr1, addr2) = keys_for_tests();
|
||||
let initial_data = [(addr1, 10000), (addr2, 20000)];
|
||||
V01State::new_with_genesis_accounts(&initial_data, &[])
|
||||
V02State::new_with_genesis_accounts(&initial_data, &[])
|
||||
}
|
||||
|
||||
fn transaction_for_tests() -> PublicTransaction {
|
||||
|
||||
@ -59,13 +59,13 @@ impl CommitmentSet {
|
||||
|
||||
type NullifierSet = HashSet<Nullifier>;
|
||||
|
||||
pub struct V01State {
|
||||
pub struct V02State {
|
||||
public_state: HashMap<Address, Account>,
|
||||
private_state: (CommitmentSet, NullifierSet),
|
||||
programs: HashMap<ProgramId, Program>,
|
||||
}
|
||||
|
||||
impl V01State {
|
||||
impl V02State {
|
||||
pub fn new_with_genesis_accounts(
|
||||
initial_data: &[(Address, u128)],
|
||||
initial_commitments: &[nssa_core::Commitment],
|
||||
@ -225,7 +225,7 @@ impl V01State {
|
||||
}
|
||||
|
||||
// TODO: Testnet only. Refactor to prevent compilation on mainnet.
|
||||
impl V01State {
|
||||
impl V02State {
|
||||
pub fn add_pinata_program(&mut self, address: Address) {
|
||||
self.insert_program(Program::pinata());
|
||||
|
||||
@ -248,7 +248,7 @@ pub mod tests {
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
Address, PublicKey, PublicTransaction, V01State,
|
||||
Address, PublicKey, PublicTransaction, V02State,
|
||||
error::NssaError,
|
||||
execute_and_prove,
|
||||
privacy_preserving_transaction::{
|
||||
@ -319,7 +319,7 @@ pub mod tests {
|
||||
this
|
||||
};
|
||||
|
||||
let state = V01State::new_with_genesis_accounts(&initial_data, &[]);
|
||||
let state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
||||
|
||||
assert_eq!(state.public_state, expected_public_state);
|
||||
assert_eq!(state.programs, expected_builtin_programs);
|
||||
@ -327,7 +327,7 @@ pub mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_insert_program() {
|
||||
let mut state = V01State::new_with_genesis_accounts(&[], &[]);
|
||||
let mut state = V02State::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));
|
||||
@ -342,7 +342,7 @@ pub mod tests {
|
||||
let key = PrivateKey::try_new([1; 32]).unwrap();
|
||||
let addr = Address::from(&PublicKey::new_from_private_key(&key));
|
||||
let initial_data = [(addr, 100u128)];
|
||||
let state = V01State::new_with_genesis_accounts(&initial_data, &[]);
|
||||
let state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
||||
let expected_account = state.public_state.get(&addr).unwrap();
|
||||
|
||||
let account = state.get_account_by_address(&addr);
|
||||
@ -353,7 +353,7 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_get_account_by_address_default_account() {
|
||||
let addr2 = Address::new([0; 32]);
|
||||
let state = V01State::new_with_genesis_accounts(&[], &[]);
|
||||
let state = V02State::new_with_genesis_accounts(&[], &[]);
|
||||
let expected_account = Account::default();
|
||||
|
||||
let account = state.get_account_by_address(&addr2);
|
||||
@ -363,7 +363,7 @@ pub mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_builtin_programs_getter() {
|
||||
let state = V01State::new_with_genesis_accounts(&[], &[]);
|
||||
let state = V02State::new_with_genesis_accounts(&[], &[]);
|
||||
|
||||
let builtin_programs = state.programs();
|
||||
|
||||
@ -375,7 +375,7 @@ pub mod tests {
|
||||
let key = PrivateKey::try_new([1; 32]).unwrap();
|
||||
let address = Address::from(&PublicKey::new_from_private_key(&key));
|
||||
let initial_data = [(address, 100)];
|
||||
let mut state = V01State::new_with_genesis_accounts(&initial_data, &[]);
|
||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
||||
let from = address;
|
||||
let to = Address::new([2; 32]);
|
||||
assert_eq!(state.get_account_by_address(&to), Account::default());
|
||||
@ -395,7 +395,7 @@ pub mod tests {
|
||||
let key = PrivateKey::try_new([1; 32]).unwrap();
|
||||
let address = Address::from(&PublicKey::new_from_private_key(&key));
|
||||
let initial_data = [(address, 100)];
|
||||
let mut state = V01State::new_with_genesis_accounts(&initial_data, &[]);
|
||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
||||
let from = address;
|
||||
let from_key = key;
|
||||
let to = Address::new([2; 32]);
|
||||
@ -419,7 +419,7 @@ pub mod tests {
|
||||
let address1 = Address::from(&PublicKey::new_from_private_key(&key1));
|
||||
let address2 = Address::from(&PublicKey::new_from_private_key(&key2));
|
||||
let initial_data = [(address1, 100), (address2, 200)];
|
||||
let mut state = V01State::new_with_genesis_accounts(&initial_data, &[]);
|
||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
||||
let from = address2;
|
||||
let from_key = key2;
|
||||
let to = address1;
|
||||
@ -442,7 +442,7 @@ pub mod tests {
|
||||
let key2 = PrivateKey::try_new([2; 32]).unwrap();
|
||||
let address2 = Address::from(&PublicKey::new_from_private_key(&key2));
|
||||
let initial_data = [(address1, 100)];
|
||||
let mut state = V01State::new_with_genesis_accounts(&initial_data, &[]);
|
||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
||||
let address3 = Address::new([3; 32]);
|
||||
let balance_to_move = 5;
|
||||
|
||||
@ -460,7 +460,7 @@ pub mod tests {
|
||||
assert_eq!(state.get_account_by_address(&address3).nonce, 0);
|
||||
}
|
||||
|
||||
impl V01State {
|
||||
impl V02State {
|
||||
pub fn force_insert_account(&mut self, address: Address, account: Account) {
|
||||
self.public_state.insert(address, account);
|
||||
}
|
||||
@ -527,7 +527,7 @@ pub mod tests {
|
||||
fn test_program_should_fail_if_modifies_nonces() {
|
||||
let initial_data = [(Address::new([1; 32]), 100)];
|
||||
let mut state =
|
||||
V01State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||
let addresses = vec![Address::new([1; 32])];
|
||||
let program_id = Program::nonce_changer_program().id();
|
||||
let message =
|
||||
@ -544,7 +544,7 @@ pub mod tests {
|
||||
fn test_program_should_fail_if_output_accounts_exceed_inputs() {
|
||||
let initial_data = [(Address::new([1; 32]), 100)];
|
||||
let mut state =
|
||||
V01State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||
let addresses = vec![Address::new([1; 32])];
|
||||
let program_id = Program::extra_output_program().id();
|
||||
let message =
|
||||
@ -561,7 +561,7 @@ pub mod tests {
|
||||
fn test_program_should_fail_with_missing_output_accounts() {
|
||||
let initial_data = [(Address::new([1; 32]), 100)];
|
||||
let mut state =
|
||||
V01State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||
let addresses = vec![Address::new([1; 32]), Address::new([2; 32])];
|
||||
let program_id = Program::missing_output_program().id();
|
||||
let message =
|
||||
@ -578,7 +578,7 @@ pub mod tests {
|
||||
fn test_program_should_fail_if_modifies_program_owner_with_only_non_default_program_owner() {
|
||||
let initial_data = [(Address::new([1; 32]), 0)];
|
||||
let mut state =
|
||||
V01State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||
let address = Address::new([1; 32]);
|
||||
let account = state.get_account_by_address(&address);
|
||||
// Assert the target account only differs from the default account in the program owner field
|
||||
@ -600,7 +600,7 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_program_should_fail_if_modifies_program_owner_with_only_non_default_balance() {
|
||||
let initial_data = [];
|
||||
let mut state = V01State::new_with_genesis_accounts(&initial_data, &[])
|
||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[])
|
||||
.with_test_programs()
|
||||
.with_non_default_accounts_but_default_program_owners();
|
||||
let address = Address::new([255; 32]);
|
||||
@ -624,7 +624,7 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_program_should_fail_if_modifies_program_owner_with_only_non_default_nonce() {
|
||||
let initial_data = [];
|
||||
let mut state = V01State::new_with_genesis_accounts(&initial_data, &[])
|
||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[])
|
||||
.with_test_programs()
|
||||
.with_non_default_accounts_but_default_program_owners();
|
||||
let address = Address::new([254; 32]);
|
||||
@ -648,7 +648,7 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_program_should_fail_if_modifies_program_owner_with_only_non_default_data() {
|
||||
let initial_data = [];
|
||||
let mut state = V01State::new_with_genesis_accounts(&initial_data, &[])
|
||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[])
|
||||
.with_test_programs()
|
||||
.with_non_default_accounts_but_default_program_owners();
|
||||
let address = Address::new([253; 32]);
|
||||
@ -673,7 +673,7 @@ pub mod tests {
|
||||
fn test_program_should_fail_if_transfers_balance_from_non_owned_account() {
|
||||
let initial_data = [(Address::new([1; 32]), 100)];
|
||||
let mut state =
|
||||
V01State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||
let sender_address = Address::new([1; 32]);
|
||||
let receiver_address = Address::new([2; 32]);
|
||||
let balance_to_move: u128 = 1;
|
||||
@ -700,7 +700,7 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_program_should_fail_if_modifies_data_of_non_owned_account() {
|
||||
let initial_data = [];
|
||||
let mut state = V01State::new_with_genesis_accounts(&initial_data, &[])
|
||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[])
|
||||
.with_test_programs()
|
||||
.with_non_default_accounts_but_default_program_owners();
|
||||
let address = Address::new([255; 32]);
|
||||
@ -725,7 +725,7 @@ pub mod tests {
|
||||
fn test_program_should_fail_if_does_not_preserve_total_balance_by_minting() {
|
||||
let initial_data = [];
|
||||
let mut state =
|
||||
V01State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||
let address = Address::new([1; 32]);
|
||||
let program_id = Program::minter().id();
|
||||
|
||||
@ -742,7 +742,7 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_program_should_fail_if_does_not_preserve_total_balance_by_burning() {
|
||||
let initial_data = [];
|
||||
let mut state = V01State::new_with_genesis_accounts(&initial_data, &[])
|
||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[])
|
||||
.with_test_programs()
|
||||
.with_account_owned_by_burner_program();
|
||||
let program_id = Program::burner().id();
|
||||
@ -817,7 +817,7 @@ pub mod tests {
|
||||
sender_keys: &TestPublicKeys,
|
||||
recipient_keys: &TestPrivateKeys,
|
||||
balance_to_move: u128,
|
||||
state: &V01State,
|
||||
state: &V02State,
|
||||
) -> PrivacyPreservingTransaction {
|
||||
let sender = AccountWithMetadata::new(
|
||||
state.get_account_by_address(&sender_keys.address()),
|
||||
@ -862,7 +862,7 @@ pub mod tests {
|
||||
recipient_keys: &TestPrivateKeys,
|
||||
balance_to_move: u128,
|
||||
new_nonces: [Nonce; 2],
|
||||
state: &V01State,
|
||||
state: &V02State,
|
||||
) -> PrivacyPreservingTransaction {
|
||||
let program = Program::authenticated_transfer_program();
|
||||
let sender_commitment = Commitment::new(&sender_keys.npk(), sender_private_account);
|
||||
@ -918,7 +918,7 @@ pub mod tests {
|
||||
recipient_address: &Address,
|
||||
balance_to_move: u128,
|
||||
new_nonce: Nonce,
|
||||
state: &V01State,
|
||||
state: &V02State,
|
||||
) -> PrivacyPreservingTransaction {
|
||||
let program = Program::authenticated_transfer_program();
|
||||
let sender_commitment = Commitment::new(&sender_keys.npk(), sender_private_account);
|
||||
@ -966,7 +966,7 @@ pub mod tests {
|
||||
let sender_keys = test_public_account_keys_1();
|
||||
let recipient_keys = test_private_account_keys_1();
|
||||
|
||||
let mut state = V01State::new_with_genesis_accounts(&[(sender_keys.address(), 200)], &[]);
|
||||
let mut state = V02State::new_with_genesis_accounts(&[(sender_keys.address(), 200)], &[]);
|
||||
|
||||
let balance_to_move = 37;
|
||||
|
||||
@ -1012,7 +1012,7 @@ pub mod tests {
|
||||
};
|
||||
let recipient_keys = test_private_account_keys_2();
|
||||
|
||||
let mut state = V01State::new_with_genesis_accounts(&[], &[])
|
||||
let mut state = V02State::new_with_genesis_accounts(&[], &[])
|
||||
.with_private_account(&sender_keys, &sender_private_account);
|
||||
|
||||
let balance_to_move = 37;
|
||||
@ -1078,7 +1078,7 @@ pub mod tests {
|
||||
};
|
||||
let recipient_keys = test_public_account_keys_1();
|
||||
let recipient_initial_balance = 400;
|
||||
let mut state = V01State::new_with_genesis_accounts(
|
||||
let mut state = V02State::new_with_genesis_accounts(
|
||||
&[(recipient_keys.address(), recipient_initial_balance)],
|
||||
&[],
|
||||
)
|
||||
@ -1966,7 +1966,7 @@ pub mod tests {
|
||||
};
|
||||
let recipient_keys = test_private_account_keys_2();
|
||||
|
||||
let mut state = V01State::new_with_genesis_accounts(&[], &[])
|
||||
let mut state = V02State::new_with_genesis_accounts(&[], &[])
|
||||
.with_private_account(&sender_keys, &sender_private_account);
|
||||
|
||||
let balance_to_move = 37;
|
||||
|
||||
@ -10,7 +10,7 @@ use crate::config::AccountInitialData;
|
||||
pub mod block_store;
|
||||
|
||||
pub struct SequecerChainStore {
|
||||
pub state: nssa::V01State,
|
||||
pub state: nssa::V02State,
|
||||
pub block_store: SequecerBlockStore,
|
||||
}
|
||||
|
||||
@ -29,12 +29,12 @@ impl SequecerChainStore {
|
||||
.collect();
|
||||
|
||||
#[cfg(not(feature = "testnet"))]
|
||||
let state = nssa::V01State::new_with_genesis_accounts(&init_accs, initial_commitments);
|
||||
let state = nssa::V02State::new_with_genesis_accounts(&init_accs, initial_commitments);
|
||||
|
||||
#[cfg(feature = "testnet")]
|
||||
let state = {
|
||||
let mut this =
|
||||
nssa::V01State::new_with_genesis_accounts(&init_accs, initial_commitments);
|
||||
nssa::V02State::new_with_genesis_accounts(&init_accs, initial_commitments);
|
||||
this.add_pinata_program("cafe".repeat(16).parse().unwrap());
|
||||
this
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user