mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-03-29 05:33:12 +00:00
clippy
This commit is contained in:
parent
6f380f1e74
commit
00f7324f8e
@ -103,7 +103,7 @@ mod tests {
|
|||||||
),
|
),
|
||||||
[0xab; 32],
|
[0xab; 32],
|
||||||
)],
|
)],
|
||||||
block_validity_window: (Some(1u64), None).try_into().unwrap(),
|
block_validity_window: (Some(1_u64), None).try_into().unwrap(),
|
||||||
timestamp_validity_window: TimestampValidityWindow::new_unbounded(),
|
timestamp_validity_window: TimestampValidityWindow::new_unbounded(),
|
||||||
};
|
};
|
||||||
let bytes = output.to_bytes();
|
let bytes = output.to_bytes();
|
||||||
|
|||||||
@ -3,10 +3,6 @@
|
|||||||
reason = "We prefer to group methods by functionality rather than by type for encoding"
|
reason = "We prefer to group methods by functionality rather than by type for encoding"
|
||||||
)]
|
)]
|
||||||
|
|
||||||
pub type BlockId = u64;
|
|
||||||
/// Unix timestamp in milliseconds.
|
|
||||||
pub type Timestamp = u64;
|
|
||||||
|
|
||||||
pub use circuit_io::{PrivacyPreservingCircuitInput, PrivacyPreservingCircuitOutput};
|
pub use circuit_io::{PrivacyPreservingCircuitInput, PrivacyPreservingCircuitOutput};
|
||||||
pub use commitment::{
|
pub use commitment::{
|
||||||
Commitment, CommitmentSetDigest, DUMMY_COMMITMENT, DUMMY_COMMITMENT_HASH, MembershipProof,
|
Commitment, CommitmentSetDigest, DUMMY_COMMITMENT, DUMMY_COMMITMENT_HASH, MembershipProof,
|
||||||
@ -25,3 +21,7 @@ pub mod program;
|
|||||||
|
|
||||||
#[cfg(feature = "host")]
|
#[cfg(feature = "host")]
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
|
||||||
|
pub type BlockId = u64;
|
||||||
|
/// Unix timestamp in milliseconds.
|
||||||
|
pub type Timestamp = u64;
|
||||||
|
|||||||
@ -5,7 +5,10 @@ use borsh::{BorshDeserialize, BorshSerialize};
|
|||||||
use risc0_zkvm::{DeserializeOwned, guest::env, serde::Deserializer};
|
use risc0_zkvm::{DeserializeOwned, guest::env, serde::Deserializer};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::account::{Account, AccountId, AccountWithMetadata};
|
use crate::{
|
||||||
|
BlockId, Timestamp,
|
||||||
|
account::{Account, AccountId, AccountWithMetadata},
|
||||||
|
};
|
||||||
|
|
||||||
pub const DEFAULT_PROGRAM_ID: ProgramId = [0; 8];
|
pub const DEFAULT_PROGRAM_ID: ProgramId = [0; 8];
|
||||||
pub const MAX_NUMBER_CHAINED_CALLS: usize = 10;
|
pub const MAX_NUMBER_CHAINED_CALLS: usize = 10;
|
||||||
@ -153,8 +156,6 @@ impl AccountPostState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::{BlockId, Timestamp};
|
|
||||||
|
|
||||||
pub type BlockValidityWindow = ValidityWindow<BlockId>;
|
pub type BlockValidityWindow = ValidityWindow<BlockId>;
|
||||||
pub type TimestampValidityWindow = ValidityWindow<Timestamp>;
|
pub type TimestampValidityWindow = ValidityWindow<Timestamp>;
|
||||||
|
|
||||||
@ -198,13 +199,13 @@ impl<T: Copy + PartialOrd> ValidityWindow<T> {
|
|||||||
|
|
||||||
/// Inclusive lower bound. `None` means no lower bound.
|
/// Inclusive lower bound. `None` means no lower bound.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn start(&self) -> Option<T> {
|
pub const fn start(&self) -> Option<T> {
|
||||||
self.from
|
self.from
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Exclusive upper bound. `None` means no upper bound.
|
/// Exclusive upper bound. `None` means no upper bound.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn end(&self) -> Option<T> {
|
pub const fn end(&self) -> Option<T> {
|
||||||
self.to
|
self.to
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,17 +5,14 @@ use std::{
|
|||||||
|
|
||||||
use borsh::{BorshDeserialize, BorshSerialize};
|
use borsh::{BorshDeserialize, BorshSerialize};
|
||||||
use nssa_core::{
|
use nssa_core::{
|
||||||
BlockId, Commitment, CommitmentSetDigest, Nullifier, PrivacyPreservingCircuitOutput, Timestamp,
|
BlockId, PrivacyPreservingCircuitOutput, Timestamp,
|
||||||
account::{Account, AccountWithMetadata},
|
account::{Account, AccountWithMetadata},
|
||||||
program::{BlockValidityWindow, TimestampValidityWindow},
|
|
||||||
};
|
};
|
||||||
use sha2::{Digest as _, digest::FixedOutput as _};
|
use sha2::{Digest as _, digest::FixedOutput as _};
|
||||||
|
|
||||||
use super::{message::Message, witness_set::WitnessSet};
|
use super::{message::Message, witness_set::WitnessSet};
|
||||||
use crate::{
|
use crate::{
|
||||||
AccountId, V03State,
|
AccountId, V03State, error::NssaError, privacy_preserving_transaction::circuit::Proof,
|
||||||
error::NssaError,
|
|
||||||
privacy_preserving_transaction::{circuit::Proof, message::EncryptedAccountData},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
|
||||||
@ -118,12 +115,7 @@ impl PrivacyPreservingTransaction {
|
|||||||
check_privacy_preserving_circuit_proof_is_valid(
|
check_privacy_preserving_circuit_proof_is_valid(
|
||||||
&witness_set.proof,
|
&witness_set.proof,
|
||||||
&public_pre_states,
|
&public_pre_states,
|
||||||
&message.public_post_states,
|
message,
|
||||||
&message.encrypted_private_post_states,
|
|
||||||
&message.new_commitments,
|
|
||||||
&message.new_nullifiers,
|
|
||||||
&message.block_validity_window,
|
|
||||||
&message.timestamp_validity_window,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// 5. Commitment freshness
|
// 5. Commitment freshness
|
||||||
@ -181,25 +173,21 @@ impl PrivacyPreservingTransaction {
|
|||||||
fn check_privacy_preserving_circuit_proof_is_valid(
|
fn check_privacy_preserving_circuit_proof_is_valid(
|
||||||
proof: &Proof,
|
proof: &Proof,
|
||||||
public_pre_states: &[AccountWithMetadata],
|
public_pre_states: &[AccountWithMetadata],
|
||||||
public_post_states: &[Account],
|
message: &Message,
|
||||||
encrypted_private_post_states: &[EncryptedAccountData],
|
|
||||||
new_commitments: &[Commitment],
|
|
||||||
new_nullifiers: &[(Nullifier, CommitmentSetDigest)],
|
|
||||||
block_validity_window: &BlockValidityWindow,
|
|
||||||
timestamp_validity_window: &TimestampValidityWindow,
|
|
||||||
) -> Result<(), NssaError> {
|
) -> Result<(), NssaError> {
|
||||||
let output = PrivacyPreservingCircuitOutput {
|
let output = PrivacyPreservingCircuitOutput {
|
||||||
public_pre_states: public_pre_states.to_vec(),
|
public_pre_states: public_pre_states.to_vec(),
|
||||||
public_post_states: public_post_states.to_vec(),
|
public_post_states: message.public_post_states.clone(),
|
||||||
ciphertexts: encrypted_private_post_states
|
ciphertexts: message
|
||||||
|
.encrypted_private_post_states
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.map(|value| value.ciphertext)
|
.map(|value| value.ciphertext)
|
||||||
.collect(),
|
.collect(),
|
||||||
new_commitments: new_commitments.to_vec(),
|
new_commitments: message.new_commitments.clone(),
|
||||||
new_nullifiers: new_nullifiers.to_vec(),
|
new_nullifiers: message.new_nullifiers.clone(),
|
||||||
block_validity_window: block_validity_window.to_owned(),
|
block_validity_window: message.block_validity_window,
|
||||||
timestamp_validity_window: timestamp_validity_window.to_owned(),
|
timestamp_validity_window: message.timestamp_validity_window,
|
||||||
};
|
};
|
||||||
proof
|
proof
|
||||||
.is_valid_for(&output)
|
.is_valid_for(&output)
|
||||||
|
|||||||
@ -524,7 +524,7 @@ mod tests {
|
|||||||
let tx = tx.transaction_stateless_check().unwrap();
|
let tx = tx.transaction_stateless_check().unwrap();
|
||||||
|
|
||||||
// Signature is not from sender. Execution fails
|
// Signature is not from sender. Execution fails
|
||||||
let result = sequencer.execute_check_transaction_on_state(tx);
|
let result = sequencer.execute_check_transaction_on_state(tx, 0, 0);
|
||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
result,
|
result,
|
||||||
@ -550,7 +550,7 @@ mod tests {
|
|||||||
// Passed pre-check
|
// Passed pre-check
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
|
||||||
let result = sequencer.execute_check_transaction_on_state(result.unwrap());
|
let result = sequencer.execute_check_transaction_on_state(result.unwrap(), 0, 0);
|
||||||
let is_failed_at_balance_mismatch = matches!(
|
let is_failed_at_balance_mismatch = matches!(
|
||||||
result.err().unwrap(),
|
result.err().unwrap(),
|
||||||
nssa::error::NssaError::ProgramExecutionFailed(_)
|
nssa::error::NssaError::ProgramExecutionFailed(_)
|
||||||
@ -572,7 +572,9 @@ mod tests {
|
|||||||
acc1, 0, acc2, 100, &sign_key1,
|
acc1, 0, acc2, 100, &sign_key1,
|
||||||
);
|
);
|
||||||
|
|
||||||
sequencer.execute_check_transaction_on_state(tx).unwrap();
|
sequencer
|
||||||
|
.execute_check_transaction_on_state(tx, 0, 0)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let bal_from = sequencer.state.get_account_by_id(acc1).balance;
|
let bal_from = sequencer.state.get_account_by_id(acc1).balance;
|
||||||
let bal_to = sequencer.state.get_account_by_id(acc2).balance;
|
let bal_to = sequencer.state.get_account_by_id(acc2).balance;
|
||||||
|
|||||||
@ -9,7 +9,7 @@ use risc0_zkvm::serde::to_vec;
|
|||||||
///
|
///
|
||||||
/// Instruction: (`window`, `chained_program_id`, `chained_window`)
|
/// Instruction: (`window`, `chained_program_id`, `chained_window`)
|
||||||
/// The initial output uses `window` and chains to `chained_program_id` with `chained_window`.
|
/// The initial output uses `window` and chains to `chained_program_id` with `chained_window`.
|
||||||
/// The chained program (validity_window) expects `(BlockValidityWindow, TimestampValidityWindow)`
|
/// The chained program (`validity_window`) expects `(BlockValidityWindow, TimestampValidityWindow)`
|
||||||
/// so an unbounded timestamp window is appended automatically.
|
/// so an unbounded timestamp window is appended automatically.
|
||||||
type Instruction = (BlockValidityWindow, ProgramId, BlockValidityWindow);
|
type Instruction = (BlockValidityWindow, ProgramId, BlockValidityWindow);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user