Skip to content

Commit

Permalink
Error on 111
Browse files Browse the repository at this point in the history
  • Loading branch information
phklive committed Aug 2, 2024
1 parent ecd788d commit 6e1d4fe
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 31 deletions.
40 changes: 30 additions & 10 deletions miden-lib/asm/kernels/transaction/api.masm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ const.ACCOUNT_VAULT_BEFORE_REMOVE_ASSET_EVENT=131074
# Event emitted after an asset is removed from the account vault.
const.ACCOUNT_VAULT_AFTER_REMOVE_ASSET_EVENT=131075

# AUTHENTICATION
# =================================================================================================

#! Authenticates that the invocation of a kernel procedure originates from the account context.
#!
#! Panics:
#! - if the invocation of the kernel procedure does not originate from the account context.
#!
#! Stack: []
#! Output: []
proc.authenticate_account_origin
# get the hash of the caller
padw caller
# => [CALLER]

# assert that the caller is from the user context
exec.account::authenticate_procedure
# => []
end

# KERNEL PROCEDURES
# =================================================================================================

Expand Down Expand Up @@ -105,7 +125,7 @@ end
#! procedure panics.
export.incr_account_nonce
# authenticate that the procedure invocation originates from the account context
exec.account::authenticate_procedure
exec.authenticate_account_origin
# => [value]

# arrange stack
Expand Down Expand Up @@ -152,7 +172,7 @@ export.set_account_item
# => [index, V', 0, 0, 0]

# authenticate that the procedure invocation originates from the account context
exec.account::authenticate_procedure
exec.authenticate_account_origin
# => [index, V', 0, 0, 0]

# set the account storage item
Expand Down Expand Up @@ -213,7 +233,7 @@ end
#! - NEW_MAP_ROOT is the root of the new map after insertion.
export.set_account_map_item.1
# authenticate that the procedure invocation originates from the account context
exec.account::authenticate_procedure
exec.authenticate_account_origin
# => [index, KEY, NEW_VALUE, ...]

# store index for later
Expand Down Expand Up @@ -242,7 +262,7 @@ end
#! - CODE_COMMITMENT is the hash of the code to set.
export.set_account_code
# authenticate that the procedure invocation originates from the account context
exec.account::authenticate_procedure
exec.authenticate_account_origin
# => [CODE_COMMITMENT]

# arrange stack
Expand Down Expand Up @@ -307,7 +327,7 @@ end
#! after ASSET was added to it.
export.account_vault_add_asset
# authenticate that the procedure invocation originates from the account context
exec.account::authenticate_procedure
exec.authenticate_account_origin
# => [ASSET]

push.0 drop # TODO: remove line, see miden-vm/#1122
Expand Down Expand Up @@ -344,7 +364,7 @@ end
#! - ASSET is the asset to remove from the vault.
export.account_vault_remove_asset
# authenticate that the procedure invocation originates from the account context
exec.account::authenticate_procedure
exec.authenticate_account_origin
# => [ASSET]

push.0 drop # TODO: remove line, see miden-vm/#1122
Expand Down Expand Up @@ -489,7 +509,7 @@ end
#! note_idx is the index of the crated note.
export.create_note
# authenticate that the procedure invocation originates from the account context
exec.account::authenticate_procedure
exec.authenticate_account_origin
# => [tag, aux, note_type, RECIPIENT]

exec.tx::create_note
Expand All @@ -513,7 +533,7 @@ end
#! ASSET can be a fungible or non-fungible asset.
export.add_asset_to_note
# authenticate that the procedure invocation originates from the account context
exec.account::authenticate_procedure
exec.authenticate_account_origin
# => [note_idx, ASSET]

exec.tx::add_asset_to_note
Expand Down Expand Up @@ -561,7 +581,7 @@ end
#! - ASSET is the asset that was minted.
export.mint_asset
# authenticate that the procedure invocation originates from the account context
exec.account::authenticate_procedure
exec.authenticate_account_origin
# => [ASSET]

# mint the asset
Expand All @@ -587,7 +607,7 @@ end
#! - ASSET is the asset that was burned.
export.burn_asset
# authenticate that the procedure invocation originates from the account context
exec.account::authenticate_procedure
exec.authenticate_account_origin
# => [ASSET]

# burn the asset
Expand Down
20 changes: 9 additions & 11 deletions miden-lib/asm/miden/kernels/tx/account.masm
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,13 @@ export.offset_storage_index
# => [storage_offset, slot_index]

# verify that slot_index is in bounds
dup.1 exec.get_max_storage_slot_index lt assert.err=ERR_STORAGE_SLOT_INDEX_OUT_OF_BOUNDS
dup.1 exec.get_max_storage_slot_index lt assert.err=111
# assert.err=ERR_STORAGE_SLOT_INDEX_OUT_OF_BOUNDS
# => [storage_offset, slot_index]

# verify that the computed offset_slot_index is in bounds
add dup exec.get_max_storage_slot_index lt assert.err=ERR_STORAGE_SLOT_INDEX_OUT_OF_BOUNDS
add dup exec.get_max_storage_slot_index lt assert.err=112
# assert.err=ERR_STORAGE_SLOT_INDEX_OUT_OF_BOUNDS
# => [offset_slot_index]
end

Expand All @@ -396,11 +398,11 @@ end
export.get_item
# apply storage offset for current procedure
exec.offset_storage_index
# => [offset_storage_index]
# => [offset_index]

