pub mod header_leaf;
pub use header_leaf::*;
pub mod transaction_leaf;
pub use transaction_leaf::*;
pub mod transition_leaf;
pub use transition_leaf::*;
mod verify;
use circuit::{
collections::merkle_tree::MerklePath,
network::Aleo,
types::{environment::prelude::*, Boolean, Field},
};
const BLOCKS_DEPTH: u8 = 32;
const HEADER_DEPTH: u8 = 3;
const TRANSACTIONS_DEPTH: u8 = 16;
const TRANSACTION_DEPTH: u8 = 4;
const TRANSITION_DEPTH: u8 = 4;
type BlockPath<A> = MerklePath<A, BLOCKS_DEPTH>;
type HeaderPath<A> = MerklePath<A, HEADER_DEPTH>;
type TransactionsPath<A> = MerklePath<A, TRANSACTIONS_DEPTH>;
type TransactionPath<A> = MerklePath<A, TRANSACTION_DEPTH>;
type TransitionPath<A> = MerklePath<A, TRANSITION_DEPTH>;
pub struct StatePath<A: Aleo> {
state_root: Field<A>,
block_path: BlockPath<A>,
block_hash: Field<A>,
previous_block_hash: Field<A>,
header_root: Field<A>,
header_path: HeaderPath<A>,
header_leaf: HeaderLeaf<A>,
transactions_path: TransactionsPath<A>,
transaction_id: Field<A>,
transaction_path: TransactionPath<A>,
transaction_leaf: TransactionLeaf<A>,
transition_path: TransitionPath<A>,
transition_leaf: TransitionLeaf<A>,
}
impl<A: Aleo> Inject for StatePath<A> {
type Primitive = crate::ledger::state_path::StatePath<A::Network>;
fn new(mode: Mode, state_path: Self::Primitive) -> Self {
Self {
state_root: Field::new(mode, *state_path.state_root()),
block_path: BlockPath::new(mode, state_path.block_path().clone()),
block_hash: Field::new(mode, *state_path.block_hash()),
previous_block_hash: Field::new(mode, *state_path.previous_block_hash()),
header_root: Field::new(mode, *state_path.header_root()),
header_path: HeaderPath::new(mode, state_path.header_path().clone()),
header_leaf: HeaderLeaf::new(mode, state_path.header_leaf().clone()),
transactions_path: TransactionsPath::new(mode, state_path.transactions_path().clone()),
transaction_id: Field::new(mode, **state_path.transaction_id()),
transaction_path: TransactionPath::new(mode, state_path.transaction_path().clone()),
transaction_leaf: TransactionLeaf::new(mode, state_path.transaction_leaf().clone()),
transition_path: TransitionPath::new(mode, state_path.transition_path().clone()),
transition_leaf: TransitionLeaf::new(mode, state_path.transition_leaf().clone()),
}
}
}
impl<A: Aleo> Eject for StatePath<A> {
type Primitive = crate::ledger::state_path::StatePath<A::Network>;
fn eject_mode(&self) -> Mode {
(
&self.state_root,
&self.block_path,
&self.block_hash,
&self.previous_block_hash,
&self.header_root,
&self.header_path,
&self.header_leaf,
&self.transactions_path,
&self.transaction_id,
&self.transaction_path,
&self.transaction_leaf,
&self.transition_path,
&self.transition_leaf,
)
.eject_mode()
}
fn eject_value(&self) -> Self::Primitive {
match Self::Primitive::new(
self.state_root.eject_value().into(),
self.block_path.eject_value(),
self.block_hash.eject_value().into(),
self.previous_block_hash.eject_value().into(),
self.header_root.eject_value(),
self.header_path.eject_value(),
self.header_leaf.eject_value(),
self.transactions_path.eject_value(),
self.transaction_id.eject_value().into(),
self.transaction_path.eject_value(),
self.transaction_leaf.eject_value(),
self.transition_path.eject_value(),
self.transition_leaf.eject_value(),
) {
Ok(state_path) => state_path,
Err(error) => A::halt(format!("Failed to eject state path: {error}")),
}
}
}