Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FPI: foreign account data loader #896

Merged
merged 26 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ec39abb
refactor: move new acct code hash to bookkeeping, update acct layout
Fumuran Sep 18, 2024
eaa0465
refactor: update names of constants, move storage slot info to even p…
Fumuran Sep 18, 2024
e865dac
refactor: move new acct code hash to bookkeeping, update acct layout
Fumuran Sep 18, 2024
a1d5eef
refactor: update names of constants, move storage slot info to even p…
Fumuran Sep 18, 2024
16ca9be
feat: impl execute_foreign_procedure tx proc
Fumuran Sep 19, 2024
1a1e711
refactor: update proc name, update proc comments
Fumuran Sep 20, 2024
0eb5df1
refactor: remove assert_native_account from api, small improvements
Fumuran Sep 23, 2024
a11c183
refactor: update api proc docs, add error code, add native account ch…
Fumuran Sep 24, 2024
02ba7d0
feat: impl foreign account data loader
Fumuran Sep 24, 2024
4f808d8
Merge branch 'next' into andrew-fpi-foreign-account-loader
Fumuran Sep 24, 2024
7ba702f
refactor: move validate procs from prologue to memory
Fumuran Sep 25, 2024
8013cf6
test: impl basic test, fix some bugs
Fumuran Sep 25, 2024
1972405
chore: update changelog, fix clippy errors
Fumuran Sep 25, 2024
b8baef7
test: implement main tests for execute_foreign_procedure, fix some bugs
Fumuran Sep 30, 2024
466910a
Merge branch 'next' into andrew-fpi-foreign-account-loader
Fumuran Sep 30, 2024
869e968
chore: fix fmt
Fumuran Sep 30, 2024
3c1582d
Merge branch 'next' into andrew-fpi-foreign-account-loader
Fumuran Oct 2, 2024
5a31101
refactor: add native id check, move helper procs to account.masm
Fumuran Oct 3, 2024
5acc13c
Merge branch 'next' into andrew-fpi-foreign-account-loader
Fumuran Oct 7, 2024
8331830
feat: implement verification of foreign account
Fumuran Oct 8, 2024
1408dfe
Merge branch 'next' into andrew-fpi-foreign-account-loader
Fumuran Oct 8, 2024
075bcb0
chore: fix formatting
Fumuran Oct 8, 2024
9f29675
refactor: skip formatting for tx_kernel_errors file
Fumuran Oct 9, 2024
d293ca0
chore: small fixes
Fumuran Oct 10, 2024
1ffdd3d
refactor: improve doc comments, other small fixes
Fumuran Oct 12, 2024
2fefa6d
chore: update constant name
Fumuran Oct 13, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Added `AccountStorageHeader` (#876).
- Implemented generation of transaction kernel procedure hashes in build.rs (#887).
- [BREAKING] `send_asset` procedure was removed from the basic wallet (#829).
- Implemented ability to invoke procedures against the foreign account (#882, #890, #896).

## 0.5.1 (2024-08-28) - `miden-objects` crate only

Expand Down
90 changes: 85 additions & 5 deletions miden-lib/asm/kernels/transaction/api.masm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use.std::collections::smt
use.std::mem
use.std::sys

use.kernel::account
Expand Down Expand Up @@ -863,20 +864,99 @@ export.get_note_serial_number
end

#! Tells the transaction kernel that we are about to execute a procedure on a foreign account.
#!
#! Inputs: [KERNEL_PROCEDURE_HASH, foreign_account_id, pad(11)]
#! Outputs: [pad(16)]
#! Loads the data of the specified foreign account to the memory and moves the pointer of the
#! currently accessing account to it.
#!
#! Inputs:
#! Operand stack: [KERNEL_PROCEDURE_HASH, foreign_account_id, pad(11)]
#! Advice map: {
#! FOREIGN_ACCOUNT_ID: [[foreign_account_id, 0, 0, account_nonce], VAULT_ROOT, STORAGE_ROOT, CODE_ROOT],
#! STORAGE_ROOT: [[STORAGE_SLOT_DATA]],
#! CODE_ROOT: [[ACCOUNT_PROCEDURE_DATA]]
#! }
#! Outputs:
#! Operand stack: []
#!
#! Where:
#! - foreign_account_id is the ID of the foreign account whose procedure is going to be executed.
#! - foreign_account_id is the ID of the foreign account whose procedure is going to be executed.
#! - FOREIGN_ACCOUNT_ID is the word constructed from the foreign_account_id as follows:
#! [foreign_account_id, 0, 0, 0].
#! - account_nonce is the nonce of the foreign account.
#! - VAULT_ROOT is the commitment of the foreign account's vault.
#! - STORAGE_ROOT is the commitment of the foreign account's storage.
#! - STORAGE_SLOT_DATA is the data contained in the storage slot which is constructed as follows:
#! [SLOT_VALUE, slot_type, 0, 0, 0]
#! - CODE_ROOT is the commitment of the foreign account's code.
#! - ACCOUNT_PROCEDURE_DATA is the information about account procedure which is constructed as
#! follows: [PROCEDURE_MAST_ROOT, storage_offset, 0, 0, 0]
#!
#! Panics if:
#! - the current context is not a native context.
export.start_foreign_context
# check that this procedure was executed against the native account
exec.memory::assert_native_account
# OS => [KERNEL_PROCEDURE_HASH, foreign_account_id]

dropw drop # unimplemented!
# drop the procedure's hash
dropw
# OS => [foreign_account_id]

# get the memory address and a flag whether this account was already loaded.
exec.memory::get_foreign_account_ptr
# OS => [was_loaded, ptr, foreign_account_id]

if.true
exec.memory::set_current_account_data_ptr drop
# OS => []
else
exec.memory::set_current_account_data_ptr
# OS => [foreign_account_id]

# construct the word with account ID to load the core account data from the advice map
push.0.0.0
# OS => [0, 0, 0, foreign_account_id]

# move the core account data to the advice stack
adv.push_mapval
# OS => [0, 0, 0, foreign_account_id]
# AS => [[foreign_account_id, 0, 0, account_nonce], VAULT_ROOT, STORAGE_ROOT, CODE_ROOT]

# store the id and nonce of the foreign account to the memory
dropw adv_loadw
exec.memory::set_acct_id_and_nonce dropw
# OS => []
# AS => [VAULT_ROOT, STORAGE_ROOT, CODE_ROOT]

# store the vault root of the foreign account to the memory
adv_loadw exec.memory::set_acct_vault_root dropw
# OS => []
# AS => [STORAGE_ROOT, CODE_ROOT]

# move the storage root and the code root to the operand stack
adv_loadw padw adv_loadw
# OS => [CODE_ROOT, STORAGE_ROOT]
# AS => []

# store the code root into the memory
exec.memory::set_acct_code_commitment
# OS => [CODE_ROOT, STORAGE_ROOT]
# AS => []

# save the account procedure data into the memory
exec.memory::save_account_procedure_data
# OS => [STORAGE_ROOT]
# AS => []

# store the storage root to the memory
exec.memory::set_acct_storage_commitment
# OS => [STORAGE_ROOT]
# AS => []

# save the storage slots data into the memory
exec.memory::save_account_storage_data
# OS => []
# AS => []
end
end

#! Tells the transaction kernel that we are done executing a procedure on a foreign account.
Expand Down
Loading
Loading