# get the storage root
exec.memory::get_acct_storage_root
# => [STORAGE_ROOT, offset_storage_index]
# => [STORAGE_ROOT, offset_index]

# get the item from storage
movup.4 push.STORAGE_TREE_DEPTH mtree_get
Expand All @@ -424,11 +426,11 @@ end
proc.set_item_raw
# apply storage offset for current procedure
exec.offset_storage_index
# => [offset_storage_index]
# => [offset_index]

# get the storage root
exec.memory::get_acct_storage_root
# => [OLD_ROOT, index, NEW_VALUE]
# => [OLD_ROOT, offset_index, NEW_VALUE]

# set the item in storage
movup.4 push.STORAGE_TREE_DEPTH mtree_set
Expand Down Expand Up @@ -568,7 +570,7 @@ export.get_procedure_info

#! Verifies that the procedure root is part of the account code
#!
#! Stack: []
#! Stack: [PROC_ROOT]
#! Output: []
#!
#! - PROC_ROOT is the hash of the procedure to authenticate.
Expand All @@ -577,10 +579,6 @@ export.get_procedure_info
#! - procedure root is not part of the account code.
#!
export.authenticate_procedure
# get the hash of the caller
padw caller
# => [CALLER]

# load procedure index
emit.ACCOUNT_PUSH_PROCEDURE_INDEX_EVENT adv_push.1
# => [index, PROC_ROOT]
Expand Down
8 changes: 7 additions & 1 deletion miden-tx/src/tests/kernel_tests/test_account.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::println;

use miden_lib::transaction::memory::{ACCT_CODE_COMMITMENT_PTR, ACCT_NEW_CODE_COMMITMENT_PTR};
use miden_objects::{
accounts::{
Expand Down Expand Up @@ -217,6 +219,8 @@ fn test_get_item() {
for storage_item in [AccountStorage::mock_item_0(), AccountStorage::mock_item_1()] {
let tx_context = TransactionContextBuilder::with_standard_account(ONE).build();

println!("item index: {}", storage_item.index);
println!("value: {}", prepare_word(&storage_item.slot.value));
let code = format!(
"
use.miden::account
Expand All @@ -228,6 +232,9 @@ fn test_get_item() {
# push the account storage item index
push.{item_index}
debug.stack
debug.mem
# assert the item value is correct
exec.account::get_item
push.{item_value}
Expand Down Expand Up @@ -472,7 +479,6 @@ fn test_get_vault_commitment() {
// ================================================================================================

#[test]
#[ignore]
fn test_authenticate_procedure() {
let tx_context = TransactionContextBuilder::with_standard_account(ONE).build();
let account = tx_context.tx_inputs().account();
Expand Down
18 changes: 9 additions & 9 deletions objects/src/testing/account_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use crate::accounts::AccountCode;
// The MAST root of the default account's interface. Use these constants to interact with the
// account's procedures.
const MASTS: [&str; 11] = [
"0xf051343e7b23945f624afbc7c54dc0c19e525cd666334758beb28538d9cbb2d7",
"0x2c9cbadc209269b5ffa7d3839e083ea41e0fbe7eb774e095bed9ce77ccd5dc34",
"0x17b37765b823ded8ae4d43400d9766229b4d2dd8f437f22c91169c0a52ee0590",
"0x6189ac61a08c21386935e574d5393d625770372d8a754a23d94e203bc856a718",
"0xf6077820d253b2d46e380cde536abebaca92c3fbd0d5ee749600de4249ce8412",
"0x35d40a218134029c7e025e134c5a6745b0ebd39e6ee6aaa70fc41545ac740502",
"0xf470e1c5eeb4a8e5d7081d19cc06302fe7c77f04c9af7f5030c489960ec50222",
"0xac63b924674e0adda4ac5b3b36846601ecbc7c79bb4257c588b6fbae7eaca9ef",
"0xdb7bb7cc807ce17c9d4cd6877522da0514e9e276e550abf373d90e4625acd65a",
"0x4732dfb243aa5ae4bb6fbb2f388f301c954198d54adab1468c3e228ee02192e5",
"0x5ba128ebb528057cd2d668b6c9208c2f849c96f568e2b09d0b46c9126fafd5ad",
"0x683b1755d2f010c67122b041b6c0f56f888078bf5c68a64490cfdd131a430b52",
"0x869ed39da799fff104fd753cdf71b929d0002e70d3cbd1be687dcf79d8a7d606",
"0x606ec0e7980353e4d3ca7d067f9205f82c807f6e9637032ccd9593d62fd09160",
"0xd27d04f4920d439810350d751abe78cbef73b6cd872c0128d4395261c43907e6",
"0x5dc86f95034ecb0933e8cd6b328e2779e871fdc152706ff9b5470a55b9c27d61",
"0x20a04d49d76703fa28032a5a5f397157bacf388978affab25c59d04a1288541d",
"0x9f2624bb905681440666321e46590fd3720a8113f135f3171abfe9d6d902dfbc",
"0xff06b90f849c4b262cbfbea67042c4ea017ea0e9c558848a951d44b23370bec5",
"0x8ef0092134469a1330e3c468f57c7f085ce611645d09cc7516c786fefc71d794",
];
Expand Down

0 comments on commit 6e1d4fe

Please sign in to comment.