mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-02 13:23:10 +00:00
rollback to is_authorized field
This commit is contained in:
parent
cee882502c
commit
80505f0440
@ -20,6 +20,7 @@ pub type FingerPrint = [u8; 32];
|
||||
#[cfg_attr(any(feature = "host", test), derive(Debug, PartialEq, Eq))]
|
||||
pub struct AccountWithMetadata {
|
||||
pub account: Account,
|
||||
pub is_authorized: bool,
|
||||
pub fingerprint: FingerPrint,
|
||||
}
|
||||
|
||||
|
||||
@ -56,6 +56,7 @@ mod tests {
|
||||
data: b"test data".to_vec(),
|
||||
nonce: 18446744073709551614,
|
||||
},
|
||||
is_authorized: true,
|
||||
fingerprint: [0; 32],
|
||||
},
|
||||
AccountWithMetadata {
|
||||
@ -65,6 +66,7 @@ mod tests {
|
||||
data: b"test data".to_vec(),
|
||||
nonce: 9999999999999999999999,
|
||||
},
|
||||
is_authorized: false,
|
||||
fingerprint: [1; 32],
|
||||
},
|
||||
],
|
||||
|
||||
@ -22,7 +22,6 @@ pub struct ProgramOutput {
|
||||
pub fn read_nssa_inputs<T: DeserializeOwned>() -> ProgramInput<T> {
|
||||
let pre_states: Vec<AccountWithMetadata> = env::read();
|
||||
let instruction_words: InstructionData = env::read();
|
||||
let authorized_fingerprints: Vec<FingerPrint> = env::read();
|
||||
let instruction = T::deserialize(&mut Deserializer::new(instruction_words.as_ref())).unwrap();
|
||||
ProgramInput {
|
||||
pre_states,
|
||||
|
||||
@ -72,14 +72,12 @@ fn execute_and_prove_program(
|
||||
program: &Program,
|
||||
pre_states: &[AccountWithMetadata],
|
||||
instruction_data: &InstructionData,
|
||||
authorized_fingerprints: &[FingerPrint],
|
||||
) -> Result<Receipt, NssaError> {
|
||||
// Write inputs to the program
|
||||
let mut env_builder = ExecutorEnv::builder();
|
||||
Program::write_inputs(
|
||||
pre_states,
|
||||
instruction_data,
|
||||
authorized_fingerprints,
|
||||
&mut env_builder,
|
||||
)?;
|
||||
let env = env_builder.build().unwrap();
|
||||
@ -118,11 +116,13 @@ mod tests {
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
fingerprint: [0; 32],
|
||||
};
|
||||
|
||||
let recipient = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
fingerprint: [1; 32],
|
||||
};
|
||||
|
||||
@ -187,6 +187,7 @@ mod tests {
|
||||
nonce: 0xdeadbeef,
|
||||
..Account::default()
|
||||
},
|
||||
is_authorized: true,
|
||||
fingerprint: [0; 32],
|
||||
};
|
||||
let sender_keys = test_private_account_keys_1();
|
||||
@ -195,6 +196,7 @@ mod tests {
|
||||
|
||||
let recipient = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
fingerprint: [1; 32],
|
||||
};
|
||||
let balance_to_move: u128 = 37;
|
||||
|
||||
@ -92,6 +92,7 @@ impl PrivacyPreservingTransaction {
|
||||
.iter()
|
||||
.map(|address| AccountWithMetadata {
|
||||
account: state.get_account_by_address(address),
|
||||
is_authorized: signer_addresses.contains(address),
|
||||
fingerprint: *address.value(),
|
||||
})
|
||||
.collect();
|
||||
|
||||
@ -33,11 +33,10 @@ impl Program {
|
||||
&self,
|
||||
pre_states: &[AccountWithMetadata],
|
||||
instruction_data: &InstructionData,
|
||||
authorized_fingerprints: &[FingerPrint]
|
||||
) -> Result<Vec<Account>, NssaError> {
|
||||
// Write inputs to the program
|
||||
let mut env_builder = ExecutorEnv::builder();
|
||||
Self::write_inputs(pre_states, instruction_data, authorized_fingerprints, &mut env_builder)?;
|
||||
Self::write_inputs(pre_states, instruction_data, &mut env_builder)?;
|
||||
let env = env_builder.build().unwrap();
|
||||
|
||||
// Execute the program (without proving)
|
||||
@ -59,13 +58,11 @@ impl Program {
|
||||
pub(crate) fn write_inputs(
|
||||
pre_states: &[AccountWithMetadata],
|
||||
instruction_data: &[u32],
|
||||
authorized_fingerprints: &[FingerPrint],
|
||||
env_builder: &mut ExecutorEnvBuilder,
|
||||
) -> Result<(), NssaError> {
|
||||
let pre_states = pre_states.to_vec();
|
||||
let authorized_fingerprints = authorized_fingerprints.to_vec();
|
||||
env_builder
|
||||
.write(&(pre_states, instruction_data, authorized_fingerprints))
|
||||
.write(&(pre_states, instruction_data))
|
||||
.map_err(|e| NssaError::ProgramWriteInputFailed(e.to_string()))?;
|
||||
Ok(())
|
||||
}
|
||||
@ -176,11 +173,13 @@ mod tests {
|
||||
balance: 77665544332211,
|
||||
..Account::default()
|
||||
},
|
||||
fingerprint: [0; 32]
|
||||
is_authorized: true,
|
||||
fingerprint: [0; 32],
|
||||
};
|
||||
let recipient = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
fingerprint: [1; 32]
|
||||
is_authorized: false,
|
||||
fingerprint: [1; 32],
|
||||
};
|
||||
|
||||
let expected_sender_post = Account {
|
||||
@ -192,7 +191,7 @@ mod tests {
|
||||
..Account::default()
|
||||
};
|
||||
let [sender_post, recipient_post] = program
|
||||
.execute(&[sender, recipient], &instruction_data, &[])
|
||||
.execute(&[sender, recipient], &instruction_data)
|
||||
.unwrap()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
|
||||
@ -93,6 +93,7 @@ impl PublicTransaction {
|
||||
.iter()
|
||||
.map(|address| AccountWithMetadata {
|
||||
account: state.get_account_by_address(address),
|
||||
is_authorized: signer_addresses.contains(address),
|
||||
fingerprint: *address.value()
|
||||
})
|
||||
.collect();
|
||||
|
||||
@ -778,6 +778,7 @@ pub mod tests {
|
||||
) -> PrivacyPreservingTransaction {
|
||||
let sender = AccountWithMetadata {
|
||||
account: state.get_account_by_address(&sender_keys.address()),
|
||||
is_authorized: true,
|
||||
fingerprint: *sender_keys.address().value(),
|
||||
};
|
||||
|
||||
@ -785,6 +786,7 @@ pub mod tests {
|
||||
|
||||
let recipient = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
fingerprint: recipient_keys.npk().to_byte_array(),
|
||||
};
|
||||
|
||||
@ -827,10 +829,12 @@ pub mod tests {
|
||||
let sender_commitment = Commitment::new(&sender_keys.npk(), sender_private_account);
|
||||
let sender_pre = AccountWithMetadata {
|
||||
account: sender_private_account.clone(),
|
||||
is_authorized: true,
|
||||
fingerprint: sender_keys.npk().to_byte_array(),
|
||||
};
|
||||
let recipient_pre = AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: false,
|
||||
fingerprint: recipient_keys.npk().to_byte_array(),
|
||||
};
|
||||
|
||||
@ -887,10 +891,12 @@ pub mod tests {
|
||||
let sender_commitment = Commitment::new(&sender_keys.npk(), sender_private_account);
|
||||
let sender_pre = AccountWithMetadata {
|
||||
account: sender_private_account.clone(),
|
||||
is_authorized: true,
|
||||
fingerprint: sender_keys.npk().to_byte_array(),
|
||||
};
|
||||
let recipient_pre = AccountWithMetadata {
|
||||
account: state.get_account_by_address(recipient_address),
|
||||
is_authorized: false,
|
||||
fingerprint: *recipient_address.value(),
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user