fix: try unify program id

This commit is contained in:
Oleksandr Pravdyvyi 2025-09-24 14:29:56 +03:00
parent d7c577061e
commit a7c60a56b7
No known key found for this signature in database
GPG Key ID: 9F8955C63C443871
7 changed files with 200 additions and 30 deletions

View File

@ -8,4 +8,4 @@ RISC0_DEV_MODE=1 cargo test --release
cd integration_tests
export NSSA_WALLET_HOME_DIR=$(pwd)/configs/debug/wallet/
export RUST_LOG=info
cargo run $(pwd)/configs/debug all
cargo run $(pwd)/configs/debug test_success_private_transfer_to_another_owned_account

View File

@ -17,9 +17,141 @@
}
],
"initial_commitments": [
[180, 94, 202, 138, 152, 13, 198, 85, 53, 34, 255, 86, 236, 7, 221, 33, 122, 36, 153, 139, 78, 195, 176, 14, 75, 126, 237, 137, 97, 120, 122, 112],
[24, 182, 41, 27, 99, 75, 199, 242, 219, 65, 169, 113, 177, 133, 128, 230, 217, 250, 159, 47, 36, 57, 27, 163, 42, 99, 181, 16, 224, 135, 53, 24]
{
"npk": [
193,
209,
150,
113,
47,
241,
48,
145,
250,
79,
235,
51,
119,
40,
184,
232,
5,
221,
36,
21,
201,
106,
90,
210,
129,
106,
71,
99,
208,
153,
75,
215
],
"account": {
"program_owner": [
2357946808,
1250390931,
1946783766,
2395930623,
2256469211,
3226409911,
3251831113,
2343238083
],
"balance": 10000,
"data": [],
"nonce": 0
}
},
{
"npk": [
27,
250,
136,
142,
88,
128,
138,
21,
49,
183,
118,
160,
117,
114,
110,
47,
136,
87,
60,
70,
59,
60,
18,
223,
23,
147,
241,
5,
184,
103,
225,
105
],
"account": {
"program_owner": [
2357946808,
1250390931,
1946783766,
2395930623,
2256469211,
3226409911,
3251831113,
2343238083
],
"balance": 20000,
"data": [],
"nonce": 0
}
}
],
"signing_key": [37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
37, 37, 37, 37, 37, 37]
}
"signing_key": [
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37,
37
]
}

View File

@ -90,14 +90,14 @@
"address": "6ffe0893c4b2c956fdb769b11fe4e3b2dd36ac4bd0ad90c810844051747c8c04",
"account": {
"program_owner": [
1793544791,
852173979,
3315478100,
4158236927,
146723505,
3793635251,
999304864,
2535706995
2357946808,
1250390931,
1946783766,
2395930623,
2256469211,
3226409911,
3251831113,
2343238083
],
"balance": 10000,
"data": [],
@ -319,14 +319,14 @@
"address": "4ee9de60e33da96fd72929f1485fb365bcc9c1634dd44e4ba55b1ab96692674b",
"account": {
"program_owner": [
1793544791,
852173979,
3315478100,
4158236927,
146723505,
3793635251,
999304864,
2535706995
2357946808,
1250390931,
1946783766,
2395930623,
2256469211,
3226409911,
3251831113,
2343238083
],
"balance": 20000,
"data": [],

View File

@ -53,22 +53,30 @@ pub fn validate_execution(
return false;
}
println!("HELLO 1");
for (pre, post) in pre_states.iter().zip(post_states) {
// 2. Nonce must remain unchanged
if pre.account.nonce != post.nonce {
return false;
}
println!("HELLO 2");
// 3. Ownership change only allowed from default accounts
if pre.account.program_owner != post.program_owner && pre.account != Account::default() {
return false;
}
println!("HELLO 3");
// 4. Decreasing balance only allowed if owned by executing program
if post.balance < pre.account.balance && pre.account.program_owner != executing_program_id {
return false;
}
println!("HELLO 4");
// 5. Data changes only allowed if owned by executing program
if pre.account.data != post.data
&& (executing_program_id != pre.account.program_owner
@ -76,6 +84,8 @@ pub fn validate_execution(
{
return false;
}
println!("HELLO 5");
}
// 6. Total balance is preserved

View File

@ -9,6 +9,13 @@ pub struct AccountInitialData {
pub balance: u128,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
///Helperstruct to initialize commitments
pub struct CommitmentsInitialData {
pub npk: nssa_core::NullifierPublicKey,
pub account: nssa_core::account::Account,
}
#[derive(Clone, Serialize, Deserialize)]
pub struct SequencerConfig {
///Home dir of sequencer storage
@ -28,7 +35,7 @@ pub struct SequencerConfig {
///List of initial accounts data
pub initial_accounts: Vec<AccountInitialData>,
///List of initial commitments
pub initial_commitments: Vec<nssa_core::Commitment>,
pub initial_commitments: Vec<CommitmentsInitialData>,
///Sequencer own signing key
pub signing_key: [u8; 32],
}

View File

@ -49,13 +49,27 @@ impl std::error::Error for TransactionMalformationErrorKind {}
impl SequencerCore {
pub fn start_from_config(config: SequencerConfig) -> Self {
let mut initial_commitments = vec![];
for init_comm_data in config.initial_commitments.clone() {
let npk = init_comm_data.npk;
let mut acc = init_comm_data.account;
acc.program_owner = nssa::program::Program::authenticated_transfer_program().id();
let comm = nssa_core::Commitment::new(&npk, &acc);
initial_commitments.push(comm);
}
Self {
store: SequecerChainStore::new_with_genesis(
&config.home,
config.genesis_id,
config.is_genesis_random,
&config.initial_accounts,
&config.initial_commitments,
&initial_commitments,
nssa::PrivateKey::try_new(config.signing_key).unwrap(),
),
mempool: MemPool::default(),

View File

@ -110,14 +110,14 @@ impl WalletCore {
to: Address,
balance_to_move: u128,
) -> Result<(SendTxResponse, nssa_core::SharedSecretKey), ExecutionFailureKind> {
let from_data = self.storage.user_data.get_private_account(&from);
let to_data = self.storage.user_data.get_private_account(&to);
let from_data = self.storage.user_data.get_private_account(&from).cloned();
let to_data = self.storage.user_data.get_private_account(&to).cloned();
let Some((from_keys, from_acc)) = from_data else {
let Some((from_keys, mut from_acc)) = from_data else {
return Err(ExecutionFailureKind::KeyNotFoundError);
};
let Some((to_keys, to_acc)) = to_data else {
let Some((to_keys, mut to_acc)) = to_data else {
return Err(ExecutionFailureKind::KeyNotFoundError);
};
@ -126,10 +126,17 @@ impl WalletCore {
if from_acc.balance >= balance_to_move {
let program = nssa::program::Program::authenticated_transfer_program();
//Kind of hacky solution
//The issue is that we don't have deterministic builds
//and native_token_transfer at different machine may be different
from_acc.program_owner = nssa::program::Program::authenticated_transfer_program().id();
to_acc.program_owner = nssa::program::Program::authenticated_transfer_program().id();
let sender_commitment =
nssa_core::Commitment::new(&from_keys.nullifer_public_key, from_acc);
nssa_core::Commitment::new(&from_keys.nullifer_public_key, &from_acc);
let receiver_commitment =
nssa_core::Commitment::new(&to_keys.nullifer_public_key, to_acc);
nssa_core::Commitment::new(&to_keys.nullifer_public_key, &to_acc);
let sender_pre = nssa_core::account::AccountWithMetadata {
account: from_acc.clone(),