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
6 changes: 3 additions & 3 deletions bin/node/src/commands/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use miden_node_store::{DEFAULT_MAX_CONCURRENT_PROOFS, Store};
use miden_node_utils::clap::{GrpcOptionsInternal, StorageOptions};
use miden_node_utils::fs::ensure_empty_directory;
use miden_node_utils::grpc::UrlExt;
use miden_protocol::block::ProvenBlock;
use miden_protocol::block::SignedBlock;
use miden_protocol::utils::serde::Deserializable;
use url::Url;

Expand Down Expand Up @@ -175,10 +175,10 @@ impl StoreCommand {
pub fn bootstrap_store(data_directory: &Path, genesis_block_path: &Path) -> anyhow::Result<()> {
// Read and deserialize the genesis block file.
let bytes = fs_err::read(genesis_block_path).context("failed to read genesis block")?;
let proven_block = ProvenBlock::read_from_bytes(&bytes)
let signed_block = SignedBlock::read_from_bytes(&bytes)
.context("failed to deserialize genesis block from file")?;
let genesis_block =
GenesisBlock::try_from(proven_block).context("genesis block validation failed")?;
GenesisBlock::try_from(signed_block).context("genesis block validation failed")?;

Store::bootstrap(genesis_block, data_directory)
}
7 changes: 3 additions & 4 deletions bin/stress-test/src/seeding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use miden_protocol::block::{
BlockNumber,
FeeParameters,
ProposedBlock,
ProvenBlock,
SignedBlock,
};
use miden_protocol::crypto::dsa::ecdsa_k256_keccak::SecretKey as EcdsaSecretKey;
Expand Down Expand Up @@ -111,12 +110,12 @@ pub async fn seed_store(
let accounts_filepath = data_directory.join(ACCOUNTS_FILENAME);
let data_directory =
miden_node_store::DataDirectory::load(data_directory).expect("data directory should exist");
let genesis_header = genesis_state.into_block().await.unwrap().into_inner();
let genesis_block = genesis_state.into_block().await.unwrap().into_inner();
let metrics = generate_blocks(
num_accounts,
public_accounts_percentage,
faucet,
genesis_header,
genesis_block,
&store_client,
data_directory,
accounts_filepath,
Expand All @@ -137,7 +136,7 @@ async fn generate_blocks(
num_accounts: usize,
public_accounts_percentage: u8,
mut faucet: Account,
genesis_block: ProvenBlock,
genesis_block: SignedBlock,
store_client: &StoreClient,
data_directory: DataDirectory,
accounts_filepath: PathBuf,
Expand Down
5 changes: 2 additions & 3 deletions crates/store/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,8 @@ impl Db {
// Run migrations.
apply_migrations(&mut conn).context("failed to apply database migrations")?;

// Insert genesis block data. Deconstruct into signed block.
let (header, body, signature, _proof) = genesis.into_inner().into_parts();
let genesis_block = SignedBlock::new_unchecked(header, body, signature);
// Insert genesis block data.
let genesis_block = genesis.into_inner();
conn.transaction(move |conn| models::queries::apply_block(conn, &genesis_block, &[], None))
.context("failed to insert genesis block")?;
Ok(())
Expand Down
23 changes: 9 additions & 14 deletions crates/store/src/genesis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ use miden_protocol::block::{
BlockHeader,
BlockNoteTree,
BlockNumber,
BlockProof,
FeeParameters,
ProvenBlock,
SignedBlock,
};
use miden_protocol::crypto::merkle::mmr::{Forest, MmrPeaks};
use miden_protocol::crypto::merkle::smt::{LargeSmt, MemoryStorage, Smt};
Expand All @@ -35,23 +34,23 @@ pub struct GenesisState<S> {
}

/// A type-safety wrapper ensuring that genesis block data can only be created from
/// [`GenesisState`] or validated from a [`ProvenBlock`] via [`GenesisBlock::try_from`].
pub struct GenesisBlock(ProvenBlock);
/// [`GenesisState`] or validated from a [`SignedBlock`] via [`GenesisBlock::try_from`].
pub struct GenesisBlock(SignedBlock);

impl GenesisBlock {
pub fn inner(&self) -> &ProvenBlock {
pub fn inner(&self) -> &SignedBlock {
&self.0
}

pub fn into_inner(self) -> ProvenBlock {
pub fn into_inner(self) -> SignedBlock {
self.0
}
}

impl TryFrom<ProvenBlock> for GenesisBlock {
impl TryFrom<SignedBlock> for GenesisBlock {
type Error = anyhow::Error;

fn try_from(block: ProvenBlock) -> anyhow::Result<Self> {
fn try_from(block: SignedBlock) -> anyhow::Result<Self> {
anyhow::ensure!(
block.header().block_num() == BlockNumber::GENESIS,
"expected genesis block number (0), got {}",
Expand Down Expand Up @@ -152,15 +151,11 @@ impl<S: BlockSigner> GenesisState<S> {
empty_transactions,
);

let block_proof = BlockProof::new_dummy();

// Sign and assert verification for sanity (no mismatch between frontend and backend signing
// impls).
let signature = self.block_signer.sign(&header).await?;
assert!(signature.verify(header.commitment(), &self.block_signer.public_key()));
// SAFETY: Header and accounts should be valid by construction.
// No notes or nullifiers are created at genesis, which is consistent with the above empty
// block note tree root and empty nullifier tree root.
Ok(GenesisBlock(ProvenBlock::new_unchecked(header, body, signature, block_proof)))
let signed_block = SignedBlock::new(header, body, signature)?;
Ok(GenesisBlock(signed_block))
}
}
Loading