mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-02 13:23:10 +00:00
Merge branch 'main' into schouhy/implement-nssa-v0.1-public-state-tmp
This commit is contained in:
commit
96b256bd4c
@ -6,5 +6,5 @@ source env.sh
|
||||
|
||||
cargo test --release
|
||||
cd integration_tests
|
||||
export NSSA_WALLET_HOME_DIR=$(pwd)/configs/debug/node/
|
||||
export NSSA_WALLET_HOME_DIR=$(pwd)/configs/debug/wallet/
|
||||
cargo run $(pwd)/configs/debug all
|
||||
@ -66,20 +66,21 @@ pub async fn post_test(residual: (ServerHandle, JoinHandle<Result<()>>, TempDir)
|
||||
sequencer_loop_handle.abort();
|
||||
seq_http_server_handle.stop(true).await;
|
||||
|
||||
//At this point all of the references to node_core and sequencer_core must be lost.
|
||||
//At this point all of the references to sequencer_core must be lost.
|
||||
//So they are dropped and tempdirs will be dropped too,
|
||||
}
|
||||
|
||||
pub async fn test_success() {
|
||||
let command = Command::SendNativeTokenTransfer {
|
||||
from: ACC_SENDER.to_string(),
|
||||
nonce: 0,
|
||||
to: ACC_RECEIVER.to_string(),
|
||||
amount: 100,
|
||||
};
|
||||
|
||||
let node_config = fetch_config().unwrap();
|
||||
let wallet_config = fetch_config().unwrap();
|
||||
|
||||
let seq_client = SequencerClient::new(node_config.sequencer_addr.clone()).unwrap();
|
||||
let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
|
||||
|
||||
wallet::execute_subcommand(command).await.unwrap();
|
||||
|
||||
@ -110,13 +111,14 @@ pub async fn test_success_move_to_another_account() {
|
||||
|
||||
let command = Command::SendNativeTokenTransfer {
|
||||
from: ACC_SENDER.to_string(),
|
||||
nonce: 0,
|
||||
to: hex_acc_receiver_new_acc.clone(),
|
||||
amount: 100,
|
||||
};
|
||||
|
||||
let node_config = fetch_config().unwrap();
|
||||
let wallet_config = fetch_config().unwrap();
|
||||
|
||||
let seq_client = SequencerClient::new(node_config.sequencer_addr.clone()).unwrap();
|
||||
let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
|
||||
|
||||
wallet::execute_subcommand(command).await.unwrap();
|
||||
|
||||
@ -145,13 +147,14 @@ pub async fn test_success_move_to_another_account() {
|
||||
pub async fn test_failure() {
|
||||
let command = Command::SendNativeTokenTransfer {
|
||||
from: ACC_SENDER.to_string(),
|
||||
nonce: 0,
|
||||
to: ACC_RECEIVER.to_string(),
|
||||
amount: 1000000,
|
||||
};
|
||||
|
||||
let node_config = fetch_config().unwrap();
|
||||
let wallet_config = fetch_config().unwrap();
|
||||
|
||||
let seq_client = SequencerClient::new(node_config.sequencer_addr.clone()).unwrap();
|
||||
let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
|
||||
|
||||
wallet::execute_subcommand(command).await.unwrap();
|
||||
|
||||
|
||||
@ -98,12 +98,6 @@ pub fn private_circuit(
|
||||
));
|
||||
}
|
||||
|
||||
for nullifier in in_nullifiers.iter() {
|
||||
let nullifier: [u8; 32] = nullifier.clone().try_into().unwrap();
|
||||
|
||||
assert!(!public_context.nullifiers_set.contains(&nullifier));
|
||||
}
|
||||
|
||||
(in_nullifiers, generate_commitments(output_utxos))
|
||||
}
|
||||
|
||||
@ -147,12 +141,6 @@ pub fn deshielded_circuit(
|
||||
));
|
||||
}
|
||||
|
||||
for nullifier in in_nullifiers.iter() {
|
||||
let nullifier: [u8; 32] = nullifier.clone().try_into().unwrap();
|
||||
|
||||
assert!(!public_context.nullifiers_set.contains(&nullifier));
|
||||
}
|
||||
|
||||
in_nullifiers
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use accounts::account_core::{address::AccountAddress, AccountPublicMask};
|
||||
use common::merkle_tree_public::{merkle_tree::UTXOCommitmentsMerkleTree, TreeHashType};
|
||||
@ -20,9 +20,7 @@ pub struct PublicSCContext {
|
||||
pub caller_balance: u64,
|
||||
pub account_masks: BTreeMap<AccountAddress, AccountPublicMask>,
|
||||
pub comitment_store_root: TreeHashType,
|
||||
pub pub_tx_store_root: TreeHashType,
|
||||
pub commitments_tree: UTXOCommitmentsMerkleTree,
|
||||
pub nullifiers_set: HashSet<[u8; 32]>,
|
||||
}
|
||||
|
||||
impl Serialize for PublicSCContext {
|
||||
@ -44,9 +42,7 @@ impl Serialize for PublicSCContext {
|
||||
s.serialize_field(ACCOUNT_MASKS_KEYS_SORTED, &account_masks_keys)?;
|
||||
s.serialize_field(ACCOUNT_MASKS_VALUES_SORTED, &account_mask_values)?;
|
||||
s.serialize_field(COMMITMENT_STORE_ROOT, &self.comitment_store_root)?;
|
||||
s.serialize_field(PUT_TX_STORE_ROOT, &self.pub_tx_store_root)?;
|
||||
s.serialize_field(COMMITMENT_TREE, &self.commitments_tree)?;
|
||||
s.serialize_field(NULLIFIERS_SET, &self.nullifiers_set)?;
|
||||
|
||||
s.end()
|
||||
}
|
||||
@ -100,12 +96,9 @@ mod tests {
|
||||
fn create_test_context() -> PublicSCContext {
|
||||
let caller_address = [1; 32];
|
||||
let comitment_store_root = [3; 32];
|
||||
let pub_tx_store_root = [4; 32];
|
||||
|
||||
let commitments_tree =
|
||||
UTXOCommitmentsMerkleTree::new(vec![UTXOCommitment { hash: [5; 32] }]);
|
||||
let mut nullifiers_set = HashSet::new();
|
||||
nullifiers_set.insert([6; 32]);
|
||||
|
||||
let mut account_masks = BTreeMap::new();
|
||||
|
||||
@ -122,9 +115,7 @@ mod tests {
|
||||
caller_balance: 100,
|
||||
account_masks,
|
||||
comitment_store_root,
|
||||
pub_tx_store_root,
|
||||
commitments_tree,
|
||||
nullifiers_set,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -76,7 +76,6 @@ impl SequencerCore {
|
||||
pub fn push_tx_into_mempool_pre_check(
|
||||
&mut self,
|
||||
transaction: nssa::PublicTransaction,
|
||||
// _tx_roots: [[u8; 32]; 2],
|
||||
) -> Result<(), TransactionMalformationErrorKind> {
|
||||
let mempool_size = self.mempool.len();
|
||||
if mempool_size >= self.sequencer_config.max_num_tx_in_block {
|
||||
@ -300,7 +299,6 @@ mod tests {
|
||||
common_setup(&mut sequencer);
|
||||
|
||||
let tx = common::test_utils::produce_dummy_empty_transaction();
|
||||
// let tx_roots = sequencer.get_tree_roots();
|
||||
let result = sequencer.transaction_pre_check(tx);
|
||||
|
||||
assert!(result.is_ok());
|
||||
@ -387,7 +385,7 @@ mod tests {
|
||||
let tx = common::test_utils::create_transaction_native_token_transfer(
|
||||
acc1, 0, acc2, 10000000, sign_key1,
|
||||
);
|
||||
// let tx_roots = sequencer.get_tree_roots();
|
||||
|
||||
let result = sequencer.transaction_pre_check(tx);
|
||||
|
||||
//Passed pre-check
|
||||
@ -452,7 +450,6 @@ mod tests {
|
||||
common_setup(&mut sequencer);
|
||||
|
||||
let tx = common::test_utils::produce_dummy_empty_transaction();
|
||||
// let tx_roots = sequencer.get_tree_roots();
|
||||
|
||||
// Fill the mempool
|
||||
sequencer.mempool.push_item(tx.clone());
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
use accounts::account_core::{address::AccountAddress, Account};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct NodeAccountsStore {
|
||||
pub struct WalletAccountsStore {
|
||||
pub accounts: HashMap<AccountAddress, Account>,
|
||||
}
|
||||
|
||||
impl NodeAccountsStore {
|
||||
impl WalletAccountsStore {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
accounts: HashMap::new(),
|
||||
@ -21,7 +21,7 @@ impl NodeAccountsStore {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for NodeAccountsStore {
|
||||
impl Default for WalletAccountsStore {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
@ -45,13 +45,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_create_empty_store() {
|
||||
let store = NodeAccountsStore::new();
|
||||
let store = WalletAccountsStore::new();
|
||||
assert!(store.accounts.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_register_account() {
|
||||
let mut store = NodeAccountsStore::new();
|
||||
let mut store = WalletAccountsStore::new();
|
||||
|
||||
let account = create_sample_account(100);
|
||||
let account_addr = account.address;
|
||||
@ -65,7 +65,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_unregister_account() {
|
||||
let mut store = NodeAccountsStore::new();
|
||||
let mut store = WalletAccountsStore::new();
|
||||
|
||||
let account = create_sample_account(100);
|
||||
let account_addr = account.address;
|
||||
@ -79,7 +79,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_unregister_nonexistent_account() {
|
||||
let mut store = NodeAccountsStore::new();
|
||||
let mut store = WalletAccountsStore::new();
|
||||
|
||||
let account_addr: [u8; 32] = pad_to_32("nonexistent".to_string().as_bytes());
|
||||
store.unregister_account(account_addr);
|
||||
@ -89,7 +89,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_register_multiple_accounts() {
|
||||
let mut store = NodeAccountsStore::new();
|
||||
let mut store = WalletAccountsStore::new();
|
||||
|
||||
let account1 = create_sample_account(100);
|
||||
let account2 = create_sample_account(200);
|
||||
|
||||
@ -1,15 +1,12 @@
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
use accounts::account_core::{address::AccountAddress, Account};
|
||||
use anyhow::Result;
|
||||
use common::{
|
||||
merkle_tree_public::merkle_tree::{PublicTransactionMerkleTree, UTXOCommitmentsMerkleTree},
|
||||
nullifier::UTXONullifier,
|
||||
};
|
||||
use common::merkle_tree_public::merkle_tree::UTXOCommitmentsMerkleTree;
|
||||
use sc_core::public_context::PublicSCContext;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::config::NodeConfig;
|
||||
use crate::config::WalletConfig;
|
||||
|
||||
pub mod accounts_store;
|
||||
|
||||
@ -39,27 +36,21 @@ impl From<AccMap> for HashMap<[u8; 32], Account> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NodeChainStore {
|
||||
pub struct WalletChainStore {
|
||||
pub acc_map: HashMap<AccountAddress, Account>,
|
||||
pub nullifier_store: HashSet<UTXONullifier>,
|
||||
pub utxo_commitments_store: UTXOCommitmentsMerkleTree,
|
||||
pub pub_tx_store: PublicTransactionMerkleTree,
|
||||
pub node_config: NodeConfig,
|
||||
pub wallet_config: WalletConfig,
|
||||
}
|
||||
|
||||
impl NodeChainStore {
|
||||
pub fn new(config: NodeConfig) -> Result<Self> {
|
||||
impl WalletChainStore {
|
||||
pub fn new(config: WalletConfig) -> Result<Self> {
|
||||
let acc_map = HashMap::new();
|
||||
let nullifier_store = HashSet::new();
|
||||
let utxo_commitments_store = UTXOCommitmentsMerkleTree::new(vec![]);
|
||||
let pub_tx_store = PublicTransactionMerkleTree::new(vec![]);
|
||||
|
||||
Ok(Self {
|
||||
acc_map,
|
||||
nullifier_store,
|
||||
utxo_commitments_store,
|
||||
pub_tx_store,
|
||||
node_config: config,
|
||||
wallet_config: config,
|
||||
})
|
||||
}
|
||||
|
||||
@ -75,12 +66,6 @@ impl NodeChainStore {
|
||||
caller_balance: self.acc_map.get(&caller).unwrap().balance,
|
||||
account_masks,
|
||||
comitment_store_root: self.utxo_commitments_store.get_root().unwrap_or([0; 32]),
|
||||
pub_tx_store_root: self.pub_tx_store.get_root().unwrap_or([0; 32]),
|
||||
nullifiers_set: self
|
||||
.nullifier_store
|
||||
.iter()
|
||||
.map(|item| item.utxo_hash)
|
||||
.collect(),
|
||||
commitments_tree: self.utxo_commitments_store.clone(),
|
||||
}
|
||||
}
|
||||
@ -135,8 +120,8 @@ mod tests {
|
||||
initial_accounts
|
||||
}
|
||||
|
||||
fn create_sample_node_config(home: PathBuf) -> NodeConfig {
|
||||
NodeConfig {
|
||||
fn create_sample_wallet_config(home: PathBuf) -> WalletConfig {
|
||||
WalletConfig {
|
||||
home,
|
||||
override_rust_log: None,
|
||||
sequencer_addr: "http://127.0.0.1".to_string(),
|
||||
@ -150,12 +135,11 @@ mod tests {
|
||||
let temp_dir = tempdir().unwrap();
|
||||
let path = temp_dir.path();
|
||||
|
||||
let config = create_sample_node_config(path.to_path_buf());
|
||||
let config = create_sample_wallet_config(path.to_path_buf());
|
||||
|
||||
let store = NodeChainStore::new(config.clone()).unwrap();
|
||||
let store = WalletChainStore::new(config.clone()).unwrap();
|
||||
|
||||
assert!(store.acc_map.is_empty());
|
||||
assert!(store.nullifier_store.is_empty());
|
||||
assert_eq!(
|
||||
store.utxo_commitments_store.get_root().unwrap_or([0; 32]),
|
||||
[0; 32]
|
||||
|
||||
@ -37,7 +37,7 @@ impl From<GasConfig> for zkvm::gas_calculator::GasCalculator {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct NodeConfig {
|
||||
pub struct WalletConfig {
|
||||
///Home dir of sequencer storage
|
||||
pub home: PathBuf,
|
||||
///Override rust log (env var logging level)
|
||||
|
||||
@ -2,24 +2,7 @@ use std::{fs::File, io::BufReader, path::PathBuf, str::FromStr};
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
|
||||
use crate::{config::NodeConfig, HOME_DIR_ENV_VAR};
|
||||
|
||||
pub fn vec_u8_to_vec_u64(bytes: Vec<u8>) -> Vec<u64> {
|
||||
// Pad with zeros to make sure it's a multiple of 8
|
||||
let mut padded = bytes.clone();
|
||||
while !padded.len().is_multiple_of(8) {
|
||||
padded.push(0);
|
||||
}
|
||||
|
||||
padded
|
||||
.chunks(8)
|
||||
.map(|chunk| {
|
||||
let mut array = [0u8; 8];
|
||||
array.copy_from_slice(chunk);
|
||||
u64::from_le_bytes(array)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
use crate::{config::WalletConfig, HOME_DIR_ENV_VAR};
|
||||
|
||||
///Get home dir for wallet. Env var `NSSA_WALLET_HOME_DIR` must be set before execution to succeed.
|
||||
pub fn get_home() -> Result<PathBuf> {
|
||||
@ -27,9 +10,9 @@ pub fn get_home() -> Result<PathBuf> {
|
||||
}
|
||||
|
||||
///Fetch config from `NSSA_WALLET_HOME_DIR`
|
||||
pub fn fetch_config() -> Result<NodeConfig> {
|
||||
pub fn fetch_config() -> Result<WalletConfig> {
|
||||
let config_home = get_home()?;
|
||||
let file = File::open(config_home.join("node_config.json"))?;
|
||||
let file = File::open(config_home.join("wallet_config.json"))?;
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
Ok(serde_json::from_reader(reader)?)
|
||||
|
||||
@ -7,8 +7,9 @@ use common::{
|
||||
|
||||
use accounts::account_core::{address::AccountAddress, Account};
|
||||
use anyhow::Result;
|
||||
use chain_storage::NodeChainStore;
|
||||
use config::NodeConfig;
|
||||
use chain_storage::WalletChainStore;
|
||||
use common::transaction::TransactionBody;
|
||||
use config::WalletConfig;
|
||||
use log::info;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
@ -22,19 +23,18 @@ pub const BLOCK_GEN_DELAY_SECS: u64 = 20;
|
||||
pub mod chain_storage;
|
||||
pub mod config;
|
||||
pub mod helperfunctions;
|
||||
pub mod requests_structs;
|
||||
|
||||
pub struct NodeCore {
|
||||
pub storage: Arc<RwLock<NodeChainStore>>,
|
||||
pub node_config: NodeConfig,
|
||||
pub struct WalletCore {
|
||||
pub storage: Arc<RwLock<WalletChainStore>>,
|
||||
pub wallet_config: WalletConfig,
|
||||
pub sequencer_client: Arc<SequencerClient>,
|
||||
}
|
||||
|
||||
impl NodeCore {
|
||||
pub async fn start_from_config_update_chain(config: NodeConfig) -> Result<Self> {
|
||||
impl WalletCore {
|
||||
pub async fn start_from_config_update_chain(config: WalletConfig) -> Result<Self> {
|
||||
let client = Arc::new(SequencerClient::new(config.sequencer_addr.clone())?);
|
||||
|
||||
let mut storage = NodeChainStore::new(config.clone())?;
|
||||
let mut storage = WalletChainStore::new(config.clone())?;
|
||||
for acc in config.clone().initial_accounts {
|
||||
storage.acc_map.insert(acc.address, acc);
|
||||
}
|
||||
@ -43,19 +43,11 @@ impl NodeCore {
|
||||
|
||||
Ok(Self {
|
||||
storage: wrapped_storage,
|
||||
node_config: config.clone(),
|
||||
wallet_config: config.clone(),
|
||||
sequencer_client: client.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn get_roots(&self) -> [[u8; 32]; 2] {
|
||||
let storage = self.storage.read().await;
|
||||
[
|
||||
storage.utxo_commitments_store.get_root().unwrap_or([0; 32]),
|
||||
storage.pub_tx_store.get_root().unwrap_or([0; 32]),
|
||||
]
|
||||
}
|
||||
|
||||
pub async fn create_new_account(&mut self) -> AccountAddress {
|
||||
let account = Account::new();
|
||||
account.log();
|
||||
@ -116,6 +108,9 @@ pub enum Command {
|
||||
///from - valid 32 byte hex string
|
||||
#[arg(long)]
|
||||
from: String,
|
||||
///nonce - u128 integer
|
||||
#[arg(long)]
|
||||
nonce: u128,
|
||||
///to - valid 32 byte hex string
|
||||
#[arg(long)]
|
||||
to: String,
|
||||
@ -136,17 +131,21 @@ pub struct Args {
|
||||
|
||||
pub async fn execute_subcommand(command: Command) -> Result<()> {
|
||||
match command {
|
||||
Command::SendNativeTokenTransfer { from, to, amount } => {
|
||||
let node_config = fetch_config()?;
|
||||
Command::SendNativeTokenTransfer {
|
||||
from,
|
||||
nonce,
|
||||
to,
|
||||
amount,
|
||||
} => {
|
||||
let wallet_config = fetch_config()?;
|
||||
|
||||
let from = produce_account_addr_from_hex(from)?;
|
||||
let to = produce_account_addr_from_hex(to)?;
|
||||
|
||||
let wallet_core = NodeCore::start_from_config_update_chain(node_config).await?;
|
||||
let wallet_core = WalletCore::start_from_config_update_chain(wallet_config).await?;
|
||||
|
||||
//ToDo: Nonce management
|
||||
let res = wallet_core
|
||||
.send_public_native_token_transfer(from, 0, to, amount)
|
||||
.send_public_native_token_transfer(from, nonce, to, amount)
|
||||
.await?;
|
||||
|
||||
info!("Results of tx send is {res:#?}");
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
use accounts::account_core::address::AccountAddress;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utxo::utxo_core::UTXO;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct MintMoneyPublicTx {
|
||||
pub acc: AccountAddress,
|
||||
pub amount: u128,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct SendMoneyShieldedTx {
|
||||
pub acc_sender: AccountAddress,
|
||||
pub amount: u128,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct SendMoneyDeshieldedTx {
|
||||
pub receiver_data: Vec<(u128, AccountAddress)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct UTXOPublication {
|
||||
pub utxos: Vec<UTXO>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum ActionData {
|
||||
MintMoneyPublicTx(MintMoneyPublicTx),
|
||||
SendMoneyShieldedTx(SendMoneyShieldedTx),
|
||||
SendMoneyDeshieldedTx(SendMoneyDeshieldedTx),
|
||||
UTXOPublication(UTXOPublication),
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user