diff --git a/artifacts/program_methods/amm.bin b/artifacts/program_methods/amm.bin
index a8ca1f4e..f058acd6 100644
Binary files a/artifacts/program_methods/amm.bin and b/artifacts/program_methods/amm.bin differ
diff --git a/artifacts/program_methods/authenticated_transfer.bin b/artifacts/program_methods/authenticated_transfer.bin
index 0bc3de67..88ddb2c5 100644
Binary files a/artifacts/program_methods/authenticated_transfer.bin and b/artifacts/program_methods/authenticated_transfer.bin differ
diff --git a/artifacts/program_methods/pinata.bin b/artifacts/program_methods/pinata.bin
index 64aaa346..bf6b7a5e 100644
Binary files a/artifacts/program_methods/pinata.bin and b/artifacts/program_methods/pinata.bin differ
diff --git a/artifacts/program_methods/pinata_token.bin b/artifacts/program_methods/pinata_token.bin
index a47d90f4..c4b23989 100644
Binary files a/artifacts/program_methods/pinata_token.bin and b/artifacts/program_methods/pinata_token.bin differ
diff --git a/artifacts/program_methods/privacy_preserving_circuit.bin b/artifacts/program_methods/privacy_preserving_circuit.bin
index 8e151aa7..4a7b82c0 100644
Binary files a/artifacts/program_methods/privacy_preserving_circuit.bin and b/artifacts/program_methods/privacy_preserving_circuit.bin differ
diff --git a/artifacts/program_methods/token.bin b/artifacts/program_methods/token.bin
index 9a1269c5..7c116318 100644
Binary files a/artifacts/program_methods/token.bin and b/artifacts/program_methods/token.bin differ
diff --git a/artifacts/test_program_methods/burner.bin b/artifacts/test_program_methods/burner.bin
index b055fbdb..514166ff 100644
Binary files a/artifacts/test_program_methods/burner.bin and b/artifacts/test_program_methods/burner.bin differ
diff --git a/artifacts/test_program_methods/chain_caller.bin b/artifacts/test_program_methods/chain_caller.bin
index c650f1f9..6e3c3ae4 100644
Binary files a/artifacts/test_program_methods/chain_caller.bin and b/artifacts/test_program_methods/chain_caller.bin differ
diff --git a/artifacts/test_program_methods/changer_claimer.bin b/artifacts/test_program_methods/changer_claimer.bin
index 2dea3a0d..9e3a452d 100644
Binary files a/artifacts/test_program_methods/changer_claimer.bin and b/artifacts/test_program_methods/changer_claimer.bin differ
diff --git a/artifacts/test_program_methods/claimer.bin b/artifacts/test_program_methods/claimer.bin
index fb881bbc..8b7c04b0 100644
Binary files a/artifacts/test_program_methods/claimer.bin and b/artifacts/test_program_methods/claimer.bin differ
diff --git a/artifacts/test_program_methods/data_changer.bin b/artifacts/test_program_methods/data_changer.bin
index 5a7a8600..861b7be4 100644
Binary files a/artifacts/test_program_methods/data_changer.bin and b/artifacts/test_program_methods/data_changer.bin differ
diff --git a/artifacts/test_program_methods/extra_output.bin b/artifacts/test_program_methods/extra_output.bin
index fc8dc194..758ae8a2 100644
Binary files a/artifacts/test_program_methods/extra_output.bin and b/artifacts/test_program_methods/extra_output.bin differ
diff --git a/artifacts/test_program_methods/malicious_authorization_changer.bin b/artifacts/test_program_methods/malicious_authorization_changer.bin
index 99dcd50f..33e01400 100644
Binary files a/artifacts/test_program_methods/malicious_authorization_changer.bin and b/artifacts/test_program_methods/malicious_authorization_changer.bin differ
diff --git a/artifacts/test_program_methods/minter.bin b/artifacts/test_program_methods/minter.bin
index 7ea603a5..20781cba 100644
Binary files a/artifacts/test_program_methods/minter.bin and b/artifacts/test_program_methods/minter.bin differ
diff --git a/artifacts/test_program_methods/missing_output.bin b/artifacts/test_program_methods/missing_output.bin
index 3b2379c7..95b412b6 100644
Binary files a/artifacts/test_program_methods/missing_output.bin and b/artifacts/test_program_methods/missing_output.bin differ
diff --git a/artifacts/test_program_methods/modified_transfer.bin b/artifacts/test_program_methods/modified_transfer.bin
index 48900c0c..7b7438ee 100644
Binary files a/artifacts/test_program_methods/modified_transfer.bin and b/artifacts/test_program_methods/modified_transfer.bin differ
diff --git a/artifacts/test_program_methods/nonce_changer.bin b/artifacts/test_program_methods/nonce_changer.bin
index b5ef1b9a..97b23f93 100644
Binary files a/artifacts/test_program_methods/nonce_changer.bin and b/artifacts/test_program_methods/nonce_changer.bin differ
diff --git a/artifacts/test_program_methods/noop.bin b/artifacts/test_program_methods/noop.bin
index c3b1d1d6..e487da6b 100644
Binary files a/artifacts/test_program_methods/noop.bin and b/artifacts/test_program_methods/noop.bin differ
diff --git a/artifacts/test_program_methods/program_owner_changer.bin b/artifacts/test_program_methods/program_owner_changer.bin
index b697cc70..d318cbda 100644
Binary files a/artifacts/test_program_methods/program_owner_changer.bin and b/artifacts/test_program_methods/program_owner_changer.bin differ
diff --git a/artifacts/test_program_methods/simple_balance_transfer.bin b/artifacts/test_program_methods/simple_balance_transfer.bin
index b54383e2..ca22e0f5 100644
Binary files a/artifacts/test_program_methods/simple_balance_transfer.bin and b/artifacts/test_program_methods/simple_balance_transfer.bin differ
diff --git a/explorer_service/src/components/account_preview.rs b/explorer_service/src/components/account_preview.rs
index c40391a8..bbe59c0f 100644
--- a/explorer_service/src/components/account_preview.rs
+++ b/explorer_service/src/components/account_preview.rs
@@ -31,7 +31,7 @@ pub fn AccountPreview(account_id: AccountId, account: Account) -> impl IntoView
"Nonce: "
- {nonce.0.to_string()}
+ {nonce.to_string()}
"Data: "
diff --git a/explorer_service/src/pages/account_page.rs b/explorer_service/src/pages/account_page.rs
index fdee3bb6..a02a8b7c 100644
--- a/explorer_service/src/pages/account_page.rs
+++ b/explorer_service/src/pages/account_page.rs
@@ -97,7 +97,7 @@ pub fn AccountPage() -> impl IntoView {
let account_id_str = acc_id.to_string();
let program_id = program_owner.to_string();
let balance_str = balance.to_string();
- let nonce_str = nonce.0.to_string();
+ let nonce_str = nonce.to_string();
let data_len = data.0.len();
view! {
diff --git a/explorer_service/src/pages/transaction_page.rs b/explorer_service/src/pages/transaction_page.rs
index 41b0d311..211dc505 100644
--- a/explorer_service/src/pages/transaction_page.rs
+++ b/explorer_service/src/pages/transaction_page.rs
@@ -126,7 +126,7 @@ pub fn TransactionPage() -> impl IntoView {
{account_id_str}
- " (nonce: " {nonce.0.to_string()} ")"
+ " (nonce: " {nonce.to_string()} ")"
}
@@ -229,7 +229,7 @@ pub fn TransactionPage() -> impl IntoView {
{account_id_str}
- " (nonce: " {nonce.0.to_string()} ")"
+ " (nonce: " {nonce.to_string()} ")"
}
diff --git a/indexer/service/protocol/src/convert.rs b/indexer/service/protocol/src/convert.rs
index cbafa0b3..499baa4c 100644
--- a/indexer/service/protocol/src/convert.rs
+++ b/indexer/service/protocol/src/convert.rs
@@ -1,5 +1,7 @@
//! Conversions between `indexer_service_protocol` types and `nssa/nssa_core` types.
+use nssa_core::account::Nonce;
+
use crate::{
Account, AccountId, BedrockStatus, Block, BlockBody, BlockHeader, Ciphertext, Commitment,
CommitmentSetDigest, Data, EncryptedAccountData, EphemeralPublicKey, HashType, MantleMsgId,
@@ -52,7 +54,7 @@ impl From for Account {
program_owner: program_owner.into(),
balance,
data: data.into(),
- nonce,
+ nonce: nonce.0,
}
}
}
@@ -72,7 +74,7 @@ impl TryFrom for nssa_core::account::Account {
program_owner: program_owner.into(),
balance,
data: data.try_into()?,
- nonce,
+ nonce: Nonce(nonce),
})
}
}
@@ -250,7 +252,7 @@ impl From for PublicMessage {
Self {
program_id: program_id.into(),
account_ids: account_ids.into_iter().map(Into::into).collect(),
- nonces,
+ nonces: nonces.iter().map(|x| x.0).collect(),
instruction_data,
}
}
@@ -267,7 +269,10 @@ impl From for nssa::public_transaction::Message {
Self::new_preserialized(
program_id.into(),
account_ids.into_iter().map(Into::into).collect(),
- nonces,
+ nonces
+ .iter()
+ .map(|x| nssa_core::account::Nonce(*x))
+ .collect(),
instruction_data,
)
}
@@ -285,7 +290,7 @@ impl From for PrivacyPre
} = value;
Self {
public_account_ids: public_account_ids.into_iter().map(Into::into).collect(),
- nonces,
+ nonces: nonces.iter().map(|x| x.0).collect(),
public_post_states: public_post_states.into_iter().map(Into::into).collect(),
encrypted_private_post_states: encrypted_private_post_states
.into_iter()
@@ -314,7 +319,10 @@ impl TryFrom for nssa::privacy_preserving_transaction:
} = value;
Ok(Self {
public_account_ids: public_account_ids.into_iter().map(Into::into).collect(),
- nonces,
+ nonces: nonces
+ .iter()
+ .map(|x| nssa_core::account::Nonce(*x))
+ .collect(),
public_post_states: public_post_states
.into_iter()
.map(TryInto::try_into)
diff --git a/integration_tests/tests/tps.rs b/integration_tests/tests/tps.rs
index c89ee761..1dee3a85 100644
--- a/integration_tests/tests/tps.rs
+++ b/integration_tests/tests/tps.rs
@@ -27,7 +27,7 @@ use nssa::{
};
use nssa_core::{
MembershipProof, NullifierPublicKey,
- account::{AccountWithMetadata, data::Data},
+ account::{AccountWithMetadata, Nonce, data::Data},
encryption::ViewingPublicKey,
};
use tokio::test;
@@ -78,7 +78,7 @@ impl TpsTestManager {
let message = putx::Message::try_new(
program.id(),
[pair[0].1, pair[1].1].to_vec(),
- [0_u128].to_vec(),
+ [Nonce(0_u128)].to_vec(),
amount,
)
.unwrap();
@@ -107,7 +107,7 @@ impl TpsTestManager {
let key_chain = KeyChain::new_os_random();
let account = Account {
balance: 100,
- nonce: 0xdead_beef,
+ nonce: Nonce(0xdead_beef),
program_owner: Program::authenticated_transfer_program().id(),
data: Data::default(),
};
@@ -216,7 +216,7 @@ fn build_privacy_transaction() -> PrivacyPreservingTransaction {
let sender_pre = AccountWithMetadata::new(
Account {
balance: 100,
- nonce: 0xdead_beef,
+ nonce: Nonce(0xdead_beef),
program_owner: program.id(),
data: Data::default(),
},
@@ -250,7 +250,6 @@ fn build_privacy_transaction() -> PrivacyPreservingTransaction {
vec![sender_pre, recipient_pre],
Program::serialize_instruction(balance_to_move).unwrap(),
vec![1, 2],
- vec![0xdead_beef1, 0xdead_beef2],
vec![
(sender_npk.clone(), sender_ss),
(recipient_npk.clone(), recipient_ss),
diff --git a/nssa/core/src/account.rs b/nssa/core/src/account.rs
index 29c967f7..fd62628f 100644
--- a/nssa/core/src/account.rs
+++ b/nssa/core/src/account.rs
@@ -6,7 +6,7 @@ use std::{
use base58::{FromBase58 as _, ToBase58 as _};
use borsh::{BorshDeserialize, BorshSerialize};
pub use data::Data;
-use risc0_zkvm::sha::{Impl, Sha256};
+use risc0_zkvm::sha::{Impl, Sha256 as _};
use serde::{Deserialize, Serialize};
use serde_with::{DeserializeFromStr, SerializeDisplay};
@@ -18,27 +18,32 @@ pub mod data;
pub struct Nonce(pub u128);
impl Nonce {
- pub fn public_account_nonce_increment(&mut self) {
- self.0 += 1;
+ pub const fn public_account_nonce_increment(&mut self) {
+ self.0 = self
+ .0
+ .checked_add(1)
+ .expect("Overflow when incrementing nonce");
}
- pub fn private_account_nonce_init(npk: &NullifierPublicKey) -> Nonce {
- let mut bytes: [u8; 64] = [0u8; 64];
+ #[must_use]
+ pub fn private_account_nonce_init(npk: &NullifierPublicKey) -> Self {
+ let mut bytes: [u8; 64] = [0_u8; 64];
bytes[..32].copy_from_slice(&npk.0);
let result: [u8; 32] = Impl::hash_bytes(&bytes).as_bytes().try_into().unwrap();
let result = result.first_chunk::<16>().unwrap();
- Nonce(u128::from_le_bytes(*result))
+ Self(u128::from_le_bytes(*result))
}
- pub fn private_account_nonce_increment(self, nsk: &NullifierSecretKey) -> Nonce {
- let mut bytes: [u8; 64] = [0u8; 64];
+ #[must_use]
+ pub fn private_account_nonce_increment(self, nsk: &NullifierSecretKey) -> Self {
+ let mut bytes: [u8; 64] = [0_u8; 64];
bytes[..32].copy_from_slice(nsk);
bytes[32..48].copy_from_slice(&self.0.to_le_bytes());
let result: [u8; 32] = Impl::hash_bytes(&bytes).as_bytes().try_into().unwrap();
let result = result.first_chunk::<16>().unwrap();
- Nonce(u128::from_le_bytes(*result))
+ Self(u128::from_le_bytes(*result))
}
}
diff --git a/nssa/core/src/encoding.rs b/nssa/core/src/encoding.rs
index 2bbbbc8d..f4c7931d 100644
--- a/nssa/core/src/encoding.rs
+++ b/nssa/core/src/encoding.rs
@@ -26,7 +26,7 @@ impl Account {
}
bytes.extend_from_slice(&self.balance.to_le_bytes());
bytes.extend_from_slice(&self.nonce.0.to_le_bytes());
- let data_length: u32 = self.data.len() as u32;
+ let data_length: u32 = u32::try_from(self.data.len()).expect("Invalid u32");
bytes.extend_from_slice(&data_length.to_le_bytes());
bytes.extend_from_slice(self.data.as_ref());
bytes
diff --git a/nssa/src/privacy_preserving_transaction/circuit.rs b/nssa/src/privacy_preserving_transaction/circuit.rs
index 084b05db..ee312dc5 100644
--- a/nssa/src/privacy_preserving_transaction/circuit.rs
+++ b/nssa/src/privacy_preserving_transaction/circuit.rs
@@ -68,7 +68,6 @@ pub fn execute_and_prove(
pre_states: Vec,
instruction_data: InstructionData,
visibility_mask: Vec,
- private_account_nonces: Vec,
private_account_keys: Vec<(NullifierPublicKey, SharedSecretKey)>,
private_account_nsks: Vec,
private_account_membership_proofs: Vec