Skip to content
Closed
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
15 changes: 14 additions & 1 deletion crates/store/src/genesis/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,20 @@ impl GenesisConfig {
let full_path = config_dir.join(&acc.path);
let account_file = AccountFile::read(&full_path)
.map_err(|e| GenesisConfigError::AccountFileRead(e, full_path.clone()))?;
Ok(account_file.account)
let mut account = account_file.account;
// Genesis accounts must have nonce=1. If the .mac file contains a new account
// (nonce=0, seed present), bump the nonce so the seed is cleared and the account
// can be represented as a delta in the genesis block.
if account.is_new() {
let delta = AccountDelta::new(
account.id(),
AccountStorageDelta::default(),
AccountVaultDelta::default(),
ONE,
)?;
account.apply_delta(&delta)?;
}
Ok(account)
})
.collect::<Result<Vec<_>, GenesisConfigError>>()?;

Expand Down
22 changes: 16 additions & 6 deletions crates/store/src/genesis/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use miden_node_utils::signer::BlockSigner;
use miden_protocol::Word;
use miden_protocol::account::delta::AccountUpdateDetails;
use miden_protocol::account::{Account, AccountDelta};
use miden_protocol::account::{Account, AccountDelta, AccountStorageDelta, AccountVaultDelta};
use miden_protocol::block::account_tree::{AccountIdKey, AccountTree};
use miden_protocol::block::{
BlockAccountUpdate,
Expand All @@ -15,9 +14,9 @@ use miden_protocol::block::{
};
use miden_protocol::crypto::merkle::mmr::{Forest, MmrPeaks};
use miden_protocol::crypto::merkle::smt::{LargeSmt, MemoryStorage, Smt};
use miden_protocol::errors::AccountError;
use miden_protocol::note::Nullifier;
use miden_protocol::transaction::{OrderedTransactionHeaders, TransactionKernel};
use miden_protocol::{ONE, Word};

pub mod config;

Expand Down Expand Up @@ -92,11 +91,22 @@ impl<S: BlockSigner> GenesisState<S> {
pub async fn into_block(self) -> anyhow::Result<GenesisBlock> {
let accounts: Vec<BlockAccountUpdate> = self
.accounts
.iter()
.map(|account| {
.into_iter()
.map(|mut account| -> anyhow::Result<BlockAccountUpdate> {
let account_update_details = if account.id().is_private() {
AccountUpdateDetails::Private
} else {
// Genesis accounts must have nonce >= 1 to be representable as deltas.
// Accounts loaded from .mac files with nonce=0 (seed present) are bumped here.
if account.is_new() {
let delta = AccountDelta::new(
account.id(),
AccountStorageDelta::default(),
AccountVaultDelta::default(),
ONE,
)?;
account.apply_delta(&delta)?;
}
AccountUpdateDetails::Delta(AccountDelta::try_from(account.clone())?)
};

Expand All @@ -106,7 +116,7 @@ impl<S: BlockSigner> GenesisState<S> {
account_update_details,
))
})
.collect::<Result<Vec<_>, AccountError>>()?;
.collect::<anyhow::Result<Vec<_>>>()?;

// Convert account updates to SMT entries using account_id_to_smt_key
let smt_entries = accounts.iter().map(|update| {
Expand Down
Loading