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