Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- Added `MockChainBuilder::validator_signing_keys` in `miden-testing` to supply validator keys for genesis and subsequent block signing. The default remains three randomly generated validators.
- Added `LocalTransactionProver::with_execution_options` to configure the `ExecutionOptions` used while proving ([#3860](https://github.com/0xMiden/protocol/pull/3860)).
- Added `BlockExecutor::with_execution_options` and `BatchExecutor::with_execution_options` to configure the `ExecutionOptions` used while running the batch and block kernels ([#3862](https://github.com/0xMiden/protocol/pull/3862)).
- Added `CodeTree`, `PartialCodeTree`, `CodeWitness` and `ProcedureRoot` to prove presence or absence of procedure roots in the blockchain ([#4062](https://github.com/0xMiden/protocol/pull/4062)).
- Added `CodeTree`, `PartialCodeTree`, `CodeWitness` and `ProcedureRoot` to prove presence or absence of procedure roots in the blockchain ([#4062](https://github.com/0xMiden/protocol/pull/4062)), ([#4129](https://github.com/0xMiden/protocol/pull/4129)).
- Added `CodePatch` to describe the procedures a transaction creates and depends on ([#4101](https://github.com/0xMiden/protocol/pull/4101)).
- [BREAKING] Added `NonFungibleFaucet` to `StandardAccountComponent` and `AccountComponentInterface`, so `AccountInterface::from_account` recognizes NFT faucets instead of reporting their procedures as custom ([#4036](https://github.com/0xMiden/protocol/issues/4036)).
- [BREAKING] `set_external_uri` (exposed as `set_contract_uri` on NFT faucets) and `set_token_base_uri` now emit a transaction log carrying the new value, so readers know to refetch the metadata it points to ([#4117](https://github.com/0xMiden/protocol/issues/4117)).
Expand Down
13 changes: 7 additions & 6 deletions crates/miden-objects/proto/block.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ message BlockHeader {
primitives.Word chain_commitment = 5;
primitives.Word account_root = 6;
primitives.Word nullifier_root = 7;
primitives.Word note_root = 8;
primitives.Word tx_commitment = 9;
ValidatorConfig validator_config = 10;
FeeParameters fee_parameters = 11;
primitives.Word protocol_config_commitment = 12;
optional NextProtocolConfig next_protocol_config = 13;
primitives.Word code_tree_root = 8;
primitives.Word note_root = 9;
primitives.Word tx_commitment = 10;
ValidatorConfig validator_config = 11;
FeeParameters fee_parameters = 12;
primitives.Word protocol_config_commitment = 13;
optional NextProtocolConfig next_protocol_config = 14;
}

message BlockAccountUpdate {
Expand Down
1 change: 1 addition & 0 deletions crates/miden-objects/proto/mock_chain.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ message MockChainV1 {
repeated AccountAuthenticator account_authenticators = 8;
repeated account_file.AuthSecretKey validator_secret_keys = 9;
protocol_config.ProtocolConfig protocol_config = 10;
repeated primitives.Word code_tree_procedure_roots = 11;
}

message ProvenBlock {
Expand Down
1 change: 1 addition & 0 deletions crates/miden-objects/src/conversion/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl From<&BlockHeader> for proto::blockchain::BlockHeader {
chain_commitment: Some(header.chain_commitment().into()),
account_root: Some(header.account_root().into()),
nullifier_root: Some(header.nullifier_root().into()),
code_tree_root: Some(header.code_tree_root().as_word().into()),
note_root: Some(header.note_root().into()),
tx_commitment: Some(header.transactions_commitment().into()),
validator_config: Some(header.validator_config().into()),
Expand Down
2 changes: 2 additions & 0 deletions crates/miden-objects/src/decoded/blockchain.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Domain construction for decoded blockchain messages.
use miden_protobuf::unwrap_infallible;
use miden_protocol::block::code_tree::CodeTreeRoot;

use crate::decoded::VerificationError;
use crate::{Verify, proto};
Expand Down Expand Up @@ -68,6 +69,7 @@ impl crate::BuildUnchecked for BlockHeader {
self.chain_commitment,
self.account_root,
self.nullifier_root,
CodeTreeRoot::from_raw(self.code_tree_root),
self.note_root,
self.tx_commitment,
self.validator_config.verify()?,
Expand Down
1 change: 1 addition & 0 deletions crates/miden-objects/src/decoded/blockchain/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub(crate) fn block_header_with_scheduled_upgrade() -> BlockHeader {
header.chain_commitment(),
header.account_root(),
header.nullifier_root(),
header.code_tree_root(),
header.note_root(),
header.transactions_commitment(),
validator_config,
Expand Down
2 changes: 2 additions & 0 deletions crates/miden-objects/src/decoded/blockchain/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use core::error::Error;

use assert_matches::assert_matches;
use miden_protocol::Word;
use miden_protocol::block::code_tree::CodeTreeRoot;
use miden_protocol::block::{BlockBody, BlockNumber};
use miden_protocol::errors::{ProtocolConfigError, ValidatorConfigError};

Expand Down Expand Up @@ -56,6 +57,7 @@ fn signed_blocks_require_a_trusted_parent_for_authentication() {
Word::empty(),
Word::empty(),
Word::empty(),
CodeTreeRoot::from_raw(Word::empty()),
body.compute_block_note_tree().root(),
body.compute_transactions_commitment(),
keys,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ fn dummy_block_header(
base.chain_commitment(),
base.account_root(),
base.nullifier_root(),
base.code_tree_root(),
base.note_root(),
base.transactions_commitment(),
base.validator_config().clone(),
Expand Down
36 changes: 25 additions & 11 deletions crates/miden-protocol/asm/kernels/transaction-core/src/memory.masm
Original file line number Diff line number Diff line change
Expand Up @@ -195,38 +195,41 @@ const BLOCK_METADATA_NUMBER_PTR = BLOCK_METADATA_PTR + 1
const BLOCK_METADATA_TIMESTAMP_PTR = BLOCK_METADATA_PTR + 2

# The memory address at which the previous block commitment is stored
const PREV_BLOCK_COMMITMENT_PTR = 2004
const PREV_BLOCK_COMMITMENT_PTR = BLOCK_METADATA_PTR + WORD_NUM_ELEMENTS

# The memory address at which the chain commitment is stored
const CHAIN_COMMITMENT_PTR = 2008
const CHAIN_COMMITMENT_PTR = PREV_BLOCK_COMMITMENT_PTR + WORD_NUM_ELEMENTS

# The memory address at which the account root is stored
const ACCT_DB_ROOT_PTR = 2012
const ACCT_DB_ROOT_PTR = CHAIN_COMMITMENT_PTR + WORD_NUM_ELEMENTS

# The memory address at which the nullifier root is stored
const NULLIFIER_ROOT_PTR = 2016
const NULLIFIER_ROOT_PTR = ACCT_DB_ROOT_PTR + WORD_NUM_ELEMENTS

# The memory address at which the code tree root is stored
const CODE_TREE_ROOT_PTR = NULLIFIER_ROOT_PTR + WORD_NUM_ELEMENTS

# The memory address at which the tx commitment is stored
const TX_COMMITMENT_PTR = 2020
const TX_COMMITMENT_PTR = CODE_TREE_ROOT_PTR + WORD_NUM_ELEMENTS

# The memory address at which the protocol config commitment is stored
const PROTOCOL_CONFIG_COMMITMENT_PTR = 2024
const PROTOCOL_CONFIG_COMMITMENT_PTR = TX_COMMITMENT_PTR + WORD_NUM_ELEMENTS

# The memory address at which the validator config commitment is stored
const VALIDATOR_CONFIG_COMMITMENT_PTR = 2028
const VALIDATOR_CONFIG_COMMITMENT_PTR = PROTOCOL_CONFIG_COMMITMENT_PTR + WORD_NUM_ELEMENTS

# The memory address at which the next protocol config commitment is stored
const NEXT_PROTOCOL_CONFIG_COMMITMENT_PTR = 2032
const NEXT_PROTOCOL_CONFIG_COMMITMENT_PTR = VALIDATOR_CONFIG_COMMITMENT_PTR + WORD_NUM_ELEMENTS

# The memory address at which the fee parameters are stored.
# [verification_base_fee, 0, 0, 0]
const FEE_PARAMETERS_PTR = 2036
const FEE_PARAMETERS_PTR = NEXT_PROTOCOL_CONFIG_COMMITMENT_PTR + WORD_NUM_ELEMENTS

# The memory address at which the verification base fee is stored.
const VERIFICATION_BASE_FEE_PTR = FEE_PARAMETERS_PTR

# The memory address at which the note root is stored
const NOTE_ROOT_PTR = 2040
# The memory address at which the note root is stored (offset by padding).
const NOTE_ROOT_PTR = FEE_PARAMETERS_PTR + 2 * WORD_NUM_ELEMENTS

# PROTOCOL CONFIG
# -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -900,6 +903,17 @@ pub proc get_nullifier_db_root() -> Commitment
padw mem_loadw_le.NULLIFIER_ROOT_PTR
end

#! Returns the code tree root of the transaction reference block.
#!
#! Inputs: []
#! Outputs: [CODE_TREE_ROOT]
#!
#! Where:
#! - CODE_TREE_ROOT is the code tree root of the transaction reference block.
pub proc get_code_tree_root() -> Commitment
padw mem_loadw_le.CODE_TREE_ROOT_PTR
end

#! Returns the tx commitment of the transaction reference block.
#!
#! Inputs: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,13 @@ end
#! PARTIAL_BLOCKCHAIN_COMMITMENT,
#! ACCOUNT_ROOT,
#! NULLIFIER_ROOT,
#! CODE_TREE_ROOT,
#! TX_COMMITMENT,
#! PROTOCOL_CONFIG_COMMITMENT,
#! VALIDATOR_CONFIG_COMMITMENT,
#! NEXT_PROTOCOL_CONFIG_COMMITMENT,
#! [verification_base_fee, 0, 0, 0],
#! EMPTY_WORD,
#! NOTE_ROOT,
#! ]
#! Outputs:
Expand All @@ -292,12 +294,14 @@ end
#! - ACCOUNT_ROOT is the root of the tree with latest account states for all accounts.
#! - NULLIFIER_ROOT is the root of the tree with nullifiers of all notes that have ever been
#! consumed.
#! - CODE_TREE_ROOT is the root of the tree with all registered procedure roots.
#! - TX_COMMITMENT is a commitment to the set of transaction IDs which affected accounts in the block.
#! - PROTOCOL_CONFIG_COMMITMENT is the commitment to the protocol config.
#! - VALIDATOR_CONFIG_COMMITMENT is the commitment to the validator config.
#! - NEXT_PROTOCOL_CONFIG_COMMITMENT is the the commitment to the next protocol config.
#! - verification_base_fee is the base fee capturing the cost for the verification of a
#! transaction.
#! - EMPTY_WORD pads the sub commitment preimage to a multiple of the hasher rate.
#! - NOTE_ROOT is the root of the tree with all notes created in the block.
proc process_block_data(block_num: BlockNumber)
push.BLOCK_METADATA_PTR
Expand All @@ -311,6 +315,7 @@ proc process_block_data(block_num: BlockNumber)
adv_pipe exec.poseidon2::permute
adv_pipe exec.poseidon2::permute
adv_pipe exec.poseidon2::permute
adv_pipe exec.poseidon2::permute
exec.poseidon2::squeeze_digest
# => [SUB_COMMITMENT, block_data_ptr', block_num]

Expand Down
9 changes: 6 additions & 3 deletions crates/miden-protocol/src/block/code_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub use partial::PartialCodeTree;
mod patch;
pub use patch::{CodePatch, CodePatchCommitment};

mod root;
pub use root::CodeTreeRoot;

/// The value of a procedure root that is present in the code tree.
///
/// Absent procedure roots have the [`EMPTY_WORD`] as their value.
Expand Down Expand Up @@ -95,8 +98,8 @@ where
// --------------------------------------------------------------------------------------------

/// Returns the root of the code SMT.
pub fn root(&self) -> Word {
self.smt.root()
pub fn root(&self) -> CodeTreeRoot {
CodeTreeRoot::from_raw(self.smt.root())
}

/// Returns the number of procedure roots in this tree.
Expand Down Expand Up @@ -358,7 +361,7 @@ mod tests {
let witness = tree.open(&root);
assert_eq!(witness.proof().get(&root.as_word()), Some(PRESENT_VALUE));
assert_eq!(witness.proof().leaf().num_entries(), 2);
assert_eq!(witness.proof().compute_root(), tree.root());
assert_eq!(witness.proof().compute_root(), tree.root().as_word());
}

Ok(())
Expand Down
11 changes: 5 additions & 6 deletions crates/miden-protocol/src/block/code_tree/partial.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::{CodeWitness, PRESENT_VALUE};
use crate::Word;
use super::{CodeTreeRoot, CodeWitness, PRESENT_VALUE};
use crate::code::ProcedureRoot;
use crate::crypto::merkle::smt::PartialSmt;
use crate::errors::CodeTreeError;
Expand All @@ -17,8 +16,8 @@ pub struct PartialCodeTree(PartialSmt);
impl PartialCodeTree {
/// Creates a new partial code tree with the provided root that does not track any procedure
/// roots.
pub fn new(root: Word) -> Self {
PartialCodeTree(PartialSmt::new(root))
pub fn new(root: CodeTreeRoot) -> Self {
PartialCodeTree(PartialSmt::new(root.as_word()))
}

/// Returns a new [`PartialCodeTree`] instantiated with the provided witnesses.
Expand All @@ -36,8 +35,8 @@ impl PartialCodeTree {
}

/// Returns the root of the tree.
pub fn root(&self) -> Word {
self.0.root()
pub fn root(&self) -> CodeTreeRoot {
CodeTreeRoot::from_raw(self.0.root())
}

/// Returns `true` if the procedure root is present in the tree, `false` otherwise.
Expand Down
24 changes: 24 additions & 0 deletions crates/miden-protocol/src/block/code_tree/root.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use core::fmt::Display;

use miden_crypto_derive::WordWrapper;

use crate::Word;

// CODE TREE ROOT
// ================================================================================================

/// The root of the [`CodeTree`](super::CodeTree).
#[derive(Debug, Clone, Copy, PartialEq, Eq, WordWrapper)]
pub struct CodeTreeRoot(Word);

impl Display for CodeTreeRoot {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_word())
}
}

impl From<CodeTreeRoot> for Word {
fn from(root: CodeTreeRoot) -> Self {
root.as_word()
}
}
Loading
Loading