From 35b636a27dbacab4029583587e2313efdcf8dffb Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Fri, 15 Aug 2025 14:27:36 +0300 Subject: [PATCH 01/10] fix: clearing and renaming --- Cargo.toml | 3 +- accounts/src/lib.rs | 2 - integration_tests/Cargo.toml | 4 +- {accounts => key_protocol}/Cargo.toml | 5 +- .../src/key_management/constants_types.rs | 0 .../key_management/ephemeral_key_holder.rs | 0 .../src/key_management/mod.rs | 30 ++-- .../src/key_management/secret_holders.rs | 0 .../src/key_protocol_core}/address.rs | 0 .../src/key_protocol_core}/mod.rs | 137 ++++----------- key_protocol/src/lib.rs | 2 + sequencer_core/Cargo.toml | 4 +- sequencer_rpc/Cargo.toml | 4 +- utxo/Cargo.toml | 17 -- utxo/src/lib.rs | 1 - utxo/src/utxo_core.rs | 162 ------------------ wallet/Cargo.toml | 7 +- wallet/src/chain_storage/accounts_store.rs | 13 +- wallet/src/chain_storage/mod.rs | 17 +- wallet/src/config.rs | 6 +- wallet/src/helperfunctions.rs | 6 +- wallet/src/lib.rs | 4 +- 22 files changed, 84 insertions(+), 340 deletions(-) delete mode 100644 accounts/src/lib.rs rename {accounts => key_protocol}/Cargo.toml (89%) rename {accounts => key_protocol}/src/key_management/constants_types.rs (100%) rename {accounts => key_protocol}/src/key_management/ephemeral_key_holder.rs (100%) rename {accounts => key_protocol}/src/key_management/mod.rs (93%) rename {accounts => key_protocol}/src/key_management/secret_holders.rs (100%) rename {accounts/src/account_core => key_protocol/src/key_protocol_core}/address.rs (100%) rename {accounts/src/account_core => key_protocol/src/key_protocol_core}/mod.rs (52%) create mode 100644 key_protocol/src/lib.rs delete mode 100644 utxo/Cargo.toml delete mode 100644 utxo/src/lib.rs delete mode 100644 utxo/src/utxo_core.rs diff --git a/Cargo.toml b/Cargo.toml index fe70572..9d31f3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,7 @@ members = [ "integration_tests", "sequencer_runner", "storage", - "accounts", - "utxo", + "key_protocol", "sequencer_rpc", "mempool", "wallet", diff --git a/accounts/src/lib.rs b/accounts/src/lib.rs deleted file mode 100644 index 998d3ec..0000000 --- a/accounts/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod account_core; -pub mod key_management; diff --git a/integration_tests/Cargo.toml b/integration_tests/Cargo.toml index 10c49fb..df2bad8 100644 --- a/integration_tests/Cargo.toml +++ b/integration_tests/Cargo.toml @@ -36,5 +36,5 @@ path = "../wallet" [dependencies.common] path = "../common" -[dependencies.accounts] -path = "../accounts" +[dependencies.key_protocol] +path = "../key_protocol" diff --git a/accounts/Cargo.toml b/key_protocol/Cargo.toml similarity index 89% rename from accounts/Cargo.toml rename to key_protocol/Cargo.toml index d4bc3fa..eeae994 100644 --- a/accounts/Cargo.toml +++ b/key_protocol/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "accounts" +name = "key_protocol" version = "0.1.0" edition = "2021" @@ -18,9 +18,6 @@ aes-gcm.workspace = true lazy_static.workspace = true tiny-keccak.workspace = true -[dependencies.utxo] -path = "../utxo" - [dependencies.common] path = "../common" diff --git a/accounts/src/key_management/constants_types.rs b/key_protocol/src/key_management/constants_types.rs similarity index 100% rename from accounts/src/key_management/constants_types.rs rename to key_protocol/src/key_management/constants_types.rs diff --git a/accounts/src/key_management/ephemeral_key_holder.rs b/key_protocol/src/key_management/ephemeral_key_holder.rs similarity index 100% rename from accounts/src/key_management/ephemeral_key_holder.rs rename to key_protocol/src/key_management/ephemeral_key_holder.rs diff --git a/accounts/src/key_management/mod.rs b/key_protocol/src/key_management/mod.rs similarity index 93% rename from accounts/src/key_management/mod.rs rename to key_protocol/src/key_management/mod.rs index 9e48cbd..2a653af 100644 --- a/accounts/src/key_management/mod.rs +++ b/key_protocol/src/key_management/mod.rs @@ -7,7 +7,7 @@ use rand::{rngs::OsRng, Rng}; use secret_holders::{SeedHolder, TopSecretKeyHolder, UTXOSecretKeyHolder}; use serde::{Deserialize, Serialize}; -use crate::account_core::PublicKey; +use crate::key_protocol_core::PublicKey; pub type PublicAccountSigningKey = [u8; 32]; use nssa::{self}; @@ -17,7 +17,7 @@ pub mod secret_holders; #[derive(Serialize, Deserialize, Clone, Debug)] ///Entrypoint to key management -pub struct AddressKeyHolder { +pub struct KeyChain { top_secret_key_holder: TopSecretKeyHolder, pub utxo_secret_key_holder: UTXOSecretKeyHolder, pub_account_signing_key: nssa::PrivateKey, @@ -25,7 +25,7 @@ pub struct AddressKeyHolder { pub viewing_public_key: PublicKey, } -impl AddressKeyHolder { +impl KeyChain { pub fn new_os_random() -> Self { //Currently dropping SeedHolder at the end of initialization. //Now entirely sure if we need it in the future. @@ -127,8 +127,8 @@ mod tests { #[test] fn test_new_os_random() { - // Ensure that a new AddressKeyHolder instance can be created without errors. - let address_key_holder = AddressKeyHolder::new_os_random(); + // Ensure that a new KeyChain instance can be created without errors. + let address_key_holder = KeyChain::new_os_random(); // Check that key holder fields are initialized with expected types assert!(!Into::::into( @@ -141,7 +141,7 @@ mod tests { #[test] fn test_calculate_shared_secret_receiver() { - let address_key_holder = AddressKeyHolder::new_os_random(); + let address_key_holder = KeyChain::new_os_random(); // Generate a random ephemeral public key sender let scalar = Scalar::random(&mut OsRng); @@ -157,7 +157,7 @@ mod tests { #[test] fn test_decrypt_data() { - let address_key_holder = AddressKeyHolder::new_os_random(); + let address_key_holder = KeyChain::new_os_random(); // Generate an ephemeral key and shared secret let ephemeral_public_key_sender = @@ -188,8 +188,8 @@ mod tests { #[test] fn test_new_os_random_initialization() { - // Ensure that AddressKeyHolder is initialized correctly - let address_key_holder = AddressKeyHolder::new_os_random(); + // Ensure that KeyChain is initialized correctly + let address_key_holder = KeyChain::new_os_random(); // Check that key holder fields are initialized with expected types and values assert!(!Into::::into( @@ -202,7 +202,7 @@ mod tests { #[test] fn test_calculate_shared_secret_with_identity_point() { - let address_key_holder = AddressKeyHolder::new_os_random(); + let address_key_holder = KeyChain::new_os_random(); // Use identity point as ephemeral public key let identity_point = AffinePoint::identity(); @@ -217,7 +217,7 @@ mod tests { #[test] #[should_panic] fn test_decrypt_data_with_incorrect_nonce() { - let address_key_holder = AddressKeyHolder::new_os_random(); + let address_key_holder = KeyChain::new_os_random(); // Generate ephemeral public key and shared secret let scalar = Scalar::random(OsRng); @@ -250,7 +250,7 @@ mod tests { #[test] #[should_panic] fn test_decrypt_data_with_incorrect_ciphertext() { - let address_key_holder = AddressKeyHolder::new_os_random(); + let address_key_holder = KeyChain::new_os_random(); // Generate ephemeral public key and shared secret let scalar = Scalar::random(OsRng); @@ -285,7 +285,7 @@ mod tests { #[test] fn test_encryption_decryption_round_trip() { - let address_key_holder = AddressKeyHolder::new_os_random(); + let address_key_holder = KeyChain::new_os_random(); // Generate ephemeral key and shared secret let scalar = Scalar::random(OsRng); @@ -303,7 +303,7 @@ mod tests { .encrypt(nonce, plaintext.as_ref()) .expect("encryption failure"); - // Decrypt the data using the `AddressKeyHolder` instance + // Decrypt the data using the `KeyChain` instance let decrypted_data = address_key_holder .decrypt_data( ephemeral_public_key_sender, @@ -318,7 +318,7 @@ mod tests { #[test] fn test_get_public_account_signing_key() { - let address_key_holder = AddressKeyHolder::new_os_random(); + let address_key_holder = KeyChain::new_os_random(); let signing_key = address_key_holder.get_pub_account_signing_key(); assert_eq!(signing_key, &address_key_holder.pub_account_signing_key); } diff --git a/accounts/src/key_management/secret_holders.rs b/key_protocol/src/key_management/secret_holders.rs similarity index 100% rename from accounts/src/key_management/secret_holders.rs rename to key_protocol/src/key_management/secret_holders.rs diff --git a/accounts/src/account_core/address.rs b/key_protocol/src/key_protocol_core/address.rs similarity index 100% rename from accounts/src/account_core/address.rs rename to key_protocol/src/key_protocol_core/address.rs diff --git a/accounts/src/account_core/mod.rs b/key_protocol/src/key_protocol_core/mod.rs similarity index 52% rename from accounts/src/account_core/mod.rs rename to key_protocol/src/key_protocol_core/mod.rs index 329e1e1..c50d713 100644 --- a/accounts/src/account_core/mod.rs +++ b/key_protocol/src/key_protocol_core/mod.rs @@ -1,83 +1,68 @@ -use std::collections::HashMap; - use anyhow::Result; -use common::{merkle_tree_public::TreeHashType, transaction::Tag}; +use common::transaction::Tag; use k256::AffinePoint; use log::info; use nssa::Address; use serde::{Deserialize, Serialize}; -use utxo::utxo_core::UTXO; use crate::key_management::{ constants_types::{CipherText, Nonce}, ephemeral_key_holder::EphemeralKeyHolder, - AddressKeyHolder, + KeyChain, }; pub type PublicKey = AffinePoint; #[derive(Clone, Debug)] -pub struct Account { - pub key_holder: AddressKeyHolder, +pub struct NSSAUserData { + pub key_holder: KeyChain, pub address: Address, pub balance: u64, - pub utxos: HashMap, } #[derive(Serialize, Deserialize, Clone, Debug)] -pub struct AccountForSerialization { - pub key_holder: AddressKeyHolder, +pub struct NSSAUserDataForSerialization { + pub key_holder: KeyChain, pub address: Address, pub balance: u64, - pub utxos: HashMap, } -impl From for AccountForSerialization { - fn from(value: Account) -> Self { - AccountForSerialization { +impl From for NSSAUserDataForSerialization { + fn from(value: NSSAUserData) -> Self { + NSSAUserDataForSerialization { key_holder: value.key_holder, address: value.address, balance: value.balance, - utxos: value - .utxos - .into_iter() - .map(|(key, val)| (hex::encode(key), val)) - .collect(), } } } -impl From for Account { - fn from(value: AccountForSerialization) -> Self { - Account { +impl From for NSSAUserData { + fn from(value: NSSAUserDataForSerialization) -> Self { + NSSAUserData { key_holder: value.key_holder, address: value.address, balance: value.balance, - utxos: value - .utxos - .into_iter() - .map(|(key, val)| (hex::decode(key).unwrap().try_into().unwrap(), val)) - .collect(), } } } -impl Serialize for Account { +impl Serialize for NSSAUserData { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, { - let account_for_serialization: AccountForSerialization = From::from(self.clone()); + let account_for_serialization: NSSAUserDataForSerialization = From::from(self.clone()); account_for_serialization.serialize(serializer) } } -impl<'de> Deserialize<'de> for Account { +impl<'de> Deserialize<'de> for NSSAUserData { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { - let account_for_serialization = ::deserialize(deserializer)?; + let account_for_serialization = ::deserialize(deserializer)?; Ok(account_for_serialization.into()) } } @@ -88,21 +73,21 @@ impl<'de> Deserialize<'de> for Account { /// /// Main usage is to encode data for other account #[derive(Serialize, Clone)] -pub struct AccountPublicMask { +pub struct NSSAUserDataPublicMask { pub nullifier_public_key: AffinePoint, pub viewing_public_key: AffinePoint, pub address: Address, pub balance: u64, } -impl AccountPublicMask { +impl NSSAUserDataPublicMask { pub fn encrypt_data( ephemeral_key_holder: &EphemeralKeyHolder, viewing_public_key_receiver: AffinePoint, data: &[u8], ) -> (CipherText, Nonce) { - //Using of parent Account fuction - Account::encrypt_data(ephemeral_key_holder, viewing_public_key_receiver, data) + //Using of parent NSSAUserData fuction + NSSAUserData::encrypt_data(ephemeral_key_holder, viewing_public_key_receiver, data) } pub fn make_tag(&self) -> Tag { @@ -110,35 +95,31 @@ impl AccountPublicMask { } } -impl Account { +impl NSSAUserData { pub fn new() -> Self { - let key_holder = AddressKeyHolder::new_os_random(); + let key_holder = KeyChain::new_os_random(); let public_key = nssa::PublicKey::new_from_private_key(key_holder.get_pub_account_signing_key()); let address = nssa::Address::from(&public_key); let balance = 0; - let utxos = HashMap::new(); Self { key_holder, address, balance, - utxos, } } pub fn new_with_balance(balance: u64) -> Self { - let key_holder = AddressKeyHolder::new_os_random(); + let key_holder = KeyChain::new_os_random(); let public_key = nssa::PublicKey::new_from_private_key(key_holder.get_pub_account_signing_key()); let address = nssa::Address::from(&public_key); - let utxos = HashMap::new(); Self { key_holder, address, balance, - utxos, } } @@ -160,42 +141,14 @@ impl Account { .decrypt_data(ephemeral_public_key_sender, ciphertext, nonce) } - pub fn add_new_utxo_outputs(&mut self, utxos: Vec) -> Result<()> { - for utxo in utxos { - if self.utxos.contains_key(&utxo.hash) { - return Err(anyhow::anyhow!("UTXO already exists")); - } - self.utxos.insert(utxo.hash, utxo); - } - Ok(()) - } - pub fn update_public_balance(&mut self, new_balance: u64) { self.balance = new_balance; } - pub fn add_asset( - &mut self, - asset: Asset, - amount: u128, - privacy_flag: bool, - ) -> Result<()> { - let asset_utxo = UTXO::new( - *self.address.value(), - serde_json::to_vec(&asset)?, - amount, - privacy_flag, - ); - - self.utxos.insert(asset_utxo.hash, asset_utxo); - - Ok(()) - } - pub fn log(&self) { info!("Keys generated"); - info!("Account address is {:?}", hex::encode(self.address)); - info!("Account balance is {:?}", self.balance); + info!("NSSAUserData address is {:?}", hex::encode(self.address)); + info!("NSSAUserData balance is {:?}", self.balance); } pub fn make_tag(&self) -> Tag { @@ -203,8 +156,8 @@ impl Account { } ///Produce account public mask - pub fn make_account_public_mask(&self) -> AccountPublicMask { - AccountPublicMask { + pub fn make_account_public_mask(&self) -> NSSAUserDataPublicMask { + NSSAUserDataPublicMask { nullifier_public_key: self.key_holder.nullifer_public_key, viewing_public_key: self.key_holder.viewing_public_key, address: self.address, @@ -213,7 +166,7 @@ impl Account { } } -impl Default for Account { +impl Default for NSSAUserData { fn default() -> Self { Self::new() } @@ -223,52 +176,24 @@ impl Default for Account { mod tests { use super::*; - fn generate_dummy_utxo(address: TreeHashType, amount: u128) -> UTXO { - UTXO::new(address, vec![], amount, false) - } - #[test] fn test_new_account() { - let account = Account::new(); + let account = NSSAUserData::new(); assert_eq!(account.balance, 0); } - #[test] - fn test_add_new_utxo_outputs() { - let mut account = Account::new(); - let utxo1 = generate_dummy_utxo(*account.address.value(), 100); - let utxo2 = generate_dummy_utxo(*account.address.value(), 200); - - let result = account.add_new_utxo_outputs(vec![utxo1.clone(), utxo2.clone()]); - - assert!(result.is_ok()); - assert_eq!(account.utxos.len(), 2); - } - #[test] fn test_update_public_balance() { - let mut account = Account::new(); + let mut account = NSSAUserData::new(); account.update_public_balance(500); assert_eq!(account.balance, 500); } - #[test] - fn test_add_asset() { - let mut account = Account::new(); - let asset = "dummy_asset"; - let amount = 1000u128; - - let result = account.add_asset(asset, amount, false); - - assert!(result.is_ok()); - assert_eq!(account.utxos.len(), 1); - } - #[test] fn accounts_accounts_mask_tag_consistency() { - let account = Account::new(); + let account = NSSAUserData::new(); let account_mask = account.make_account_public_mask(); diff --git a/key_protocol/src/lib.rs b/key_protocol/src/lib.rs new file mode 100644 index 0000000..5adef9e --- /dev/null +++ b/key_protocol/src/lib.rs @@ -0,0 +1,2 @@ +pub mod key_protocol_core; +pub mod key_management; diff --git a/sequencer_core/Cargo.toml b/sequencer_core/Cargo.toml index 2083f42..2e3570b 100644 --- a/sequencer_core/Cargo.toml +++ b/sequencer_core/Cargo.toml @@ -22,8 +22,8 @@ path = "../storage" [dependencies.mempool] path = "../mempool" -[dependencies.accounts] -path = "../accounts" +[dependencies.key_protocol] +path = "../key_protocol" [dependencies.common] path = "../common" diff --git a/sequencer_rpc/Cargo.toml b/sequencer_rpc/Cargo.toml index ce61f7e..c6ce004 100644 --- a/sequencer_rpc/Cargo.toml +++ b/sequencer_rpc/Cargo.toml @@ -22,8 +22,8 @@ tokio.workspace = true [dependencies.mempool] path = "../mempool" -[dependencies.accounts] -path = "../accounts" +[dependencies.key_protocol] +path = "../key_protocol" [dependencies.sequencer_core] path = "../sequencer_core" diff --git a/utxo/Cargo.toml b/utxo/Cargo.toml deleted file mode 100644 index 02b9ed8..0000000 --- a/utxo/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "utxo" -version = "0.1.0" -edition = "2021" - -[dependencies] -anyhow.workspace = true -serde_json.workspace = true -env_logger.workspace = true -log.workspace = true -serde.workspace = true -sha2.workspace = true -hex.workspace = true -rand.workspace = true - -[dependencies.common] -path = "../common" diff --git a/utxo/src/lib.rs b/utxo/src/lib.rs deleted file mode 100644 index 7baf984..0000000 --- a/utxo/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod utxo_core; diff --git a/utxo/src/utxo_core.rs b/utxo/src/utxo_core.rs deleted file mode 100644 index 07a8830..0000000 --- a/utxo/src/utxo_core.rs +++ /dev/null @@ -1,162 +0,0 @@ -use anyhow::Result; -use common::{merkle_tree_public::TreeHashType, AccountId}; -use log::info; -use rand::{rngs::OsRng, RngCore}; -use serde::{Deserialize, Serialize}; -use sha2::{digest::FixedOutput, Digest}; - -///Raw asset data -pub type Asset = Vec; -pub type Randomness = [u8; 32]; - -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] -///Container for raw utxo payload -pub struct UTXO { - pub hash: TreeHashType, - pub owner: AccountId, - pub asset: Asset, - // TODO: change to u256 - pub amount: u128, - pub privacy_flag: bool, - pub randomness: Randomness, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct UTXOPayload { - pub owner: AccountId, - pub asset: Asset, - // TODO: change to u256 - pub amount: u128, - pub privacy_flag: bool, - pub randomness: Randomness, -} - -impl UTXOPayload { - fn to_bytes(&self) -> Vec { - let mut result = Vec::new(); - result.extend_from_slice(&self.owner); - result.extend_from_slice(&self.asset); - result.extend_from_slice(&self.amount.to_be_bytes()); - result.push(self.privacy_flag as u8); - result.extend_from_slice(&self.randomness); - result - } -} - -impl UTXO { - pub fn new(owner: AccountId, asset: Asset, amount: u128, privacy_flag: bool) -> Self { - let mut randomness = Randomness::default(); - OsRng.fill_bytes(&mut randomness); - let payload = UTXOPayload { - owner, - asset, - amount, - privacy_flag, - randomness, - }; - Self::create_utxo_from_payload(payload) - } - pub fn create_utxo_from_payload(payload_with_asset: UTXOPayload) -> Self { - let mut hasher = sha2::Sha256::new(); - hasher.update(payload_with_asset.to_bytes()); - let hash = ::from(hasher.finalize_fixed()); - - Self { - hash, - owner: payload_with_asset.owner, - asset: payload_with_asset.asset, - amount: payload_with_asset.amount, - privacy_flag: payload_with_asset.privacy_flag, - randomness: payload_with_asset.randomness, - } - } - - pub fn interpret_asset<'de, ToInterpret: Deserialize<'de>>(&'de self) -> Result { - Ok(serde_json::from_slice(&self.asset)?) - } - - pub fn into_payload(&self) -> UTXOPayload { - UTXOPayload { - owner: self.owner, - asset: self.asset.clone(), - amount: self.amount, - privacy_flag: self.privacy_flag, - randomness: self.randomness, - } - } - - pub fn log(&self) { - info!("UTXO hash is {:?}", hex::encode(self.hash)); - info!("UTXO owner is {:?}", hex::encode(self.owner)); - info!("UTXO asset is {:?}", hex::encode(self.asset.clone())); - info!("UTXO amount is {:?}", self.amount); - info!("UTXO privacy_flag is {:?}", self.privacy_flag); - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[derive(Serialize, Deserialize, PartialEq, Debug)] - struct TestAsset { - id: u32, - name: String, - } - - fn sample_account() -> AccountId { - AccountId::default() - } - - fn sample_payload() -> UTXOPayload { - UTXOPayload { - owner: sample_account(), - asset: serde_json::to_vec(&TestAsset { - id: 1, - name: "Test".to_string(), - }) - .unwrap(), - amount: 10, - privacy_flag: false, - randomness: Randomness::default(), - } - } - - #[test] - fn test_create_utxo_from_payload() { - let payload = sample_payload(); - let utxo = UTXO::create_utxo_from_payload(payload.clone()); - - // Ensure hash is created and the UTXO fields are correctly assigned - assert_eq!(utxo.owner, payload.owner); - assert_eq!(utxo.asset, payload.asset); - } - - #[test] - fn test_interpret_asset() { - let payload = sample_payload(); - let utxo = UTXO::create_utxo_from_payload(payload); - - // Interpret asset as TestAsset - let interpreted: TestAsset = utxo.interpret_asset().unwrap(); - - assert_eq!( - interpreted, - TestAsset { - id: 1, - name: "Test".to_string() - } - ); - } - - #[test] - fn test_interpret_invalid_asset() { - let mut payload = sample_payload(); - payload.asset = vec![0, 1, 2, 3]; // Invalid data for deserialization - let utxo = UTXO::create_utxo_from_payload(payload); - - // This should fail because the asset is not valid JSON for TestAsset - let result: Result = utxo.interpret_asset(); - assert!(result.is_err()); - } -} diff --git a/wallet/Cargo.toml b/wallet/Cargo.toml index e5b01b7..13bea50 100644 --- a/wallet/Cargo.toml +++ b/wallet/Cargo.toml @@ -23,11 +23,8 @@ hex.workspace = true actix-rt.workspace = true clap.workspace = true -[dependencies.accounts] -path = "../accounts" - -[dependencies.utxo] -path = "../utxo" +[dependencies.key_protocol] +path = "../key_protocol" [dependencies.nssa] path = "../nssa" diff --git a/wallet/src/chain_storage/accounts_store.rs b/wallet/src/chain_storage/accounts_store.rs index 4dad474..243fe6a 100644 --- a/wallet/src/chain_storage/accounts_store.rs +++ b/wallet/src/chain_storage/accounts_store.rs @@ -1,9 +1,10 @@ -use accounts::account_core::Account; +//TODO: NOT NSSA USER DATA, ACCOUNT +use key_protocol::key_protocol_core::NSSAUserData; use nssa::Address; use std::collections::HashMap; pub struct WalletAccountsStore { - pub accounts: HashMap, + pub accounts: HashMap, } impl WalletAccountsStore { @@ -13,7 +14,7 @@ impl WalletAccountsStore { } } - pub fn register_account(&mut self, account: Account) { + pub fn register_account(&mut self, account: NSSAUserData) { self.accounts.insert(account.address, account); } @@ -31,10 +32,10 @@ impl Default for WalletAccountsStore { #[cfg(test)] mod tests { use super::*; - use accounts::account_core::Account; + use key_protocol::key_protocol_core::NSSAUserData; /// Helper function to create a sample account - fn create_sample_account(balance: u64) -> Account { - Account::new_with_balance(balance) + fn create_sample_account(balance: u64) -> NSSAUserData { + NSSAUserData::new_with_balance(balance) } fn pad_to_32(slice: &[u8]) -> [u8; 32] { diff --git a/wallet/src/chain_storage/mod.rs b/wallet/src/chain_storage/mod.rs index 86bb37e..8c57284 100644 --- a/wallet/src/chain_storage/mod.rs +++ b/wallet/src/chain_storage/mod.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; -use accounts::account_core::Account; +//TODO: NOT USER DATA, ACCOUNT +use key_protocol::key_protocol_core::NSSAUserData; use anyhow::Result; use common::merkle_tree_public::merkle_tree::UTXOCommitmentsMerkleTree; use nssa::Address; @@ -12,11 +13,11 @@ pub mod accounts_store; #[derive(Deserialize, Serialize)] pub struct AccMap { - pub acc_map: HashMap, + pub acc_map: HashMap, } -impl From> for AccMap { - fn from(value: HashMap<[u8; 32], Account>) -> Self { +impl From> for AccMap { + fn from(value: HashMap<[u8; 32], NSSAUserData>) -> Self { AccMap { acc_map: value .into_iter() @@ -26,7 +27,7 @@ impl From> for AccMap { } } -impl From for HashMap<[u8; 32], Account> { +impl From for HashMap<[u8; 32], NSSAUserData> { fn from(value: AccMap) -> Self { value .acc_map @@ -37,7 +38,7 @@ impl From for HashMap<[u8; 32], Account> { } pub struct WalletChainStore { - pub acc_map: HashMap, + pub acc_map: HashMap, pub utxo_commitments_store: UTXOCommitmentsMerkleTree, pub wallet_config: WalletConfig, } @@ -58,11 +59,11 @@ impl WalletChainStore { #[cfg(test)] mod tests { use super::*; - use accounts::account_core::Account; + use key_protocol::key_protocol_core::NSSAUserData; use std::path::PathBuf; use tempfile::tempdir; - fn create_initial_accounts() -> Vec { + fn create_initial_accounts() -> Vec { let initial_acc1 = serde_json::from_str(r#"{ "address": "1b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f", "balance": 100, diff --git a/wallet/src/config.rs b/wallet/src/config.rs index 9e174f3..087762b 100644 --- a/wallet/src/config.rs +++ b/wallet/src/config.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use accounts::account_core::Account; +use key_protocol::key_protocol_core::NSSAUserData; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] @@ -32,5 +32,7 @@ pub struct WalletConfig { ///Sequencer polling duration for new blocks in seconds pub seq_poll_timeout_secs: u64, ///Initial accounts for wallet - pub initial_accounts: Vec, + /// + /// TODO: NOT USRE DATA, ACCOUNT + pub initial_accounts: Vec, } diff --git a/wallet/src/helperfunctions.rs b/wallet/src/helperfunctions.rs index 3a3cca5..790d9d6 100644 --- a/wallet/src/helperfunctions.rs +++ b/wallet/src/helperfunctions.rs @@ -1,6 +1,6 @@ use std::{fs::File, io::BufReader, path::PathBuf, str::FromStr}; -use accounts::account_core::Account; +use key_protocol::key_protocol_core::NSSAUserData; use anyhow::Result; use nssa::Address; @@ -28,7 +28,9 @@ pub fn produce_account_addr_from_hex(hex_str: String) -> Result
{ ///Fetch list of accounts stored at `NSSA_WALLET_HOME_DIR/curr_accounts.json` /// /// If file not present, it is considered as empty list of persistent accounts -pub fn fetch_persistent_accounts() -> Result> { +/// +/// ToDo: NOT USER DATA, ACCOUNT +pub fn fetch_persistent_accounts() -> Result> { let home = get_home()?; let accs_path = home.join("curr_accounts.json"); diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index 40ee615..5746bcf 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -5,7 +5,7 @@ use common::{ ExecutionFailureKind, }; -use accounts::account_core::Account; +use key_protocol::key_protocol_core::NSSAUserData; use anyhow::Result; use chain_storage::WalletChainStore; use config::WalletConfig; @@ -54,7 +54,7 @@ impl WalletCore { } pub async fn create_new_account(&mut self) -> Address { - let account = Account::new(); + let account = NSSAUserData::new(); account.log(); let addr = account.address; From e617cac69ccd47eacce189018cf5eca26c0893e3 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Mon, 18 Aug 2025 16:15:25 +0300 Subject: [PATCH 02/10] fix: key proctocol crate updated --- key_protocol/Cargo.toml | 1 + key_protocol/src/key_management/mod.rs | 71 ++++++--- key_protocol/src/key_protocol_core/address.rs | 3 - key_protocol/src/key_protocol_core/mod.rs | 149 +++++++----------- key_protocol/src/lib.rs | 2 +- nssa/src/signature/private_key.rs | 18 +++ wallet/src/chain_storage/mod.rs | 2 +- wallet/src/config.rs | 2 +- wallet/src/helperfunctions.rs | 4 +- wallet/src/lib.rs | 3 +- 10 files changed, 126 insertions(+), 129 deletions(-) delete mode 100644 key_protocol/src/key_protocol_core/address.rs diff --git a/key_protocol/Cargo.toml b/key_protocol/Cargo.toml index eeae994..2f2bb07 100644 --- a/key_protocol/Cargo.toml +++ b/key_protocol/Cargo.toml @@ -17,6 +17,7 @@ hex.workspace = true aes-gcm.workspace = true lazy_static.workspace = true tiny-keccak.workspace = true +nssa-core = { path = "../nssa/core" } [dependencies.common] path = "../common" diff --git a/key_protocol/src/key_management/mod.rs b/key_protocol/src/key_management/mod.rs index 2a653af..bc6d14c 100644 --- a/key_protocol/src/key_management/mod.rs +++ b/key_protocol/src/key_management/mod.rs @@ -1,15 +1,15 @@ +use std::collections::HashMap; + use aes_gcm::{aead::Aead, Aes256Gcm, KeyInit}; use constants_types::{CipherText, Nonce}; use elliptic_curve::point::AffineCoordinates; use k256::AffinePoint; use log::info; -use rand::{rngs::OsRng, Rng}; use secret_holders::{SeedHolder, TopSecretKeyHolder, UTXOSecretKeyHolder}; use serde::{Deserialize, Serialize}; use crate::key_protocol_core::PublicKey; pub type PublicAccountSigningKey = [u8; 32]; -use nssa::{self}; pub mod constants_types; pub mod ephemeral_key_holder; @@ -20,7 +20,8 @@ pub mod secret_holders; pub struct KeyChain { top_secret_key_holder: TopSecretKeyHolder, pub utxo_secret_key_holder: UTXOSecretKeyHolder, - pub_account_signing_key: nssa::PrivateKey, + ///Map for all users accounts + pub_account_signing_keys: HashMap, pub nullifer_public_key: PublicKey, pub viewing_public_key: PublicKey, } @@ -37,26 +38,50 @@ impl KeyChain { let nullifer_public_key = utxo_secret_key_holder.generate_nullifier_public_key(); let viewing_public_key = utxo_secret_key_holder.generate_viewing_public_key(); - let mut rng = OsRng; - let pub_account_signing_key = loop { - match nssa::PrivateKey::try_new(rng.gen()) { - Ok(key) => break key, - Err(_) => continue, - } - }; + Self { + top_secret_key_holder, + utxo_secret_key_holder, + nullifer_public_key, + viewing_public_key, + pub_account_signing_keys: HashMap::new(), + } + } + + pub fn new_os_random_with_accounts(accounts: HashMap) -> Self { + //Currently dropping SeedHolder at the end of initialization. + //Now entirely sure if we need it in the future. + let seed_holder = SeedHolder::new_os_random(); + let top_secret_key_holder = seed_holder.produce_top_secret_key_holder(); + + let utxo_secret_key_holder = top_secret_key_holder.produce_utxo_secret_holder(); + + let nullifer_public_key = utxo_secret_key_holder.generate_nullifier_public_key(); + let viewing_public_key = utxo_secret_key_holder.generate_viewing_public_key(); Self { top_secret_key_holder, utxo_secret_key_holder, nullifer_public_key, viewing_public_key, - pub_account_signing_key, + pub_account_signing_keys: accounts, } } + pub fn generate_new_private_key(&mut self) -> nssa::Address { + let private_key = nssa::PrivateKey::new_os_random(); + let address = nssa::Address::from(&nssa::PublicKey::new_from_private_key(&private_key)); + + self.pub_account_signing_keys.insert(address, private_key); + + address + } + /// Returns the signing key for public transaction signatures - pub fn get_pub_account_signing_key(&self) -> &nssa::PrivateKey { - &self.pub_account_signing_key + pub fn get_pub_account_signing_key( + &self, + address: &nssa::Address, + ) -> Option<&nssa::PrivateKey> { + self.pub_account_signing_keys.get(address) } pub fn calculate_shared_secret_receiver( @@ -318,9 +343,15 @@ mod tests { #[test] fn test_get_public_account_signing_key() { - let address_key_holder = KeyChain::new_os_random(); - let signing_key = address_key_holder.get_pub_account_signing_key(); - assert_eq!(signing_key, &address_key_holder.pub_account_signing_key); + let mut address_key_holder = KeyChain::new_os_random(); + + let address = address_key_holder.generate_new_private_key(); + + let is_private_key_generated = address_key_holder + .get_pub_account_signing_key(&address) + .is_some(); + + assert!(is_private_key_generated); } #[test] @@ -333,13 +364,7 @@ mod tests { let nullifer_public_key = utxo_secret_key_holder.generate_nullifier_public_key(); let viewing_public_key = utxo_secret_key_holder.generate_viewing_public_key(); - let mut rng = OsRng; - let pub_account_signing_key = loop { - match nssa::PrivateKey::try_new(rng.gen()) { - Ok(key) => break key, - Err(_) => continue, - } - }; + let pub_account_signing_key = nssa::PrivateKey::new_os_random(); let public_key = nssa::PublicKey::new_from_private_key(&pub_account_signing_key); diff --git a/key_protocol/src/key_protocol_core/address.rs b/key_protocol/src/key_protocol_core/address.rs deleted file mode 100644 index 83ce792..0000000 --- a/key_protocol/src/key_protocol_core/address.rs +++ /dev/null @@ -1,3 +0,0 @@ -// TODO: Consider wrapping `AccountAddress` in a struct. - -pub type AccountAddress = [u8; 32]; diff --git a/key_protocol/src/key_protocol_core/mod.rs b/key_protocol/src/key_protocol_core/mod.rs index c50d713..cd9ab39 100644 --- a/key_protocol/src/key_protocol_core/mod.rs +++ b/key_protocol/src/key_protocol_core/mod.rs @@ -1,8 +1,7 @@ +use std::collections::HashMap; + use anyhow::Result; -use common::transaction::Tag; use k256::AffinePoint; -use log::info; -use nssa::Address; use serde::{Deserialize, Serialize}; use crate::key_management::{ @@ -13,58 +12,10 @@ use crate::key_management::{ pub type PublicKey = AffinePoint; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct NSSAUserData { pub key_holder: KeyChain, - pub address: Address, - pub balance: u64, -} - -#[derive(Serialize, Deserialize, Clone, Debug)] -pub struct NSSAUserDataForSerialization { - pub key_holder: KeyChain, - pub address: Address, - pub balance: u64, -} - -impl From for NSSAUserDataForSerialization { - fn from(value: NSSAUserData) -> Self { - NSSAUserDataForSerialization { - key_holder: value.key_holder, - address: value.address, - balance: value.balance, - } - } -} - -impl From for NSSAUserData { - fn from(value: NSSAUserDataForSerialization) -> Self { - NSSAUserData { - key_holder: value.key_holder, - address: value.address, - balance: value.balance, - } - } -} - -impl Serialize for NSSAUserData { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - let account_for_serialization: NSSAUserDataForSerialization = From::from(self.clone()); - account_for_serialization.serialize(serializer) - } -} - -impl<'de> Deserialize<'de> for NSSAUserData { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - let account_for_serialization = ::deserialize(deserializer)?; - Ok(account_for_serialization.into()) - } + pub accounts: HashMap, } ///A strucure, which represents all the visible(public) information @@ -76,8 +27,6 @@ impl<'de> Deserialize<'de> for NSSAUserData { pub struct NSSAUserDataPublicMask { pub nullifier_public_key: AffinePoint, pub viewing_public_key: AffinePoint, - pub address: Address, - pub balance: u64, } impl NSSAUserDataPublicMask { @@ -90,39 +39,45 @@ impl NSSAUserDataPublicMask { NSSAUserData::encrypt_data(ephemeral_key_holder, viewing_public_key_receiver, data) } - pub fn make_tag(&self) -> Tag { - self.address.value()[0] - } + //ToDo: Part of a private keys update + // pub fn make_tag(&self) -> Tag { + // self.address.value()[0] + // } } impl NSSAUserData { pub fn new() -> Self { let key_holder = KeyChain::new_os_random(); - let public_key = - nssa::PublicKey::new_from_private_key(key_holder.get_pub_account_signing_key()); - let address = nssa::Address::from(&public_key); - let balance = 0; Self { key_holder, - address, - balance, + accounts: HashMap::new(), } } - pub fn new_with_balance(balance: u64) -> Self { - let key_holder = KeyChain::new_os_random(); - let public_key = - nssa::PublicKey::new_from_private_key(key_holder.get_pub_account_signing_key()); - let address = nssa::Address::from(&public_key); + pub fn new_with_accounts( + accounts_keys: HashMap, + accounts: HashMap, + ) -> Self { + let key_holder = KeyChain::new_os_random_with_accounts(accounts_keys); Self { key_holder, - address, - balance, + accounts, } } + pub fn generate_new_account(&mut self) -> nssa::Address { + let address = self.key_holder.generate_new_private_key(); + self.accounts.insert(address, nssa_core::account::Account::default()); + + address + } + + pub fn get_account_balance(&self, address: &nssa::Address) -> u128 { + self.accounts.get(address).map(|acc| acc.balance).unwrap_or(0) + } + pub fn encrypt_data( ephemeral_key_holder: &EphemeralKeyHolder, viewing_public_key_receiver: AffinePoint, @@ -141,27 +96,23 @@ impl NSSAUserData { .decrypt_data(ephemeral_public_key_sender, ciphertext, nonce) } - pub fn update_public_balance(&mut self, new_balance: u64) { - self.balance = new_balance; + pub fn update_account_balance(&mut self, address: nssa::Address, new_balance: u128) { + self.accounts + .entry(address) + .and_modify(|acc| acc.balance = new_balance) + .or_insert(nssa_core::account::Account::default()); } - pub fn log(&self) { - info!("Keys generated"); - info!("NSSAUserData address is {:?}", hex::encode(self.address)); - info!("NSSAUserData balance is {:?}", self.balance); - } - - pub fn make_tag(&self) -> Tag { - self.address.value()[0] - } + //ToDo: Part of a private keys update + // pub fn make_tag(&self) -> Tag { + // self.address.value()[0] + // } ///Produce account public mask pub fn make_account_public_mask(&self) -> NSSAUserDataPublicMask { NSSAUserDataPublicMask { nullifier_public_key: self.key_holder.nullifer_public_key, viewing_public_key: self.key_holder.viewing_public_key, - address: self.address, - balance: self.balance, } } } @@ -178,25 +129,31 @@ mod tests { #[test] fn test_new_account() { - let account = NSSAUserData::new(); + let mut user_data = NSSAUserData::new(); - assert_eq!(account.balance, 0); + let addr = user_data.generate_new_account(); + + assert_eq!(user_data.get_account_balance(&addr), 0); } #[test] - fn test_update_public_balance() { - let mut account = NSSAUserData::new(); - account.update_public_balance(500); + fn test_update_balance() { + let mut user_data = NSSAUserData::new(); - assert_eq!(account.balance, 500); + let address = user_data.generate_new_account(); + + user_data.update_account_balance(address, 500); + + assert_eq!(user_data.get_account_balance(&address), 500); } - #[test] - fn accounts_accounts_mask_tag_consistency() { - let account = NSSAUserData::new(); + //ToDo: Part of a private keys update + // #[test] + // fn accounts_accounts_mask_tag_consistency() { + // let account = NSSAUserData::new(); - let account_mask = account.make_account_public_mask(); + // let account_mask = account.make_account_public_mask(); - assert_eq!(account.make_tag(), account_mask.make_tag()); - } + // assert_eq!(account.make_tag(), account_mask.make_tag()); + // } } diff --git a/key_protocol/src/lib.rs b/key_protocol/src/lib.rs index 5adef9e..1a52c20 100644 --- a/key_protocol/src/lib.rs +++ b/key_protocol/src/lib.rs @@ -1,2 +1,2 @@ -pub mod key_protocol_core; pub mod key_management; +pub mod key_protocol_core; diff --git a/nssa/src/signature/private_key.rs b/nssa/src/signature/private_key.rs index b35d7da..abe5af6 100644 --- a/nssa/src/signature/private_key.rs +++ b/nssa/src/signature/private_key.rs @@ -1,3 +1,4 @@ +use rand::{Rng, rngs::OsRng}; use serde::{Deserialize, Serialize}; use crate::error::NssaError; @@ -8,6 +9,17 @@ use crate::error::NssaError; pub struct PrivateKey([u8; 32]); impl PrivateKey { + pub fn new_os_random() -> Self { + let mut rng = OsRng; + + loop { + match Self::try_new(rng.r#gen()) { + Ok(key) => break key, + Err(_) => continue, + }; + } + } + fn is_valid_key(value: [u8; 32]) -> bool { secp256k1::SecretKey::from_byte_array(value).is_ok() } @@ -33,4 +45,10 @@ mod tests { let key = PrivateKey::try_new([1; 32]).unwrap(); assert_eq!(key.value(), &key.0); } + + #[test] + fn test_produce_key() { + let key = PrivateKey::new_os_random(); + println!("{:?}", key.0); + } } diff --git a/wallet/src/chain_storage/mod.rs b/wallet/src/chain_storage/mod.rs index 8c57284..80a14f8 100644 --- a/wallet/src/chain_storage/mod.rs +++ b/wallet/src/chain_storage/mod.rs @@ -1,9 +1,9 @@ use std::collections::HashMap; //TODO: NOT USER DATA, ACCOUNT -use key_protocol::key_protocol_core::NSSAUserData; use anyhow::Result; use common::merkle_tree_public::merkle_tree::UTXOCommitmentsMerkleTree; +use key_protocol::key_protocol_core::NSSAUserData; use nssa::Address; use serde::{Deserialize, Serialize}; diff --git a/wallet/src/config.rs b/wallet/src/config.rs index 087762b..a6bf634 100644 --- a/wallet/src/config.rs +++ b/wallet/src/config.rs @@ -32,7 +32,7 @@ pub struct WalletConfig { ///Sequencer polling duration for new blocks in seconds pub seq_poll_timeout_secs: u64, ///Initial accounts for wallet - /// + /// /// TODO: NOT USRE DATA, ACCOUNT pub initial_accounts: Vec, } diff --git a/wallet/src/helperfunctions.rs b/wallet/src/helperfunctions.rs index 790d9d6..334129b 100644 --- a/wallet/src/helperfunctions.rs +++ b/wallet/src/helperfunctions.rs @@ -1,7 +1,7 @@ use std::{fs::File, io::BufReader, path::PathBuf, str::FromStr}; -use key_protocol::key_protocol_core::NSSAUserData; use anyhow::Result; +use key_protocol::key_protocol_core::NSSAUserData; use nssa::Address; use crate::{config::WalletConfig, HOME_DIR_ENV_VAR}; @@ -28,7 +28,7 @@ pub fn produce_account_addr_from_hex(hex_str: String) -> Result
{ ///Fetch list of accounts stored at `NSSA_WALLET_HOME_DIR/curr_accounts.json` /// /// If file not present, it is considered as empty list of persistent accounts -/// +/// /// ToDo: NOT USER DATA, ACCOUNT pub fn fetch_persistent_accounts() -> Result> { let home = get_home()?; diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index 5746bcf..a8ab45f 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -5,10 +5,10 @@ use common::{ ExecutionFailureKind, }; -use key_protocol::key_protocol_core::NSSAUserData; use anyhow::Result; use chain_storage::WalletChainStore; use config::WalletConfig; +use key_protocol::key_protocol_core::NSSAUserData; use log::info; use nssa::Address; @@ -55,7 +55,6 @@ impl WalletCore { pub async fn create_new_account(&mut self) -> Address { let account = NSSAUserData::new(); - account.log(); let addr = account.address; From 80620b6aac7c46e207b3d8e30827ae1d3ec6b4b6 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Tue, 19 Aug 2025 14:14:09 +0300 Subject: [PATCH 03/10] fix: wallet fix --- common/src/lib.rs | 2 + .../configs/debug/wallet/wallet_config.json | 150 +++++++++++++----- integration_tests/src/lib.rs | 4 +- key_protocol/src/key_protocol_core/mod.rs | 20 ++- wallet/Cargo.toml | 1 + wallet/src/chain_storage/accounts_store.rs | 113 ------------- wallet/src/chain_storage/mod.rs | 101 ++++-------- wallet/src/config.rs | 13 +- wallet/src/helperfunctions.rs | 10 +- wallet/src/lib.rs | 62 ++++---- 10 files changed, 208 insertions(+), 268 deletions(-) delete mode 100644 wallet/src/chain_storage/accounts_store.rs diff --git a/common/src/lib.rs b/common/src/lib.rs index b7f45ab..01ae261 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -68,6 +68,8 @@ pub enum ExecutionFailureKind { DecodeError(String), #[error("Inputs amounts does not match outputs")] AmountMismatchError, + #[error("Accounts key not found")] + KeyNotFoundError, #[error("Sequencer client error: {0:?}")] SequencerClientError(#[from] SequencerClientError), #[error("Insufficient gas for operation")] diff --git a/integration_tests/configs/debug/wallet/wallet_config.json b/integration_tests/configs/debug/wallet/wallet_config.json index 6085a36..d888119 100644 --- a/integration_tests/configs/debug/wallet/wallet_config.json +++ b/integration_tests/configs/debug/wallet/wallet_config.json @@ -1,45 +1,113 @@ { - "home": "./node", - "override_rust_log": null, - "sequencer_addr": "http://127.0.0.1:3040", - "seq_poll_timeout_secs": 10, - "initial_accounts": [ - { - "address": "1b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f", - "balance": 10000, - "key_holder": { - "address": "1b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f", - "nullifer_public_key": "03A340BECA9FAAB444CED0140681D72EA1318B5C611704FEE017DA9836B17DB718", - "pub_account_signing_key": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - "top_secret_key_holder": { - "secret_spending_key": "7BC46784DB1BC67825D8F029436846712BFDF9B5D79EA3AB11D39A52B9B229D4" + "home": "./node", + "override_rust_log": null, + "sequencer_addr": "http://127.0.0.1:3040", + "seq_poll_timeout_secs": 10, + "initial_accounts": [ + { + "address": "1b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f", + "pub_sign_key": [ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ], + "account": { + "program_owner": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "balance": 10000, + "nonce": 0, + "data": [] + } }, - "utxo_secret_key_holder": { - "nullifier_secret_key": "BB54A8D3C9C51B82C431082D1845A74677B0EF829A11B517E1D9885DE3139506", - "viewing_secret_key": "AD923E92F6A5683E30140CEAB2702AFB665330C1EE4EFA70FAF29767B6B52BAF" - }, - "viewing_public_key": "0361220C5D277E7A1709340FD31A52600C1432B9C45B9BCF88A43581D58824A8B6" - }, - "utxos": {} - }, - { - "address": "4d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d0766", - "balance": 20000, - "key_holder": { - "address": "4d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d0766", - "nullifer_public_key": "02172F50274DE67C4087C344F5D58E11DF761D90285B095060E0994FAA6BCDE271", - "pub_account_signing_key": [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], - "top_secret_key_holder": { - "secret_spending_key": "80A186737C8D38B4288A03F0F589957D9C040D79C19F3E0CC4BA80F8494E5179" - }, - "utxo_secret_key_holder": { - "nullifier_secret_key": "746928E63F0984F6F4818933493CE9C067562D9CB932FDC06D82C86CDF6D7122", - "viewing_secret_key": "89176CF4BC9E673807643FD52110EF99D4894335AFB10D881AC0B5041FE1FCB7" - }, - "viewing_public_key": "026072A8F83FEC3472E30CDD4767683F30B91661D25B1040AD9A5FC2E01D659F99" - }, - "utxos": {} - } - ] + { + "address": "4d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d0766", + "pub_sign_key": [ + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2 + ], + "account": { + "program_owner": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "balance": 20000, + "nonce": 0, + "data": [] + } + } + ] } diff --git a/integration_tests/src/lib.rs b/integration_tests/src/lib.rs index b5bb265..812e44f 100644 --- a/integration_tests/src/lib.rs +++ b/integration_tests/src/lib.rs @@ -156,7 +156,9 @@ pub async fn test_failure() { let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap(); - wallet::execute_subcommand(command).await.unwrap(); + let failed_send = wallet::execute_subcommand(command).await; + + assert!(failed_send.is_err()); info!("Waiting for next block creation"); tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await; diff --git a/key_protocol/src/key_protocol_core/mod.rs b/key_protocol/src/key_protocol_core/mod.rs index cd9ab39..3b8092e 100644 --- a/key_protocol/src/key_protocol_core/mod.rs +++ b/key_protocol/src/key_protocol_core/mod.rs @@ -69,14 +69,26 @@ impl NSSAUserData { pub fn generate_new_account(&mut self) -> nssa::Address { let address = self.key_holder.generate_new_private_key(); - self.accounts.insert(address, nssa_core::account::Account::default()); + self.accounts + .insert(address, nssa_core::account::Account::default()); address } pub fn get_account_balance(&self, address: &nssa::Address) -> u128 { - self.accounts.get(address).map(|acc| acc.balance).unwrap_or(0) - } + self.accounts + .get(address) + .map(|acc| acc.balance) + .unwrap_or(0) + } + + pub fn get_account(&self, address: &nssa::Address) -> Option<&nssa_core::account::Account> { + self.accounts.get(address) + } + + pub fn get_account_signing_key(&self, address: &nssa::Address) -> Option<&nssa::PrivateKey> { + self.key_holder.get_pub_account_signing_key(address) + } pub fn encrypt_data( ephemeral_key_holder: &EphemeralKeyHolder, @@ -100,7 +112,7 @@ impl NSSAUserData { self.accounts .entry(address) .and_modify(|acc| acc.balance = new_balance) - .or_insert(nssa_core::account::Account::default()); + .or_default(); } //ToDo: Part of a private keys update diff --git a/wallet/Cargo.toml b/wallet/Cargo.toml index 13bea50..4a67791 100644 --- a/wallet/Cargo.toml +++ b/wallet/Cargo.toml @@ -22,6 +22,7 @@ risc0-zkvm = "2.3.1" hex.workspace = true actix-rt.workspace = true clap.workspace = true +nssa-core = { path = "../nssa/core" } [dependencies.key_protocol] path = "../key_protocol" diff --git a/wallet/src/chain_storage/accounts_store.rs b/wallet/src/chain_storage/accounts_store.rs deleted file mode 100644 index 243fe6a..0000000 --- a/wallet/src/chain_storage/accounts_store.rs +++ /dev/null @@ -1,113 +0,0 @@ -//TODO: NOT NSSA USER DATA, ACCOUNT -use key_protocol::key_protocol_core::NSSAUserData; -use nssa::Address; -use std::collections::HashMap; - -pub struct WalletAccountsStore { - pub accounts: HashMap, -} - -impl WalletAccountsStore { - pub fn new() -> Self { - Self { - accounts: HashMap::new(), - } - } - - pub fn register_account(&mut self, account: NSSAUserData) { - self.accounts.insert(account.address, account); - } - - pub fn unregister_account(&mut self, account_addr: Address) { - self.accounts.remove(&account_addr); - } -} - -impl Default for WalletAccountsStore { - fn default() -> Self { - Self::new() - } -} - -#[cfg(test)] -mod tests { - use super::*; - use key_protocol::key_protocol_core::NSSAUserData; - /// Helper function to create a sample account - fn create_sample_account(balance: u64) -> NSSAUserData { - NSSAUserData::new_with_balance(balance) - } - - fn pad_to_32(slice: &[u8]) -> [u8; 32] { - let mut padded = [0u8; 32]; - let len = slice.len().min(32); - padded[..len].copy_from_slice(&slice[..len]); - padded - } - - #[test] - fn test_create_empty_store() { - let store = WalletAccountsStore::new(); - assert!(store.accounts.is_empty()); - } - - #[test] - fn test_register_account() { - let mut store = WalletAccountsStore::new(); - - let account = create_sample_account(100); - let account_addr = account.address; - - store.register_account(account); - - assert_eq!(store.accounts.len(), 1); - let stored_account = store.accounts.get(&account_addr).unwrap(); - assert_eq!(stored_account.balance, 100); - } - - #[test] - fn test_unregister_account() { - let mut store = WalletAccountsStore::new(); - - let account = create_sample_account(100); - let account_addr = account.address; - store.register_account(account); - - assert_eq!(store.accounts.len(), 1); - - store.unregister_account(account_addr); - assert!(store.accounts.is_empty()); - } - - #[test] - fn test_unregister_nonexistent_account() { - let mut store = WalletAccountsStore::new(); - - let account_addr: [u8; 32] = pad_to_32("nonexistent".to_string().as_bytes()); - store.unregister_account(Address::new(account_addr)); - - assert!(store.accounts.is_empty()); - } - - #[test] - fn test_register_multiple_accounts() { - let mut store = WalletAccountsStore::new(); - - let account1 = create_sample_account(100); - let account2 = create_sample_account(200); - - let address_1 = account1.address; - let address_2 = account2.address; - - store.register_account(account1); - store.register_account(account2); - - assert_eq!(store.accounts.len(), 2); - - let stored_account1 = store.accounts.get(&address_1).unwrap(); - let stored_account2 = store.accounts.get(&address_2).unwrap(); - - assert_eq!(stored_account1.balance, 100); - assert_eq!(stored_account2.balance, 200); - } -} diff --git a/wallet/src/chain_storage/mod.rs b/wallet/src/chain_storage/mod.rs index 80a14f8..40c9ddc 100644 --- a/wallet/src/chain_storage/mod.rs +++ b/wallet/src/chain_storage/mod.rs @@ -1,55 +1,37 @@ use std::collections::HashMap; -//TODO: NOT USER DATA, ACCOUNT use anyhow::Result; use common::merkle_tree_public::merkle_tree::UTXOCommitmentsMerkleTree; use key_protocol::key_protocol_core::NSSAUserData; -use nssa::Address; -use serde::{Deserialize, Serialize}; use crate::config::WalletConfig; -pub mod accounts_store; - -#[derive(Deserialize, Serialize)] -pub struct AccMap { - pub acc_map: HashMap, -} - -impl From> for AccMap { - fn from(value: HashMap<[u8; 32], NSSAUserData>) -> Self { - AccMap { - acc_map: value - .into_iter() - .map(|(key, val)| (hex::encode(key), val)) - .collect(), - } - } -} - -impl From for HashMap<[u8; 32], NSSAUserData> { - fn from(value: AccMap) -> Self { - value - .acc_map - .into_iter() - .map(|(key, val)| (hex::decode(key).unwrap().try_into().unwrap(), val)) - .collect() - } -} - pub struct WalletChainStore { - pub acc_map: HashMap, + pub user_data: NSSAUserData, pub utxo_commitments_store: UTXOCommitmentsMerkleTree, pub wallet_config: WalletConfig, } impl WalletChainStore { pub fn new(config: WalletConfig) -> Result { - let acc_map = HashMap::new(); + let accounts: HashMap = config + .initial_accounts + .clone() + .into_iter() + .map(|init_acc_data| (init_acc_data.address, init_acc_data.account)) + .collect(); + + let accounts_keys: HashMap = config + .initial_accounts + .clone() + .into_iter() + .map(|init_acc_data| (init_acc_data.address, init_acc_data.pub_sign_key)) + .collect(); + let utxo_commitments_store = UTXOCommitmentsMerkleTree::new(vec![]); Ok(Self { - acc_map, + user_data: NSSAUserData::new_with_accounts(accounts_keys, accounts), utxo_commitments_store, wallet_config: config, }) @@ -58,48 +40,33 @@ impl WalletChainStore { #[cfg(test)] mod tests { + use crate::config::InitialAccountData; + use super::*; - use key_protocol::key_protocol_core::NSSAUserData; use std::path::PathBuf; use tempfile::tempdir; - fn create_initial_accounts() -> Vec { + fn create_initial_accounts() -> Vec { let initial_acc1 = serde_json::from_str(r#"{ "address": "1b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f", - "balance": 100, - "nonce": 0, - "key_holder": { - "nullifer_public_key": "03A340BECA9FAAB444CED0140681D72EA1318B5C611704FEE017DA9836B17DB718", - "pub_account_signing_key": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - "top_secret_key_holder": { - "secret_spending_key": "7BC46784DB1BC67825D8F029436846712BFDF9B5D79EA3AB11D39A52B9B229D4" - }, - "utxo_secret_key_holder": { - "nullifier_secret_key": "BB54A8D3C9C51B82C431082D1845A74677B0EF829A11B517E1D9885DE3139506", - "viewing_secret_key": "AD923E92F6A5683E30140CEAB2702AFB665330C1EE4EFA70FAF29767B6B52BAF" - }, - "viewing_public_key": "0361220C5D277E7A1709340FD31A52600C1432B9C45B9BCF88A43581D58824A8B6" - }, - "utxos": {} + "pub_sign_key": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + "account": { + "program_owner": [0,0,0,0,0,0,0,0], + "balance": 100, + "nonce": 0, + "data": [] + } }"#).unwrap(); let initial_acc2 = serde_json::from_str(r#"{ "address": "4d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d0766", - "balance": 200, - "nonce": 0, - "key_holder": { - "nullifer_public_key": "02172F50274DE67C4087C344F5D58E11DF761D90285B095060E0994FAA6BCDE271", - "pub_account_signing_key": [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], - "top_secret_key_holder": { - "secret_spending_key": "80A186737C8D38B4288A03F0F589957D9C040D79C19F3E0CC4BA80F8494E5179" - }, - "utxo_secret_key_holder": { - "nullifier_secret_key": "746928E63F0984F6F4818933493CE9C067562D9CB932FDC06D82C86CDF6D7122", - "viewing_secret_key": "89176CF4BC9E673807643FD52110EF99D4894335AFB10D881AC0B5041FE1FCB7" - }, - "viewing_public_key": "026072A8F83FEC3472E30CDD4767683F30B91661D25B1040AD9A5FC2E01D659F99" - }, - "utxos": {} + "pub_sign_key": [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], + "account": { + "program_owner": [0,0,0,0,0,0,0,0], + "balance": 100, + "nonce": 0, + "data": [] + } }"#).unwrap(); let initial_accounts = vec![initial_acc1, initial_acc2]; @@ -126,7 +93,7 @@ mod tests { let store = WalletChainStore::new(config.clone()).unwrap(); - assert!(store.acc_map.is_empty()); + assert_eq!(store.user_data.accounts.len(), 2); assert_eq!( store.utxo_commitments_store.get_root().unwrap_or([0; 32]), [0; 32] diff --git a/wallet/src/config.rs b/wallet/src/config.rs index a6bf634..21bd912 100644 --- a/wallet/src/config.rs +++ b/wallet/src/config.rs @@ -1,7 +1,12 @@ +use serde::{Deserialize, Serialize}; use std::path::PathBuf; -use key_protocol::key_protocol_core::NSSAUserData; -use serde::{Deserialize, Serialize}; +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct InitialAccountData { + pub address: nssa::Address, + pub account: nssa_core::account::Account, + pub pub_sign_key: nssa::PrivateKey, +} #[derive(Debug, Clone, Serialize, Deserialize)] pub struct GasConfig { @@ -32,7 +37,5 @@ pub struct WalletConfig { ///Sequencer polling duration for new blocks in seconds pub seq_poll_timeout_secs: u64, ///Initial accounts for wallet - /// - /// TODO: NOT USRE DATA, ACCOUNT - pub initial_accounts: Vec, + pub initial_accounts: Vec, } diff --git a/wallet/src/helperfunctions.rs b/wallet/src/helperfunctions.rs index 334129b..51b9d9d 100644 --- a/wallet/src/helperfunctions.rs +++ b/wallet/src/helperfunctions.rs @@ -1,10 +1,12 @@ use std::{fs::File, io::BufReader, path::PathBuf, str::FromStr}; use anyhow::Result; -use key_protocol::key_protocol_core::NSSAUserData; use nssa::Address; -use crate::{config::WalletConfig, HOME_DIR_ENV_VAR}; +use crate::{ + config::{InitialAccountData, 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 { @@ -28,9 +30,7 @@ pub fn produce_account_addr_from_hex(hex_str: String) -> Result
{ ///Fetch list of accounts stored at `NSSA_WALLET_HOME_DIR/curr_accounts.json` /// /// If file not present, it is considered as empty list of persistent accounts -/// -/// ToDo: NOT USER DATA, ACCOUNT -pub fn fetch_persistent_accounts() -> Result> { +pub fn fetch_persistent_accounts() -> Result> { let home = get_home()?; let accs_path = home.join("curr_accounts.json"); diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index a8ab45f..2c4b711 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -8,7 +8,6 @@ use common::{ use anyhow::Result; use chain_storage::WalletChainStore; use config::WalletConfig; -use key_protocol::key_protocol_core::NSSAUserData; use log::info; use nssa::Address; @@ -27,7 +26,6 @@ pub mod helperfunctions; pub struct WalletCore { pub storage: WalletChainStore, - pub wallet_config: WalletConfig, pub sequencer_client: Arc, } @@ -35,32 +33,23 @@ impl WalletCore { pub async fn start_from_config_update_chain(config: WalletConfig) -> Result { let client = Arc::new(SequencerClient::new(config.sequencer_addr.clone())?); - let mut storage = WalletChainStore::new(config.clone())?; - for acc in config.clone().initial_accounts { - storage.acc_map.insert(acc.address, acc); - } + let mut storage = WalletChainStore::new(config)?; - //Persistent accounts take precedence for initial accounts let persistent_accounts = fetch_persistent_accounts()?; for acc in persistent_accounts { - storage.acc_map.insert(acc.address, acc); + storage + .user_data + .update_account_balance(acc.address, acc.account.balance); } Ok(Self { storage, - wallet_config: config.clone(), sequencer_client: client.clone(), }) } pub async fn create_new_account(&mut self) -> Address { - let account = NSSAUserData::new(); - - let addr = account.address; - - self.storage.acc_map.insert(account.address, account); - - addr + self.storage.user_data.generate_new_account() } pub async fn send_public_native_token_transfer( @@ -70,27 +59,36 @@ impl WalletCore { to: Address, balance_to_move: u128, ) -> Result { - let account = self.storage.acc_map.get(&from); + let account = self.storage.user_data.get_account(&from); if let Some(account) = account { - let addresses = vec![from, to]; - let nonces = vec![nonce]; - let program_id = nssa::program::Program::authenticated_transfer_program().id(); - let message = nssa::public_transaction::Message::try_new( - program_id, - addresses, - nonces, - balance_to_move, - ) - .unwrap(); + if account.balance >= balance_to_move { + let addresses = vec![from, to]; + let nonces = vec![nonce]; + let program_id = nssa::program::Program::authenticated_transfer_program().id(); + let message = nssa::public_transaction::Message::try_new( + program_id, + addresses, + nonces, + balance_to_move, + ) + .unwrap(); - let signing_key = account.key_holder.get_pub_account_signing_key(); - let witness_set = - nssa::public_transaction::WitnessSet::for_message(&message, &[signing_key]); + let signing_key = self.storage.user_data.get_account_signing_key(&from); - let tx = nssa::PublicTransaction::new(message, witness_set); + if let Some(signing_key) = signing_key { + let witness_set = + nssa::public_transaction::WitnessSet::for_message(&message, &[signing_key]); - Ok(self.sequencer_client.send_tx(tx).await?) + let tx = nssa::PublicTransaction::new(message, witness_set); + + Ok(self.sequencer_client.send_tx(tx).await?) + } else { + Err(ExecutionFailureKind::KeyNotFoundError) + } + } else { + Err(ExecutionFailureKind::InsufficientFundsError) + } } else { Err(ExecutionFailureKind::AmountMismatchError) } From 22cdce51026f9d9e24ae751fae428b9bfbf07843 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Mon, 1 Sep 2025 14:06:43 +0300 Subject: [PATCH 04/10] fix: comments fix --- key_protocol/src/key_protocol_core/mod.rs | 60 +---------------------- nssa/src/signature/private_key.rs | 3 +- 2 files changed, 2 insertions(+), 61 deletions(-) diff --git a/key_protocol/src/key_protocol_core/mod.rs b/key_protocol/src/key_protocol_core/mod.rs index 3b8092e..ab5840c 100644 --- a/key_protocol/src/key_protocol_core/mod.rs +++ b/key_protocol/src/key_protocol_core/mod.rs @@ -1,14 +1,9 @@ use std::collections::HashMap; -use anyhow::Result; use k256::AffinePoint; use serde::{Deserialize, Serialize}; -use crate::key_management::{ - constants_types::{CipherText, Nonce}, - ephemeral_key_holder::EphemeralKeyHolder, - KeyChain, -}; +use crate::key_management::KeyChain; pub type PublicKey = AffinePoint; @@ -18,33 +13,6 @@ pub struct NSSAUserData { pub accounts: HashMap, } -///A strucure, which represents all the visible(public) information -/// -/// known to each node about account `address` -/// -/// Main usage is to encode data for other account -#[derive(Serialize, Clone)] -pub struct NSSAUserDataPublicMask { - pub nullifier_public_key: AffinePoint, - pub viewing_public_key: AffinePoint, -} - -impl NSSAUserDataPublicMask { - pub fn encrypt_data( - ephemeral_key_holder: &EphemeralKeyHolder, - viewing_public_key_receiver: AffinePoint, - data: &[u8], - ) -> (CipherText, Nonce) { - //Using of parent NSSAUserData fuction - NSSAUserData::encrypt_data(ephemeral_key_holder, viewing_public_key_receiver, data) - } - - //ToDo: Part of a private keys update - // pub fn make_tag(&self) -> Tag { - // self.address.value()[0] - // } -} - impl NSSAUserData { pub fn new() -> Self { let key_holder = KeyChain::new_os_random(); @@ -90,24 +58,6 @@ impl NSSAUserData { self.key_holder.get_pub_account_signing_key(address) } - pub fn encrypt_data( - ephemeral_key_holder: &EphemeralKeyHolder, - viewing_public_key_receiver: AffinePoint, - data: &[u8], - ) -> (CipherText, Nonce) { - ephemeral_key_holder.encrypt_data(viewing_public_key_receiver, data) - } - - pub fn decrypt_data( - &self, - ephemeral_public_key_sender: AffinePoint, - ciphertext: CipherText, - nonce: Nonce, - ) -> Result, aes_gcm::Error> { - self.key_holder - .decrypt_data(ephemeral_public_key_sender, ciphertext, nonce) - } - pub fn update_account_balance(&mut self, address: nssa::Address, new_balance: u128) { self.accounts .entry(address) @@ -119,14 +69,6 @@ impl NSSAUserData { // pub fn make_tag(&self) -> Tag { // self.address.value()[0] // } - - ///Produce account public mask - pub fn make_account_public_mask(&self) -> NSSAUserDataPublicMask { - NSSAUserDataPublicMask { - nullifier_public_key: self.key_holder.nullifer_public_key, - viewing_public_key: self.key_holder.viewing_public_key, - } - } } impl Default for NSSAUserData { diff --git a/nssa/src/signature/private_key.rs b/nssa/src/signature/private_key.rs index abe5af6..667fc30 100644 --- a/nssa/src/signature/private_key.rs +++ b/nssa/src/signature/private_key.rs @@ -48,7 +48,6 @@ mod tests { #[test] fn test_produce_key() { - let key = PrivateKey::new_os_random(); - println!("{:?}", key.0); + let _key = PrivateKey::new_os_random(); } } From 5c3418ca8ec4725b3c57b2bbb30785248eb51440 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Mon, 1 Sep 2025 14:17:16 +0300 Subject: [PATCH 05/10] fix: comments fix 2 --- key_protocol/src/key_protocol_core/mod.rs | 23 ++++++++++++++++++++--- wallet/src/chain_storage/mod.rs | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/key_protocol/src/key_protocol_core/mod.rs b/key_protocol/src/key_protocol_core/mod.rs index ab5840c..eb946f9 100644 --- a/key_protocol/src/key_protocol_core/mod.rs +++ b/key_protocol/src/key_protocol_core/mod.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; +use anyhow::Result; use k256::AffinePoint; use serde::{Deserialize, Serialize}; @@ -23,16 +24,32 @@ impl NSSAUserData { } } + fn valid_key_transaction_pairing_check( + accounts_keys_map: &HashMap, + ) -> bool { + let mut check_res = true; + for (addr, key) in accounts_keys_map { + if &nssa::Address::from(&nssa::PublicKey::new_from_private_key(&key)) != addr { + check_res = false; + } + } + check_res + } + pub fn new_with_accounts( accounts_keys: HashMap, accounts: HashMap, - ) -> Self { + ) -> Result { + if !Self::valid_key_transaction_pairing_check(&accounts_keys) { + anyhow::bail!("Key transaction pairing check not satisfied, there is addresses, which is not derived from keys"); + } + let key_holder = KeyChain::new_os_random_with_accounts(accounts_keys); - Self { + Ok(Self { key_holder, accounts, - } + }) } pub fn generate_new_account(&mut self) -> nssa::Address { diff --git a/wallet/src/chain_storage/mod.rs b/wallet/src/chain_storage/mod.rs index 40c9ddc..dae0dc1 100644 --- a/wallet/src/chain_storage/mod.rs +++ b/wallet/src/chain_storage/mod.rs @@ -31,7 +31,7 @@ impl WalletChainStore { let utxo_commitments_store = UTXOCommitmentsMerkleTree::new(vec![]); Ok(Self { - user_data: NSSAUserData::new_with_accounts(accounts_keys, accounts), + user_data: NSSAUserData::new_with_accounts(accounts_keys, accounts)?, utxo_commitments_store, wallet_config: config, }) From 9993590d457344973d2a87a9651545b96ba3af3f Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Tue, 2 Sep 2025 07:32:39 +0300 Subject: [PATCH 06/10] fix: comments fix 2 --- key_protocol/src/key_protocol_core/mod.rs | 54 +- nssa/Cargo.toml | 2 +- nssa/core/Cargo.toml | 2 +- nssa/program_methods/Cargo.toml | 2 +- nssa/program_methods/guest/Cargo.lock | 715 +++++++++++++++------ nssa/program_methods/guest/Cargo.toml | 2 +- nssa/test_program_methods/Cargo.toml | 2 +- nssa/test_program_methods/guest/Cargo.toml | 2 +- wallet/Cargo.toml | 2 +- wallet/src/chain_storage/mod.rs | 10 +- wallet/src/lib.rs | 29 +- 11 files changed, 561 insertions(+), 261 deletions(-) diff --git a/key_protocol/src/key_protocol_core/mod.rs b/key_protocol/src/key_protocol_core/mod.rs index eb946f9..327b937 100644 --- a/key_protocol/src/key_protocol_core/mod.rs +++ b/key_protocol/src/key_protocol_core/mod.rs @@ -11,7 +11,6 @@ pub type PublicKey = AffinePoint; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct NSSAUserData { pub key_holder: KeyChain, - pub accounts: HashMap, } impl NSSAUserData { @@ -20,7 +19,6 @@ impl NSSAUserData { Self { key_holder, - accounts: HashMap::new(), } } @@ -38,7 +36,6 @@ impl NSSAUserData { pub fn new_with_accounts( accounts_keys: HashMap, - accounts: HashMap, ) -> Result { if !Self::valid_key_transaction_pairing_check(&accounts_keys) { anyhow::bail!("Key transaction pairing check not satisfied, there is addresses, which is not derived from keys"); @@ -48,44 +45,18 @@ impl NSSAUserData { Ok(Self { key_holder, - accounts, }) } pub fn generate_new_account(&mut self) -> nssa::Address { let address = self.key_holder.generate_new_private_key(); - self.accounts - .insert(address, nssa_core::account::Account::default()); address } - pub fn get_account_balance(&self, address: &nssa::Address) -> u128 { - self.accounts - .get(address) - .map(|acc| acc.balance) - .unwrap_or(0) - } - - pub fn get_account(&self, address: &nssa::Address) -> Option<&nssa_core::account::Account> { - self.accounts.get(address) - } - pub fn get_account_signing_key(&self, address: &nssa::Address) -> Option<&nssa::PrivateKey> { self.key_holder.get_pub_account_signing_key(address) } - - pub fn update_account_balance(&mut self, address: nssa::Address, new_balance: u128) { - self.accounts - .entry(address) - .and_modify(|acc| acc.balance = new_balance) - .or_default(); - } - - //ToDo: Part of a private keys update - // pub fn make_tag(&self) -> Tag { - // self.address.value()[0] - // } } impl Default for NSSAUserData { @@ -102,29 +73,6 @@ mod tests { fn test_new_account() { let mut user_data = NSSAUserData::new(); - let addr = user_data.generate_new_account(); - - assert_eq!(user_data.get_account_balance(&addr), 0); + let _addr = user_data.generate_new_account(); } - - #[test] - fn test_update_balance() { - let mut user_data = NSSAUserData::new(); - - let address = user_data.generate_new_account(); - - user_data.update_account_balance(address, 500); - - assert_eq!(user_data.get_account_balance(&address), 500); - } - - //ToDo: Part of a private keys update - // #[test] - // fn accounts_accounts_mask_tag_consistency() { - // let account = NSSAUserData::new(); - - // let account_mask = account.make_account_public_mask(); - - // assert_eq!(account.make_tag(), account_mask.make_tag()); - // } } diff --git a/nssa/Cargo.toml b/nssa/Cargo.toml index 5a579fd..4ebe658 100644 --- a/nssa/Cargo.toml +++ b/nssa/Cargo.toml @@ -5,7 +5,7 @@ edition = "2024" [dependencies] thiserror = "2.0.12" -risc0-zkvm = "2.3.1" +risc0-zkvm = "3.0.3" nssa-core = { path = "core" } program-methods = { path = "program_methods" } serde = "1.0.219" diff --git a/nssa/core/Cargo.toml b/nssa/core/Cargo.toml index feb907d..aba5e45 100644 --- a/nssa/core/Cargo.toml +++ b/nssa/core/Cargo.toml @@ -4,5 +4,5 @@ version = "0.1.0" edition = "2024" [dependencies] -risc0-zkvm = "2.3.1" +risc0-zkvm = "3.0.3" serde = { version = "1.0", default-features = false } diff --git a/nssa/program_methods/Cargo.toml b/nssa/program_methods/Cargo.toml index ea7e36b..af52307 100644 --- a/nssa/program_methods/Cargo.toml +++ b/nssa/program_methods/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [build-dependencies] -risc0-build = { version = "2.3.1" } +risc0-build = { version = "3.0.3" } [package.metadata.risc0] methods = ["guest"] diff --git a/nssa/program_methods/guest/Cargo.lock b/nssa/program_methods/guest/Cargo.lock index 1d3063f..dea19c8 100644 --- a/nssa/program_methods/guest/Cargo.lock +++ b/nssa/program_methods/guest/Cargo.lock @@ -44,6 +44,21 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anyhow" version = "1.0.98" @@ -303,6 +318,12 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64ct" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba" + [[package]] name = "bincode" version = "1.3.3" @@ -356,15 +377,15 @@ dependencies = [ [[package]] name = "bonsai-sdk" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bce8d6acc5286a16e94c29e9c885d1869358885e08a6feeb6bc54e36fe20055" +checksum = "21055e2f49cbbdbfe9f8f96d597c5527b0c6ab7933341fdc2f147180e48a988e" dependencies = [ "duplicate", "maybe-async", "reqwest", "serde", - "thiserror 1.0.69", + "thiserror", ] [[package]] @@ -460,7 +481,7 @@ dependencies = [ "semver", "serde", "serde_json", - "thiserror 2.0.12", + "thiserror", ] [[package]] @@ -484,13 +505,26 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-link", +] + [[package]] name = "cobs" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1" dependencies = [ - "thiserror 2.0.12", + "thiserror", ] [[package]] @@ -580,6 +614,27 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "deranged" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d630bccd429a5bb5a64b5e94f693bfc48c9f8566418fda4c494cc94f911f87cc" +dependencies = [ + "powerfmt", + "serde", +] + [[package]] name = "derivative" version = "2.2.0" @@ -657,23 +712,23 @@ dependencies = [ [[package]] name = "dirs" -version = "5.0.1" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e" dependencies = [ "dirs-sys", ] [[package]] name = "dirs-sys" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.48.0", + "windows-sys 0.60.2", ] [[package]] @@ -701,14 +756,21 @@ checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "duplicate" -version = "1.0.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de78e66ac9061e030587b2a2e75cc88f22304913c907b11307bca737141230cb" +checksum = "97af9b5f014e228b33e77d75ee0e6e87960124f0f4b16337b586a6bec91867b1" dependencies = [ - "heck 0.4.1", - "proc-macro-error", + "heck", + "proc-macro2", + "proc-macro2-diagnostics", ] +[[package]] +name = "dyn-clone" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" + [[package]] name = "educe" version = "0.6.0" @@ -802,6 +864,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "foreign-types" version = "0.5.0" @@ -945,12 +1013,9 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "hashbrown" -version = "0.14.5" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", -] +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" @@ -959,23 +1024,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" dependencies = [ "allocator-api2", + "foldhash", ] [[package]] name = "hashlink" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" dependencies = [ - "hashbrown 0.14.5", + "hashbrown 0.15.4", ] -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "heck" version = "0.5.0" @@ -1094,6 +1154,30 @@ dependencies = [ "tracing", ] +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "icu_collections" version = "2.0.0" @@ -1213,6 +1297,17 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ee796ad498c8d9a1d68e477df8f754ed784ef875de1414ebdaf169f70a6a784" +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + [[package]] name = "indexmap" version = "2.10.0" @@ -1221,6 +1316,7 @@ checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" dependencies = [ "equivalent", "hashbrown 0.15.4", + "serde", ] [[package]] @@ -1459,6 +1555,29 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-bigint-dig" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" +dependencies = [ + "byteorder", + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand 0.8.5", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.46" @@ -1468,6 +1587,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -1475,6 +1605,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", +] + +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.104", ] [[package]] @@ -1513,6 +1665,15 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -1531,6 +1692,27 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "postcard" version = "1.1.3" @@ -1552,6 +1734,12 @@ dependencies = [ "zerovec", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.21" @@ -1570,30 +1758,6 @@ dependencies = [ "toml_edit", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" version = "1.0.95" @@ -1603,6 +1767,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "proc-macro2-diagnostics" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.104", + "version_check", + "yansi", +] + [[package]] name = "programs" version = "0.1.0" @@ -1611,6 +1788,20 @@ dependencies = [ "risc0-zkvm", ] +[[package]] +name = "proptest" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fcdab19deb5195a31cf7726a210015ff1496ba1464fd42cb4f537b8b01b471f" +dependencies = [ + "bitflags 2.9.1", + "num-traits", + "rand 0.9.2", + "rand_chacha 0.9.0", + "rand_xorshift", + "unarray", +] + [[package]] name = "prost" version = "0.13.5" @@ -1648,7 +1839,7 @@ dependencies = [ "rustc-hash", "rustls", "socket2 0.5.10", - "thiserror 2.0.12", + "thiserror", "tokio", "tracing", "web-time", @@ -1669,7 +1860,7 @@ dependencies = [ "rustls", "rustls-pki-types", "slab", - "thiserror 2.0.12", + "thiserror", "tinyvec", "tracing", "web-time", @@ -1749,6 +1940,9 @@ name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.16", +] [[package]] name = "rand_core" @@ -1760,14 +1954,43 @@ dependencies = [ ] [[package]] -name = "redox_users" -version = "0.4.6" +name = "rand_xorshift" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a" +dependencies = [ + "rand_core 0.9.3", +] + +[[package]] +name = "redox_users" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" dependencies = [ "getrandom 0.2.16", "libredox", - "thiserror 1.0.69", + "thiserror", +] + +[[package]] +name = "ref-cast" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a0ae411dbe946a674d89546582cea4ba2bb8defac896622d6496f14c23ba5cf" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1165225c21bff1f3bbce98f5a1f889949bc902d3575308cc7b0de30b4f6d27c7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.104", ] [[package]] @@ -1857,18 +2080,21 @@ dependencies = [ [[package]] name = "risc0-binfmt" -version = "2.0.2" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62eb7025356a233c1bc267c458a2ce56fcfc89b136d813c8a77be14ef1eaf2b1" +checksum = "1c8f97f81bcdead4101bca06469ecef481a2695cd04e7e877b49dea56a7f6f2a" dependencies = [ "anyhow", "borsh", + "bytemuck", "derive_more", "elf", "lazy_static", "postcard", + "rand 0.9.2", "risc0-zkp", "risc0-zkvm-platform", + "ruint", "semver", "serde", "tracing", @@ -1876,9 +2102,9 @@ dependencies = [ [[package]] name = "risc0-build" -version = "2.3.1" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62ffc0f135e6c1e9851e7e19438d03ff41a9d49199ee4f6c17b8bb30b4f83910" +checksum = "1bbb512d728e011d03ce0958ca7954624ee13a215bcafd859623b3c63b2a3f60" dependencies = [ "anyhow", "cargo_metadata", @@ -1900,9 +2126,9 @@ dependencies = [ [[package]] name = "risc0-circuit-keccak" -version = "3.0.0" +version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0094af5a57b020388a03bdd3834959c7d62723f1687be81414ade25104d93263" +checksum = "5f195f865ac1afdc21a172d7756fdcc21be18e13eb01d78d3d7f2b128fa881ba" dependencies = [ "anyhow", "bytemuck", @@ -1916,9 +2142,9 @@ dependencies = [ [[package]] name = "risc0-circuit-recursion" -version = "3.0.0" +version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76ebded45c902c2b6939924a1cddd1d06b5d1d4ad1531e8798ebfee78f9c038d" +checksum = "dca8f15c8abc0fd8c097aa7459879110334d191c63dd51d4c28881c4a497279e" dependencies = [ "anyhow", "bytemuck", @@ -1931,9 +2157,9 @@ dependencies = [ [[package]] name = "risc0-circuit-rv32im" -version = "3.0.0" +version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15030849f8356f01f23c74b37dbfa4283100b594eb634109993e9e005ef45f64" +checksum = "ae1b0689f4a270a2f247b04397ebb431b8f64fe5170e98ee4f9d71bd04825205" dependencies = [ "anyhow", "bit-vec", @@ -1949,24 +2175,24 @@ dependencies = [ [[package]] name = "risc0-core" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317bbf70a8750b64d4fd7a2bdc9d7d5f30d8bb305cae486962c797ef35c8d08e" +checksum = "80f2723fedace48c6c5a505bd8f97ac4e1712bc4cb769083e10536d862b66987" dependencies = [ "bytemuck", - "bytemuck_derive", - "rand_core 0.6.4", + "rand_core 0.9.3", ] [[package]] name = "risc0-groth16" -version = "2.0.2" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cf5d0b673d5fc67a89147c2e9c53134707dcc8137a43d1ef06b4ff68e99b74f" +checksum = "724285dc79604abfb2d40feaefe3e335420a6b293511661f77d6af62f1f5fae9" dependencies = [ "anyhow", "ark-bn254", "ark-ec", + "ark-ff", "ark-groth16", "ark-serialize", "bytemuck", @@ -1976,24 +2202,24 @@ dependencies = [ "risc0-binfmt", "risc0-zkp", "serde", - "stability", ] [[package]] name = "risc0-zkos-v1compat" -version = "2.0.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f76c479b69d1987cb54ac72dcc017197296fdcd6daf78fafc10cbbd3a167a7de" +checksum = "840c2228803557a8b7dc035a8f196516b6fd68c9dc6ac092f0c86241b5b1bafb" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] name = "risc0-zkp" -version = "2.0.2" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a287e9cd6d7b3b38eeb49c62090c46a1935922309fbd997a9143ed8c43c8f3cb" +checksum = "ffb6bf356f469bb8744f72a07a37134c5812c1d55d6271bba80e87bdb7a58c8e" dependencies = [ "anyhow", "blake2", @@ -2005,7 +2231,7 @@ dependencies = [ "hex-literal", "metal", "paste", - "rand_core 0.6.4", + "rand_core 0.9.3", "risc0-core", "risc0-zkvm-platform", "serde", @@ -2016,9 +2242,9 @@ dependencies = [ [[package]] name = "risc0-zkvm" -version = "2.3.1" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9684b333c1c5d83f29ce2a92314ccfafd9d8cdfa6c4e19c07b97015d2f1eb9d0" +checksum = "3fcce11648a9ff60b8e7af2f0ce7fbf8d25275ab6d414cc91b9da69ee75bc978" dependencies = [ "anyhow", "bincode", @@ -2027,7 +2253,6 @@ dependencies = [ "bytemuck", "bytes", "derive_more", - "getrandom 0.2.16", "hex", "lazy-regex", "prost", @@ -2053,15 +2278,17 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.3" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cae9cb2c2f6cab2dfa395ea6e2576713929040c7fb0c5f4150d13e1119d18686" +checksum = "5c826f09626ab2ae76671673e5a232548ddd95a34eece2ea4ced5f010383f95b" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.16", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -2075,6 +2302,48 @@ dependencies = [ "paste", ] +[[package]] +name = "rsa" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78928ac1ed176a5ca1d17e578a1825f3d81ca54cf41053a592584b020cfd691b" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core 0.6.4", + "signature", + "spki", + "subtle", + "zeroize", +] + +[[package]] +name = "ruint" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ecb38f82477f20c5c3d62ef52d7c4e536e38ea9b73fb570a20c5cae0e14bcf6" +dependencies = [ + "borsh", + "proptest", + "rand 0.8.5", + "rand 0.9.2", + "ruint-macro", + "serde", + "valuable", + "zeroize", +] + +[[package]] +name = "ruint-macro" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" + [[package]] name = "rustc-demangle" version = "0.1.26" @@ -2149,19 +2418,47 @@ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "rzup" -version = "0.4.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "400558bf12d4292a7804093b60a437ba8b0219ea7d53716b2c010a0d31e5f4a8" +checksum = "5d2aed296f203fa64bcb4b52069356dd86d6ec578593985b919b6995bee1f0ae" dependencies = [ + "hex", + "rsa", "semver", "serde", + "serde_with", + "sha2", "strum", "tempfile", - "thiserror 2.0.12", + "thiserror", "toml", "yaml-rust2", ] +[[package]] +name = "schemars" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd191f9397d57d581cddd31014772520aa448f65ef991055d7f61582c65165f" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + +[[package]] +name = "schemars" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82d20c4491bc164fa2f6c5d44565947a52ad80b9505d8e36f8d54c27c739fcd0" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + [[package]] name = "semver" version = "1.0.26" @@ -2224,6 +2521,38 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2c45cd61fefa9db6f254525d46e392b852e0e61d9a1fd36e5bd183450a556d5" +dependencies = [ + "base64", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.10.0", + "schemars 0.9.0", + "schemars 1.0.4", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de90945e6565ce0d9a25098082ed4ee4002e047cb59892c318d66821e14bb30f" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.104", +] + [[package]] name = "sha2" version = "0.10.9" @@ -2241,6 +2570,16 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core 0.6.4", +] + [[package]] name = "slab" version = "0.4.10" @@ -2279,6 +2618,16 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "stability" version = "0.2.1" @@ -2303,23 +2652,22 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "strum" -version = "0.26.3" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf" dependencies = [ "strum_macros", ] [[package]] name = "strum_macros" -version = "0.26.4" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", - "rustversion", "syn 2.0.104", ] @@ -2384,33 +2732,13 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl 1.0.69", -] - [[package]] name = "thiserror" version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" dependencies = [ - "thiserror-impl 2.0.12", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.104", + "thiserror-impl", ] [[package]] @@ -2424,6 +2752,36 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "time" +version = "0.3.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ca967379f9d8eb8058d86ed467d81d03e81acd45757e4ca341c24affbe8e8e3" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9108bb380861b07264b950ded55a44a14a4adc68b9f5efd85aafc3aa4d40a68" + +[[package]] +name = "time-macros" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7182799245a7264ce590b349d90338f1c1affad93d2639aed5f8f69c090b334c" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tinystr" version = "0.8.1" @@ -2516,7 +2874,7 @@ version = "0.22.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ - "indexmap", + "indexmap 2.10.0", "serde", "serde_spanned", "toml_datetime", @@ -2629,6 +2987,12 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + [[package]] name = "unicode-ident" version = "1.0.18" @@ -2813,6 +3177,41 @@ dependencies = [ "rustls-pki-types", ] +[[package]] +name = "windows-core" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.104", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.104", +] + [[package]] name = "windows-link" version = "0.1.3" @@ -2820,12 +3219,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" [[package]] -name = "windows-sys" -version = "0.48.0" +name = "windows-result" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" dependencies = [ - "windows-targets 0.48.5", + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", ] [[package]] @@ -2855,21 +3263,6 @@ dependencies = [ "windows-targets 0.53.3", ] -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - [[package]] name = "windows-targets" version = "0.52.6" @@ -2903,12 +3296,6 @@ dependencies = [ "windows_x86_64_msvc 0.53.0", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" @@ -2921,12 +3308,6 @@ version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.6" @@ -2939,12 +3320,6 @@ version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -2969,12 +3344,6 @@ version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.6" @@ -2987,12 +3356,6 @@ version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.6" @@ -3005,12 +3368,6 @@ version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" @@ -3023,12 +3380,6 @@ version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.6" @@ -3067,15 +3418,21 @@ checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" [[package]] name = "yaml-rust2" -version = "0.9.0" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a1a1c0bc9823338a3bdf8c61f994f23ac004c6fa32c08cd152984499b445e8d" +checksum = "4ce2a4ff45552406d02501cea6c18d8a7e50228e7736a872951fe2fe75c91be7" dependencies = [ "arraydeque", "encoding_rs", "hashlink", ] +[[package]] +name = "yansi" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" + [[package]] name = "yoke" version = "0.8.0" diff --git a/nssa/program_methods/guest/Cargo.toml b/nssa/program_methods/guest/Cargo.toml index 4b377c8..0d47ccd 100644 --- a/nssa/program_methods/guest/Cargo.toml +++ b/nssa/program_methods/guest/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" [workspace] [dependencies] -risc0-zkvm = { version = "2.3.1", default-features = false, features = ['std'] } +risc0-zkvm = { version = "3.0.3", default-features = false, features = ['std'] } nssa-core = { path = "../../core" } diff --git a/nssa/test_program_methods/Cargo.toml b/nssa/test_program_methods/Cargo.toml index dded508..50d6ca2 100644 --- a/nssa/test_program_methods/Cargo.toml +++ b/nssa/test_program_methods/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [build-dependencies] -risc0-build = { version = "2.3.1" } +risc0-build = { version = "3.0.3" } [package.metadata.risc0] methods = ["guest"] diff --git a/nssa/test_program_methods/guest/Cargo.toml b/nssa/test_program_methods/guest/Cargo.toml index 4b377c8..0d47ccd 100644 --- a/nssa/test_program_methods/guest/Cargo.toml +++ b/nssa/test_program_methods/guest/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" [workspace] [dependencies] -risc0-zkvm = { version = "2.3.1", default-features = false, features = ['std'] } +risc0-zkvm = { version = "3.0.3", default-features = false, features = ['std'] } nssa-core = { path = "../../core" } diff --git a/wallet/Cargo.toml b/wallet/Cargo.toml index 4a67791..56974c4 100644 --- a/wallet/Cargo.toml +++ b/wallet/Cargo.toml @@ -18,7 +18,7 @@ reqwest.workspace = true thiserror.workspace = true tokio.workspace = true tempfile.workspace = true -risc0-zkvm = "2.3.1" +risc0-zkvm = "3.0.3" hex.workspace = true actix-rt.workspace = true clap.workspace = true diff --git a/wallet/src/chain_storage/mod.rs b/wallet/src/chain_storage/mod.rs index dae0dc1..7dfb8a2 100644 --- a/wallet/src/chain_storage/mod.rs +++ b/wallet/src/chain_storage/mod.rs @@ -14,13 +14,6 @@ pub struct WalletChainStore { impl WalletChainStore { pub fn new(config: WalletConfig) -> Result { - let accounts: HashMap = config - .initial_accounts - .clone() - .into_iter() - .map(|init_acc_data| (init_acc_data.address, init_acc_data.account)) - .collect(); - let accounts_keys: HashMap = config .initial_accounts .clone() @@ -31,7 +24,7 @@ impl WalletChainStore { let utxo_commitments_store = UTXOCommitmentsMerkleTree::new(vec![]); Ok(Self { - user_data: NSSAUserData::new_with_accounts(accounts_keys, accounts)?, + user_data: NSSAUserData::new_with_accounts(accounts_keys)?, utxo_commitments_store, wallet_config: config, }) @@ -93,7 +86,6 @@ mod tests { let store = WalletChainStore::new(config.clone()).unwrap(); - assert_eq!(store.user_data.accounts.len(), 2); assert_eq!( store.utxo_commitments_store.get_root().unwrap_or([0; 32]), [0; 32] diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index 2c4b711..a12d52f 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -12,9 +12,10 @@ use log::info; use nssa::Address; use clap::{Parser, Subcommand}; +use nssa_core::account::Account; use crate::helperfunctions::{ - fetch_config, fetch_persistent_accounts, produce_account_addr_from_hex, + fetch_config, produce_account_addr_from_hex, }; pub const HOME_DIR_ENV_VAR: &str = "NSSA_WALLET_HOME_DIR"; @@ -30,17 +31,10 @@ pub struct WalletCore { } impl WalletCore { - pub async fn start_from_config_update_chain(config: WalletConfig) -> Result { + pub fn start_from_config_update_chain(config: WalletConfig) -> Result { let client = Arc::new(SequencerClient::new(config.sequencer_addr.clone())?); - let mut storage = WalletChainStore::new(config)?; - - let persistent_accounts = fetch_persistent_accounts()?; - for acc in persistent_accounts { - storage - .user_data - .update_account_balance(acc.address, acc.account.balance); - } + let storage = WalletChainStore::new(config)?; Ok(Self { storage, @@ -48,10 +42,19 @@ impl WalletCore { }) } - pub async fn create_new_account(&mut self) -> Address { + pub fn create_new_account(&mut self) -> Address { self.storage.user_data.generate_new_account() } + pub fn search_for_initial_account(&self, acc_addr: Address) -> Option { + for initial_acc in &self.storage.wallet_config.initial_accounts { + if initial_acc.address == acc_addr { + return Some(initial_acc.account.clone()); + } + } + None + } + pub async fn send_public_native_token_transfer( &self, from: Address, @@ -59,7 +62,7 @@ impl WalletCore { to: Address, balance_to_move: u128, ) -> Result { - let account = self.storage.user_data.get_account(&from); + let account = self.search_for_initial_account(from); if let Some(account) = account { if account.balance >= balance_to_move { @@ -138,7 +141,7 @@ pub async fn execute_subcommand(command: Command) -> Result<()> { let from = produce_account_addr_from_hex(from)?; let to = produce_account_addr_from_hex(to)?; - let wallet_core = WalletCore::start_from_config_update_chain(wallet_config).await?; + let wallet_core = WalletCore::start_from_config_update_chain(wallet_config)?; let res = wallet_core .send_public_native_token_transfer(from, nonce, to, amount) From 5de28e999e28fbbfa19eeb009e9073ad31e86a1c Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Tue, 2 Sep 2025 07:44:24 +0300 Subject: [PATCH 07/10] fix: fmt fix --- key_protocol/src/key_protocol_core/mod.rs | 8 ++------ wallet/src/lib.rs | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/key_protocol/src/key_protocol_core/mod.rs b/key_protocol/src/key_protocol_core/mod.rs index 327b937..c2cbbee 100644 --- a/key_protocol/src/key_protocol_core/mod.rs +++ b/key_protocol/src/key_protocol_core/mod.rs @@ -17,9 +17,7 @@ impl NSSAUserData { pub fn new() -> Self { let key_holder = KeyChain::new_os_random(); - Self { - key_holder, - } + Self { key_holder } } fn valid_key_transaction_pairing_check( @@ -43,9 +41,7 @@ impl NSSAUserData { let key_holder = KeyChain::new_os_random_with_accounts(accounts_keys); - Ok(Self { - key_holder, - }) + Ok(Self { key_holder }) } pub fn generate_new_account(&mut self) -> nssa::Address { diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index a12d52f..e2213dc 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -14,9 +14,7 @@ use nssa::Address; use clap::{Parser, Subcommand}; use nssa_core::account::Account; -use crate::helperfunctions::{ - fetch_config, produce_account_addr_from_hex, -}; +use crate::helperfunctions::{fetch_config, produce_account_addr_from_hex}; pub const HOME_DIR_ENV_VAR: &str = "NSSA_WALLET_HOME_DIR"; pub const BLOCK_GEN_DELAY_SECS: u64 = 20; From 7c42b3de1020cbeb92f282c3115c0c7f3d248cf7 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Tue, 2 Sep 2025 07:51:49 +0300 Subject: [PATCH 08/10] fix: lint fix 1 --- key_protocol/src/key_protocol_core/mod.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/key_protocol/src/key_protocol_core/mod.rs b/key_protocol/src/key_protocol_core/mod.rs index c2cbbee..67cb52c 100644 --- a/key_protocol/src/key_protocol_core/mod.rs +++ b/key_protocol/src/key_protocol_core/mod.rs @@ -25,7 +25,7 @@ impl NSSAUserData { ) -> bool { let mut check_res = true; for (addr, key) in accounts_keys_map { - if &nssa::Address::from(&nssa::PublicKey::new_from_private_key(&key)) != addr { + if &nssa::Address::from(&nssa::PublicKey::new_from_private_key(key)) != addr { check_res = false; } } @@ -45,9 +45,7 @@ impl NSSAUserData { } pub fn generate_new_account(&mut self) -> nssa::Address { - let address = self.key_holder.generate_new_private_key(); - - address + self.key_holder.generate_new_private_key() } pub fn get_account_signing_key(&self, address: &nssa::Address) -> Option<&nssa::PrivateKey> { From 4ac2196ddfebadc390880eaad2375bd3d7dcb7a6 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Tue, 2 Sep 2025 16:11:27 +0300 Subject: [PATCH 09/10] fix: lock update --- nssa/program_methods/guest/Cargo.lock | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nssa/program_methods/guest/Cargo.lock b/nssa/program_methods/guest/Cargo.lock index 9c164d2..18285e9 100644 --- a/nssa/program_methods/guest/Cargo.lock +++ b/nssa/program_methods/guest/Cargo.lock @@ -1340,6 +1340,15 @@ dependencies = [ "serde", ] +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", +] + [[package]] name = "io-uring" version = "0.7.9" From 570a516cbfd1408bcaa7ff1de994dc7cd6f8d314 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Tue, 2 Sep 2025 16:22:40 +0300 Subject: [PATCH 10/10] fix: merge fix --- nssa/src/address.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/nssa/src/address.rs b/nssa/src/address.rs index 7e4bc1e..93304d5 100644 --- a/nssa/src/address.rs +++ b/nssa/src/address.rs @@ -1,5 +1,7 @@ use std::{fmt::Display, str::FromStr}; +use serde::{Deserialize, Serialize}; + use crate::signature::PublicKey; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] @@ -57,6 +59,28 @@ impl Display for Address { } } +impl Serialize for Address { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let hex_string = self.to_string(); + + hex_string.serialize(serializer) + } +} + +impl<'de> Deserialize<'de> for Address { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let hex_string = String::deserialize(deserializer)?; + + Address::from_str(&hex_string).map_err(serde::de::Error::custom) + } +} + #[cfg(test)] mod tests { use crate::{Address, address::AddressError};