Skip to content

Commit

Permalink
Merge branch 'next' into polydez-onchain-accounts
Browse files Browse the repository at this point in the history
# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	block-producer/src/block.rs
#	block-producer/src/block_builder/mod.rs
#	block-producer/src/test_utils/block.rs
#	block-producer/src/test_utils/proven_tx.rs
#	faucet/Cargo.toml
#	proto/src/errors.rs
#	store/src/state.rs
  • Loading branch information
polydez committed Apr 5, 2024
2 parents fcdc331 + 1cbe5a8 commit 6eafe6e
Show file tree
Hide file tree
Showing 25 changed files with 405 additions and 203 deletions.
298 changes: 231 additions & 67 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ repository = "https://github.com/0xPolygonMiden/miden-node"
exclude = [".github/"]

[workspace.dependencies]
miden-air = { version = "0.8", default-features = false }
miden-air = { version = "0.9", default-features = false }
miden-lib = { git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next" }
miden-objects = { git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next" }
miden-processor = { version = "0.8" }
miden-stdlib = { version = "0.8", default-features = false }
miden-processor = { version = "0.9" }
miden-stdlib = { version = "0.9", default-features = false }
miden-tx = { git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next" }
thiserror = { version = "1.0" }
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3", features = [
"fmt",
"json",
"env-filter",
"fmt",
"json",
"env-filter",
] }
18 changes: 8 additions & 10 deletions block-producer/src/batch_builder/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ use std::collections::BTreeMap;
use miden_node_proto::domain::accounts::UpdatedAccount;
use miden_objects::{
accounts::AccountId,
crypto::{
hash::blake::{Blake3Digest, Blake3_256},
merkle::SimpleSmt,
},
batches::BatchNoteTree,
crypto::hash::blake::{Blake3Digest, Blake3_256},
notes::{NoteEnvelope, Nullifier},
Digest, BATCH_OUTPUT_NOTES_TREE_DEPTH, MAX_NOTES_PER_BATCH,
Digest, MAX_NOTES_PER_BATCH,
};
use tracing::instrument;

Expand All @@ -28,7 +26,7 @@ pub struct TransactionBatch {
id: BatchId,
updated_accounts: BTreeMap<AccountId, AccountStates>,
produced_nullifiers: Vec<Nullifier>,
created_notes_smt: SimpleSmt<BATCH_OUTPUT_NOTES_TREE_DEPTH>,
created_notes_smt: BatchNoteTree,
/// The notes stored `created_notes_smt`
created_notes: Vec<NoteEnvelope>,
}
Expand Down Expand Up @@ -75,10 +73,10 @@ impl TransactionBatch {
// TODO: document under what circumstances SMT creating can fail
(
created_notes.clone(),
SimpleSmt::<BATCH_OUTPUT_NOTES_TREE_DEPTH>::with_contiguous_leaves(
created_notes.into_iter().flat_map(|note_envelope| {
[note_envelope.note_id().into(), note_envelope.metadata().into()]
}),
BatchNoteTree::with_contiguous_leaves(
created_notes
.iter()
.map(|note_envelope| (note_envelope.note_id(), note_envelope.metadata())),
)
.map_err(|e| BuildBatchError::NotesSmtError(e, txs))?,
)
Expand Down
2 changes: 1 addition & 1 deletion block-producer/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::store::BlockInputsError;
pub struct Block {
pub header: BlockHeader,
pub updated_accounts: Vec<UpdatedAccount>,
pub created_notes: BTreeMap<u64, NoteEnvelope>,
pub created_notes: Vec<(usize, usize, NoteEnvelope)>,
pub produced_nullifiers: Vec<Nullifier>,
// TODO:
// - full states for updated public accounts
Expand Down
10 changes: 5 additions & 5 deletions block-producer/src/block_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use async_trait::async_trait;
use miden_node_utils::formatting::{format_array, format_blake3_digest};
use miden_objects::{notes::Nullifier, MAX_NOTES_PER_BATCH};
use miden_objects::notes::Nullifier;
use tracing::{debug, info, instrument};

use crate::{
Expand Down Expand Up @@ -83,10 +83,10 @@ where
.iter()
.enumerate()
.flat_map(|(batch_idx, batch)| {
batch.created_notes().enumerate().map(move |(note_idx_in_batch, note)| {
let note_idx_in_block = batch_idx * MAX_NOTES_PER_BATCH + note_idx_in_batch;
(note_idx_in_block as u64, *note)
})
batch
.created_notes()
.enumerate()
.map(move |(note_idx_in_batch, note)| (batch_idx, note_idx_in_batch, *note))
})
.collect();
let produced_nullifiers: Vec<Nullifier> =
Expand Down
4 changes: 3 additions & 1 deletion block-producer/src/block_builder/prover/block_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ impl BlockWitness {
.expect("updated accounts number is greater than or equal to the field modulus"),
);

StackInputs::new(stack_inputs)
// TODO: We need provide produced nullifier different way, because such big stack inputs
// will cause problem in recursive proofs
StackInputs::new(stack_inputs).expect("Stack inputs count extends max limit")
}

/// Builds the advice inputs to the block kernel
Expand Down
18 changes: 9 additions & 9 deletions block-producer/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use thiserror::Error;
// Transaction verification errors
// =================================================================================================

#[derive(Error, Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq, Error)]
pub enum VerifyTxError {
/// The account that the transaction modifies has already been modified and isn't yet committed
/// to a block
Expand Down Expand Up @@ -49,7 +49,7 @@ pub enum VerifyTxError {
// Transaction adding errors
// =================================================================================================

#[derive(Error, Debug)]
#[derive(Debug, PartialEq, Eq, Error)]
pub enum AddTransactionError {
#[error("Transaction verification failed: {0}")]
VerificationFailed(#[from] VerifyTxError),
Expand All @@ -63,7 +63,7 @@ pub enum AddTransactionError {
/// These errors are returned from the batch builder to the transaction queue, instead of
/// dropping the transactions, they are included into the error values, so that the transaction
/// queue can re-queue them.
#[derive(Error, Debug)]
#[derive(Debug, PartialEq, Eq, Error)]
pub enum BuildBatchError {
#[error("Too many notes in the batch. Got: {0}, max: {}", MAX_NOTES_PER_BATCH)]
TooManyNotesCreated(usize, Vec<ProvenTransaction>),
Expand All @@ -84,21 +84,21 @@ impl BuildBatchError {
// Block prover errors
// =================================================================================================

#[derive(Error, Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq, Error)]
pub enum BlockProverError {
#[error("Received invalid merkle path")]
InvalidMerklePaths(MerkleError),
#[error("program execution failed")]
#[error("Program execution failed")]
ProgramExecutionFailed(ExecutionError),
#[error("failed to retrieve {0} root from stack outputs")]
#[error("Failed to retrieve {0} root from stack outputs")]
InvalidRootOutput(&'static str),
}

// Block inputs errors
// =================================================================================================

#[allow(clippy::enum_variant_names)]
#[derive(Debug, PartialEq, Error)]
#[derive(Debug, PartialEq, Eq, Error)]
pub enum BlockInputsError {
#[error("failed to parse protobuf message: {0}")]
ConversionError(#[from] ConversionError),
Expand All @@ -120,7 +120,7 @@ pub enum ApplyBlockError {
// Block building errors
// =================================================================================================

#[derive(Debug, Error, PartialEq)]
#[derive(Debug, PartialEq, Eq, Error)]
pub enum BuildBlockError {
#[error("failed to compute new block: {0}")]
BlockProverFailed(#[from] BlockProverError),
Expand All @@ -144,7 +144,7 @@ pub enum BuildBlockError {
// Transaction inputs errors
// =================================================================================================

#[derive(Debug, PartialEq, Error)]
#[derive(Debug, PartialEq, Eq, Error)]
pub enum TxInputsError {
#[error("gRPC client failed with error: {0}")]
GrpcClientError(String),
Expand Down
39 changes: 16 additions & 23 deletions block-producer/src/test_utils/block.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::collections::BTreeMap;

use miden_node_proto::domain::accounts::UpdatedAccount;
use miden_objects::{
block::BlockNoteTree,
crypto::merkle::{Mmr, SimpleSmt},
notes::{NoteEnvelope, Nullifier},
BlockHeader, Digest, ACCOUNT_TREE_DEPTH, BLOCK_OUTPUT_NOTES_TREE_DEPTH, MAX_NOTES_PER_BATCH,
ONE, ZERO,
BlockHeader, Digest, ACCOUNT_TREE_DEPTH, ONE, ZERO,
};

use super::MockStoreSuccess;
Expand Down Expand Up @@ -92,7 +90,7 @@ pub struct MockBlockBuilder {
last_block_header: BlockHeader,

updated_accounts: Option<Vec<UpdatedAccount>>,
created_notes: Option<BTreeMap<u64, NoteEnvelope>>,
created_notes: Option<Vec<(usize, usize, NoteEnvelope)>>,
produced_nullifiers: Option<Vec<Nullifier>>,
}

Expand Down Expand Up @@ -125,7 +123,7 @@ impl MockBlockBuilder {

pub fn created_notes(
mut self,
created_notes: BTreeMap<u64, NoteEnvelope>,
created_notes: Vec<(usize, usize, NoteEnvelope)>,
) -> Self {
self.created_notes = Some(created_notes);

Expand All @@ -150,7 +148,7 @@ impl MockBlockBuilder {
self.store_chain_mmr.peaks(self.store_chain_mmr.forest()).unwrap().hash_peaks(),
self.store_accounts.root(),
Digest::default(),
note_created_smt_from_envelopes(created_notes.iter()).root(),
note_created_smt_from_envelopes(created_notes.iter().cloned()).root(),
Digest::default(),
Digest::default(),
ZERO,
Expand All @@ -166,28 +164,23 @@ impl MockBlockBuilder {
}
}

pub(crate) fn note_created_smt_from_envelopes<'a>(
note_iterator: impl Iterator<Item = (&'a u64, &'a NoteEnvelope)>
) -> SimpleSmt<BLOCK_OUTPUT_NOTES_TREE_DEPTH> {
SimpleSmt::<BLOCK_OUTPUT_NOTES_TREE_DEPTH>::with_leaves(note_iterator.flat_map(
|(note_idx_in_block, note)| {
let index = note_idx_in_block * 2;
[(index, note.note_id().into()), (index + 1, note.metadata().into())]
},
))
pub(crate) fn note_created_smt_from_envelopes(
note_iterator: impl Iterator<Item = (usize, usize, NoteEnvelope)>
) -> BlockNoteTree {
BlockNoteTree::with_entries(note_iterator.map(|(batch_idx, note_idx_in_batch, note)| {
(batch_idx, note_idx_in_batch, (note.note_id().into(), *note.metadata()))
}))
.unwrap()
}

pub(crate) fn note_created_smt_from_batches<'a>(
batches: impl Iterator<Item = &'a TransactionBatch>
) -> SimpleSmt<BLOCK_OUTPUT_NOTES_TREE_DEPTH> {
let note_leaf_iterator = batches.enumerate().flat_map(|(batch_index, batch)| {
let subtree_index = batch_index * MAX_NOTES_PER_BATCH * 2;
batch.created_notes().enumerate().flat_map(move |(note_index, note)| {
let index = (subtree_index + note_index * 2) as u64;
[(index, note.note_id().into()), (index + 1, note.metadata().into())]
) -> BlockNoteTree {
let note_leaf_iterator = batches.enumerate().flat_map(|(batch_idx, batch)| {
batch.created_notes().enumerate().map(move |(note_idx_in_batch, note)| {
(batch_idx, note_idx_in_batch, (note.note_id().into(), *note.metadata()))
})
});

SimpleSmt::<BLOCK_OUTPUT_NOTES_TREE_DEPTH>::with_leaves(note_leaf_iterator).unwrap()
BlockNoteTree::with_entries(note_leaf_iterator).unwrap()
}
4 changes: 2 additions & 2 deletions block-producer/src/test_utils/proven_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use miden_objects::{
notes::{NoteEnvelope, NoteMetadata, NoteType, Nullifier},
transaction::{ProvenTransaction, ProvenTransactionBuilder},
vm::ExecutionProof,
Digest, Felt, Hasher, ONE, ZERO,
Digest, Felt, Hasher, ONE,
};
use winterfell::StarkProof;

Expand Down Expand Up @@ -84,7 +84,7 @@ impl MockProvenTxBuilder {

NoteEnvelope::new(
note_hash.into(),
NoteMetadata::new(self.account_id, NoteType::OffChain, 0.into(), ZERO).unwrap(),
NoteMetadata::new(self.account_id, NoteType::OffChain, 0.into(), ONE).unwrap(),
)
})
.collect();
Expand Down
11 changes: 6 additions & 5 deletions block-producer/src/test_utils/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use std::collections::BTreeSet;

use async_trait::async_trait;
use miden_objects::{
block::BlockNoteTree,
crypto::merkle::{Mmr, SimpleSmt, Smt, ValuePath},
notes::{NoteEnvelope, Nullifier},
BlockHeader, ACCOUNT_TREE_DEPTH, BLOCK_OUTPUT_NOTES_TREE_DEPTH, EMPTY_WORD, ONE, ZERO,
BlockHeader, ACCOUNT_TREE_DEPTH, EMPTY_WORD, ONE, ZERO,
};

use super::*;
Expand All @@ -22,7 +23,7 @@ use crate::{
#[derive(Debug)]
pub struct MockStoreSuccessBuilder {
accounts: Option<SimpleSmt<ACCOUNT_TREE_DEPTH>>,
notes: Option<SimpleSmt<BLOCK_OUTPUT_NOTES_TREE_DEPTH>>,
notes: Option<BlockNoteTree>,
produced_nullifiers: Option<BTreeSet<Digest>>,
chain_mmr: Option<Mmr>,
block_num: Option<u32>,
Expand Down Expand Up @@ -68,9 +69,9 @@ impl MockStoreSuccessBuilder {
}
}

pub fn initial_notes<'a>(
pub fn initial_notes(
mut self,
notes: impl Iterator<Item = (&'a u64, &'a NoteEnvelope)>,
notes: impl Iterator<Item = (usize, usize, NoteEnvelope)>,
) -> Self {
self.notes = Some(note_created_smt_from_envelopes(notes));

Expand Down Expand Up @@ -107,7 +108,7 @@ impl MockStoreSuccessBuilder {
pub fn build(self) -> MockStoreSuccess {
let block_num = self.block_num.unwrap_or(1);
let accounts_smt = self.accounts.unwrap_or(SimpleSmt::new().unwrap());
let notes_smt = self.notes.unwrap_or(SimpleSmt::new().unwrap());
let notes_smt = self.notes.unwrap_or_default();
let chain_mmr = self.chain_mmr.unwrap_or_default();
let nullifiers_smt = self
.produced_nullifiers
Expand Down
4 changes: 2 additions & 2 deletions faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ actix-files = "0.6.5"
actix-cors = "0.7.0"
derive_more = "0.99.17"
figment = { version = "0.10", features = ["toml", "env"] }
miden-lib = { version = "0.1" } # Need to set older version because client doesn't support newest miden-objects yet
miden-lib = { version = "0.1.0" } # Version of miden-base is pinned due to client requirement
miden-client = { version = "0.1.0", features = ["concurrent"] }
miden-node-proto = { path = "../proto", version = "0.2" }
miden-node-utils = { path = "../utils", version = "0.2" }
miden-objects = { version = "0.1" } # Need to set older version because client doesn't support newest miden-objects yet
miden-objects = { version = "0.1.0" } # Version of miden-base is pinned due to client requirement
serde = { version = "1.0", features = ["derive"] }
clap = { version = "4.5.1", features = ["derive"] }
async-mutex = "1.4.0"
Expand Down
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ miden-node-rpc = { path = "../rpc", version = "0.2" }
miden-node-store = { path = "../store", version = "0.2" }
miden-node-utils = { path = "../utils", version = "0.2" }
miden-objects = { workspace = true }
rand_chacha = "0.3"
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.29", features = ["rt-multi-thread", "net", "macros"] }
tracing = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions node/genesis.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ timestamp = 1672531200
type = "BasicWallet"
init_seed = "0xa123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
auth_scheme = "RpoFalcon512"
auth_seed = "0xb123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
auth_seed = "0xb123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"

[[accounts]]
type = "BasicFungibleFaucet"
init_seed = "0xc123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
auth_scheme = "RpoFalcon512"
auth_seed = "0xd123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
auth_seed = "0xd123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
token_symbol = "POL"
decimals = 12
max_supply = 1000000
Loading

0 comments on commit 6eafe6e

Please sign in to comment.