Skip to content

Commit

Permalink
fix: Faucet storage offset validation code (#911)
Browse files Browse the repository at this point in the history
  • Loading branch information
igamigo authored Oct 8, 2024
1 parent 6dd2004 commit deafad8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion miden-lib/asm/kernels/transaction/lib/account.masm
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ export.validate_procedure_metadata
# => [index, num_storage_slots, num_account_procedures]
else
# assert that storage offset is in bounds
dup dup.3 lt assert.err=ERR_STORAGE_SLOT_INDEX_OUT_OF_BOUNDS
dup dup.4 lt assert.err=ERR_STORAGE_SLOT_INDEX_OUT_OF_BOUNDS
# => [storage_offset, storage_size, index, num_storage_slots, num_account_procedures]

# assert that storage limit is in bounds
Expand Down
15 changes: 12 additions & 3 deletions miden-lib/src/accounts/faucets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use alloc::string::ToString;

use miden_objects::{
accounts::{
Account, AccountCode, AccountId, AccountStorage, AccountStorageMode, AccountType,
StorageSlot,
Account, AccountCode, AccountId, AccountProcedureInfo, AccountStorage, AccountStorageMode,
AccountType, StorageSlot,
},
assets::TokenSymbol,
AccountError, Felt, Word, ZERO,
Expand Down Expand Up @@ -39,7 +39,7 @@ pub fn create_basic_fungible_faucet(
auth_scheme: AuthScheme,
) -> Result<(Account, Word), AccountError> {
// Atm we only have RpoFalcon512 as authentication scheme and this is also the default in the
// faucet contract, so we can just use the public key as storage slot 0.
// faucet contract.

let (auth_scheme_procedure, auth_data): (&str, Word) = match auth_scheme {
AuthScheme::RpoFalcon512 { pub_key } => ("auth_tx_rpo_falcon512", pub_key.into()),
Expand All @@ -56,6 +56,15 @@ pub fn create_basic_fungible_faucet(
let assembler = TransactionKernel::assembler();
let account_code = AccountCode::compile(source_code, assembler, true)?;

// TODO: Remove this manual modification once we have the ability to set sizes using the
// assembler.
let procedures = account_code
.procedures()
.iter()
.map(|proc| AccountProcedureInfo::new(*proc.mast_root(), proc.storage_offset(), 2).unwrap())
.collect();
let account_code = AccountCode::from_parts(account_code.mast(), procedures);

// First check that the metadata is valid.
if decimals > MAX_DECIMALS {
return Err(AccountError::FungibleFaucetInvalidMetadata(
Expand Down

0 comments on commit deafad8

Please sign in to comment.