Skip to content

Commit

Permalink
refactor: extend AccountId to two felts and refactor creation proce…
Browse files Browse the repository at this point in the history
…ss (#982)
  • Loading branch information
PhilippGackstatter authored Dec 25, 2024
1 parent bd34926 commit 64d7a2e
Show file tree
Hide file tree
Showing 83 changed files with 3,422 additions and 1,686 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Added conversion from `Account` to `AccountDelta` for initial account state representation as delta (#983).
- [BREAKING] Added `miden::note::get_script_hash` procedure (#995).
- [BREAKING] Refactor error messages in `miden-lib` and `miden-tx` and use `thiserror` 2.0 (#1005).
- [BREAKING] Extend `AccountId` to two `Felt`s and require block hash in derivation (#982).
- Removed workers list from the proxy configuration file (#1018).

## 0.6.2 (2024-11-20)
Expand Down
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ WARNINGS=RUSTDOCFLAGS="-D warnings"
DEBUG_ASSERTIONS=RUSTFLAGS="-C debug-assertions"
ALL_FEATURES_BUT_ASYNC=--features concurrent,testing
BUILD_KERNEL_ERRORS=BUILD_KERNEL_ERRORS=1
# Enable backtraces for tests where we return an anyhow::Result. If enabled, anyhow::Error will
# then contain a `Backtrace` and print it when a test returns an error.
BACKTRACE=RUST_BACKTRACE=1

# -- linting --------------------------------------------------------------------------------------

Expand Down Expand Up @@ -56,12 +59,12 @@ test-build: ## Build the test binary

.PHONY: test-default
test-default: ## Run default tests excluding `prove`
$(DEBUG_ASSERTIONS) cargo nextest run --profile default --cargo-profile test-release --features concurrent,testing --filter-expr "not test(prove)"
$(DEBUG_ASSERTIONS) $(BACKTRACE) cargo nextest run --profile default --cargo-profile test-release --features concurrent,testing --filter-expr "not test(prove)"


.PHONY: test-prove
test-prove: ## Run `prove` tests (tests which use the Miden prover)
$(DEBUG_ASSERTIONS) cargo nextest run --profile prove --cargo-profile test-release --features concurrent,testing --filter-expr "test(prove)"
$(DEBUG_ASSERTIONS) $(BACKTRACE) cargo nextest run --profile prove --cargo-profile test-release --features concurrent,testing --filter-expr "test(prove)"


.PHONY: test
Expand Down
5 changes: 3 additions & 2 deletions bin/bench-tx/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ use super::{read_to_string, write, Benchmark, Path};
// CONSTANTS
// ================================================================================================

pub const ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN: u64 = 0x200000000000001f; // 2305843009213693983
pub const ACCOUNT_ID_SENDER: u64 = 0x800000000000001f; // 9223372036854775839
// Copied from miden_objects::testing::account_id.
pub const ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN: u128 = 0x00aa00000000bc200000bc000000de00;
pub const ACCOUNT_ID_SENDER: u128 = 0x00fa00000000bb800000cc000000de00;

pub const DEFAULT_AUTH_SCRIPT: &str = "
begin
Expand Down
6 changes: 4 additions & 2 deletions bin/tx-prover/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ mod test {

use miden_lib::transaction::TransactionKernel;
use miden_objects::{
accounts::account_id::testing::{ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_SENDER},
assets::{Asset, FungibleAsset},
notes::NoteType,
testing::account_code::DEFAULT_AUTH_SCRIPT,
testing::{
account_code::DEFAULT_AUTH_SCRIPT,
account_id::{ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_SENDER},
},
transaction::{ProvenTransaction, TransactionScript, TransactionWitness},
};
use miden_tx::{
Expand Down
61 changes: 32 additions & 29 deletions miden-lib/asm/kernels/transaction/api.masm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ end
#! Returns the account id.
#!
#! Inputs: [pad(16)]
#! Outputs: [acct_id, pad(15)]
#! Outputs: [acct_id_hi, acct_id_lo, pad(14)]
#!
#! Where:
#! - acct_id is the account id.
Expand All @@ -83,11 +83,11 @@ end
export.get_account_id
# get the account id
exec.account::get_id
# => [acct_id, pad(16)]
# => [acct_id_hi, acct_id_lo, pad(16)]

# truncate the stack
swap drop
# => [acct_id, pad(15)]
movup.2 drop movup.2 drop
# => [acct_id_hi, acct_id_lo, pad(14)]
end

#! Returns the account nonce.
Expand Down Expand Up @@ -229,7 +229,7 @@ export.set_account_item
# if the transaction is being executed against a faucet account then assert
# index != FAUCET_STORAGE_DATA_SLOT (reserved slot)
dup exec.account::get_faucet_storage_data_slot eq
exec.account::get_id exec.account::is_faucet
exec.account::get_id swap drop exec.account::is_faucet
and assertz.err=ERR_FAUCET_STORAGE_DATA_SLOT_IS_RESERVED
# => [index, V', pad(11)]

Expand Down Expand Up @@ -371,11 +371,12 @@ end

#! Returns the balance of a fungible asset associated with a faucet_id.
#!
#! Inputs: [faucet_id, pad(15)]
#! Inputs: [faucet_id_hi, faucet_id_lo, pad(14)]
#! Outputs: [balance, pad(15)]
#!
#! Where:
#! - faucet_id is the faucet id of the fungible asset of interest.
#! - faucet_id_{hi,lo} are the first and second felt of the faucet id of the fungible asset
#! of interest.
#! - balance is the vault balance of the fungible asset.
#!
#! Panics if:
Expand All @@ -384,8 +385,8 @@ end
#! Invocation: dynexec
export.account_vault_get_balance
# get the vault root
exec.memory::get_acct_vault_root_ptr swap
# => [faucet_id, acct_vault_root_ptr, pad(15)]
exec.memory::get_acct_vault_root_ptr movdn.2
# => [faucet_id_hi, faucet_id_lo, acct_vault_root_ptr, pad(13)]

# get the asset balance
exec.asset_vault::get_balance
Expand Down Expand Up @@ -554,22 +555,23 @@ end
#! Returns the sender of the note currently being processed.
#!
#! Inputs: [pad(16)]
#! Outputs: [sender, pad(15)]
#! Outputs: [sender_hi, sender_lo, pad(14)]
#!
#! Where:
#! - sender is the sender of the note currently being processed.
#! - sender_{hi,lo} are the first and second felt of the sender account id of the note currently
#! being processed.
#!
#! Panics if:
#! - a note is not being processed.
#!
#! Invocation: dynexec
export.get_note_sender
exec.note::get_sender
# => [sender, pad(16)]
exec.note::get_sender
# => [sender_hi, sender_lo, pad(16)]

# truncate the stack
swap drop
# => [sender, pad(15)]
swapw dropw
# => [sender_hi, sender_lo, pad(14)]
end

#! Returns the block number of the last known block at the time of transaction execution.
Expand Down Expand Up @@ -818,7 +820,7 @@ end
#! Invocation: dynexec
export.get_fungible_faucet_total_issuance
# assert that we are executing a transaction against a fungible faucet (access checks)
exec.account::get_id exec.account::is_fungible_faucet
exec.account::get_id swap drop exec.account::is_fungible_faucet
assert.err=ERR_ACCOUNT_TOTAL_ISSUANCE_PROC_CAN_ONLY_BE_CALLED_ON_FUNGIBLE_FAUCET
# => [pad(16)]

Expand Down Expand Up @@ -879,20 +881,21 @@ end
#! Moves the account pointer to the currently accessing foreign account.
#!
#! Inputs:
#! Operand stack: [foreign_account_id, pad(15)]
#! Operand stack: [foreign_account_id_hi, foreign_account_id_lo, pad(14)]
#! Advice map: {
#! FOREIGN_ACCOUNT_ID: [[foreign_account_id, 0, 0, account_nonce], VAULT_ROOT, STORAGE_ROOT,
#! CODE_ROOT],
#! FOREIGN_ACCOUNT_ID: [[foreign_account_lo, foreign_account_id_hi, 0, account_nonce],
#! VAULT_ROOT, STORAGE_ROOT, CODE_ROOT],
#! STORAGE_ROOT: [[STORAGE_SLOT_DATA]],
#! CODE_ROOT: [num_procs, [ACCOUNT_PROCEDURE_DATA]]
#! }
#! Outputs:
#! Operand stack: [pad(16)]
#!
#! Where:
#! - foreign_account_id is the ID of the foreign account whose procedure is going to be executed.
#! - foreign_account_id_{hi,lo} are the first and second felt of 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].
#! [foreign_account_id_hi, foreign_account_lo, 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.
Expand All @@ -909,27 +912,27 @@ end
export.start_foreign_context
# check that this procedure was executed against the native account
exec.memory::assert_native_account
# OS => [foreign_account_id, pad(15)]
# OS => [foreign_account_id_hi, foreign_account_id_lo, pad(14)]

# get the memory address and a flag whether this account was already loaded.
exec.account::get_foreign_account_ptr
# OS => [was_loaded, ptr, foreign_account_id, pad(15)]
# OS => [was_loaded, ptr, foreign_account_id_hi, foreign_account_id_lo, pad(14)]

if.true
exec.memory::set_current_account_data_ptr drop
exec.memory::set_current_account_data_ptr drop drop
# OS => [pad(16)]
else
exec.memory::set_current_account_data_ptr
# OS => [foreign_account_id, pad(15)]
# OS => [foreign_account_id_hi, foreign_account_id_lo, pad(14)]

# 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, pad(15)]
swap push.0.0
# OS => [0, 0, foreign_account_id_lo, foreign_account_id_hi, pad(14)]

# move the core account data to the advice stack
adv.push_mapval
# OS => [0, 0, 0, foreign_account_id, pad(15)]
# AS => [[foreign_account_id, 0, 0, account_nonce], VAULT_ROOT, STORAGE_ROOT, CODE_ROOT]
# OS => [0, 0, foreign_account_id_lo, foreign_account_id_hi, pad(14)]
# AS => [[foreign_account_id_hi, foreign_account_lo, 0, account_nonce], VAULT_ROOT, STORAGE_ROOT, CODE_ROOT]

# store the id and nonce of the foreign account to the memory
dropw adv_loadw
Expand Down
Loading

0 comments on commit 64d7a2e

Please sign in to comment.