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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Changes

- Added proc-macro `WordWrapper` to ease implementation of `Word`-wrapping types ([#2071](https://github.com/0xMiden/miden-base/pull/2108)).
- Closed gap in account memory layout by moving procedure tracking section immediately after procedure roots ([#2199](https://github.com/0xMiden/miden-base/pull/2199)).
- [BREAKING] Added `BlockBody` and `BlockProof` structs in preparation for validator signatures and deferred block proving ([#2012](https://github.com/0xMiden/miden-base/pull/2012)).
- [BREAKING] Renamed `TransactionEvent` into `TransactionEventId` and split event handling into data extraction and handling logic ([#2071](https://github.com/0xMiden/miden-base/pull/2071)).
- Split tx progress events out into a separate enum ([#2103](https://github.com/0xMiden/miden-base/pull/2103)).
Expand Down
8 changes: 4 additions & 4 deletions crates/miden-lib/asm/kernels/transaction/lib/memory.masm
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ const.ACCT_CODE_COMMITMENT_OFFSET=12
const.ACCT_CORE_DATA_SECTION_END_OFFSET=16
const.NUM_ACCT_PROCEDURES_OFFSET=28
const.ACCT_PROCEDURES_SECTION_OFFSET=32
const.ACCT_PROCEDURES_CALL_TRACKING_OFFSET=2084
const.NUM_ACCT_STORAGE_SLOTS_OFFSET=2340
const.ACCT_STORAGE_SLOTS_SECTION_OFFSET=2344
const.ACCT_PROCEDURES_CALL_TRACKING_OFFSET=1060
const.NUM_ACCT_STORAGE_SLOTS_OFFSET=1316
const.ACCT_STORAGE_SLOTS_SECTION_OFFSET=3360

# Offset at which an exact copy of the account's storage slot section starting at
# ACCT_STORAGE_SLOTS_SECTION_OFFSET is kept. This keeps the initial values of the account storage
# slots accessible to enable computing a diff between the initial and current account storage slots
# for use in the account delta. This section is only present for the native account.
const.ACCT_INITIAL_STORAGE_SLOTS_SECTION_OFFSET=4384
const.ACCT_INITIAL_STORAGE_SLOTS_SECTION_OFFSET=1320

# NATIVE ACCOUNT DELTA
# -------------------------------------------------------------------------------------------------
Expand Down
40 changes: 20 additions & 20 deletions crates/miden-lib/src/transaction/kernel_procedures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,65 @@ use miden_objects::{Word, word};
/// Hashes of all dynamically executed kernel procedures.
pub const KERNEL_PROCEDURES: [Word; 52] = [
// account_get_initial_commitment
word!("0x1c95a0386ebf3645c6271253a4ae49ea4be8610dea7b4436c58951277a75f0c1"),
word!("0x1bbebdc5b04407925b05dee65911648144a4736cc29bf5156121d9f9845ca552"),
// account_compute_commitment
word!("0x1aed40e2cc4d3798448f4efdce1a14c9598611da065eebe58432f144c3bca9de"),
word!("0x1be7cd026a891235ab0401c2f1d3ab162583375ee4b5b9c301c8197a9334ab30"),
// account_get_id
word!("0xd76288f2e94b9e6a8f7eeee45c4ee0a23997d78496f6132e3f55681efea809c4"),
// account_get_nonce
word!("0x4a1f11db21ddb1f0ebf7c9fd244f896a95e99bb136008185da3e7d6aa85827a3"),
// account_incr_nonce
word!("0x8bcc1f43091608403ea8d2fdefbcbfc799b41a0ff3fccc29b9873a23ff8edfbd"),
word!("0xd1316d21f95e20385283ac72914585a4a3281ff69935540d130fd1ace25ec9ae"),
// account_get_code_commitment
word!("0x54406e5633978e8319003d8d65527a48c0d0a4828263aa30f40687a2bbfd7be0"),
word!("0x8c044d53df35c71425c806b8997c6541e0aac70d7880657e9354b9854626ce3e"),
// account_get_initial_storage_commitment
word!("0x91377c2852feb7a2798e54d7dbaa2d97000270ec4c0d0888b26d720a25ae0e84"),
// account_compute_storage_commitment
word!("0xaa54d5c070ad5e2a39c9b8b3a17aaa3c9e9387c35c59f72c965060ba91e4f748"),
word!("0x3a23d1218e58884afe87df989f56f923fe5cec6875587a7d3190b1d6a530d3fd"),
// account_get_item
word!("0x6e3dc7fd548bfd6c802b6799be6e996eff247ecb2f16834a9363eca1b1751607"),
word!("0x0b001ad75998639c9b7e212696b851ed25bb750a309b51809ff44735ef45e848"),
// account_get_initial_item
word!("0x4835f7023bcafd46f28ece1e5c879f0f99191f78e4026c5c0590c01edc8ab598"),
word!("0xcef7817dc0618f198f7fd2eb30e4595e51d56947af26c4bcb667184f8dbc6e9a"),
// account_set_item
word!("0x07737e8ce29230526bb76b64f64da0e45739363e11b11cb746657adaa749b37c"),
word!("0x9a814c196233497b14726c6d0f0e44ddd371c8eeb8e37131b5c0fef28cf9e177"),
// account_get_map_item
word!("0xd816dc31953635af927407f3b1cd8f1ec6825522363a93c264cc36eaeb23d019"),
word!("0x031295794f6b94f17b4fd33084cb6bcb1afdd3075b78cc33ad49410b93f4e168"),
// account_get_initial_map_item
word!("0x773b9197efb18287cc9f1009ea53dbd3945b79b7168717b6a56ff0292083d1ea"),
word!("0xfb8800511ba276a0b148cb069bb2e9ef5595c00b57d5452c9df57c749c60f224"),
// account_set_map_item
word!("0x5e8aafb3ad8a442e29c9850c372d391ffbfd5e55e90109d33e4017d7c2626e62"),
word!("0xb43811f4773414f6d0e7ac8567f71877579d36a86a4eb682a7e5674798f3c042"),
// account_get_initial_vault_root
word!("0x46297d9ac95afd60c7ef1a065e024ad49aa4c019f6b3924191905449b244d4ec"),
// account_get_vault_root
word!("0x42a2bfb8eac4fce9bbf75ea15215b00729faeeaf7fff784692948d3f618a9bb7"),
// account_add_asset
word!("0x222ae6f550bb09b675cd73acf2e8ab25e4b8f06afa3ef1a1f66d3372e843ff3e"),
word!("0x75e527cd32297a838f8e47af2f2f69d2c14eb03b9ab9554d98c8caa6e3b3f049"),
// account_remove_asset
word!("0xc927af9fb41cece5eeafa4cc05ad4d82ec7771e8bc94db677a357bfca1f92ca7"),
word!("0xf4df1ee5eaa4effe8e6dcacf701a73a72f2dfc406dc8e193fe480f68b185f5bd"),
// account_get_balance
word!("0x1ed792cc7775aa1ce2f32367a3d430561ec9bceb33f5bb222691c49a6bde8112"),
// account_get_initial_balance
word!("0xdc1320d6f044c40d37e5e835a584b643d6e77e3fc1136f498815298e28c912b8"),
// account_has_non_fungible_asset
word!("0xfaad11de0c026551df15231790c2364cc598e891444bf826da01b524b1a8ca8f"),
// account_compute_delta_commitment
word!("0xd7ced8e16079d9c775e7dfc6b9d4b7a946ccd973fcd0ccaa84095bf8e10561a2"),
word!("0x0d791c9be955c547160a13ec6dabb88e24d89dc2d201062cedc2c42713d2c581"),
// account_get_num_procedures
word!("0x53b5ec38b7841948762c258010e6e07ad93963bcaac2d83813f8edb6710dc720"),
// account_get_procedure_root
word!("0xa45796077477599813ea54d88a83dfca3e64b1c112117970d63a1c24f7cfef5a"),
// account_was_procedure_called
word!("0x23ccd2f94111eabb33481664f8ca5a400b1518380a5adadabd2cee7a825a0465"),
word!("0xd9e08c27f3f1e7d01d257cbb4583ecf14f5e362d9c19e39ada8bc19dcc820d45"),
// account_has_procedure
word!("0xb0b63fdd01af0bcb4aacb2412e934cdc7691308647152d416c7ae4fc909da076"),
// faucet_mint_asset
word!("0xf44dbb74a478e3ac63eada9680c32d57890e481f7ade41382cbf2a98592320fe"),
word!("0x2f678d04d34d9c5fa3999f8afe67b90541d283145ce6b126339ef0829b5e5c52"),
// faucet_burn_asset
word!("0x522a0592e159ac3fa15bfc73bba8afd1b753fdb9f86a6526f3c02a25b42bacec"),
word!("0xfd3ee96700d65ee217eae73259c8eeb4bd3e5a18e71afbc4230a64a067eae8a1"),
// faucet_get_total_fungible_asset_issuance
word!("0x51cfb361598b5dd34ff93ae2c3788e7c1cd702e8831e2ea1d45dfc2ccd97876f"),
word!("0x8b7e6fe35aad099792f7aed7bf49437d5fc91ba086f6ee192c2f62b645e97c28"),
// faucet_is_non_fungible_asset_issued
word!("0xb4e83658a2c6b89ce2562fed3a6dfa141f7ff00c3d36a89d0d06f70b6690f133"),
word!("0x1a7d7f5ade931849e6f3a2307237393f36730b25bf5afbe0d42d607a8700e1b8"),
// input_note_get_metadata
word!("0x7ad3e94585e7a397ee27443c98b376ed8d4ba762122af6413fde9314c00a6219"),
// input_note_get_assets_info
Expand Down Expand Up @@ -104,7 +104,7 @@ pub const KERNEL_PROCEDURES: [Word; 52] = [
// tx_get_block_timestamp
word!("0x7903185b847517debb6c2072364e3e757b99ee623e97c2bd0a4661316c5c5418"),
// tx_start_foreign_context
word!("0x923b99b2b14173d265dfdeda4375fb4195f1246a6c96b102b256bb1a6400d2e9"),
word!("0xa53392b79f6caae70be66f33bc180dec56cabdb5d10481837bc44c7397d74bbb"),
// tx_end_foreign_context
word!("0xaa0018aa8da890b73511879487f65553753fb7df22de380dd84c11e6f77eec6f"),
// tx_get_expiration_delta
Expand Down
80 changes: 36 additions & 44 deletions crates/miden-lib/src/transaction/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,49 @@ pub type StorageSlot = u8;

// General layout
//
// Here the "end address" is the last memory address occupied by the current data
//
// | Section | Start address, pointer (word pointer) | End address, pointer (word pointer) | Comment |
// | ------------------ | :-----------------------------------: | :---------------------------------: | ------------------------------------------ |
// | Bookkeeping | 0 (0) | 88 (22) | |
// | Global inputs | 400 (100) | 439 (109) | |
// | Block header | 800 (200) | 843 (210) | |
// | Partial blockchain | 1_200 (300) | 1_331? (332?) | |
// | Kernel data | 1_600 (400) | 1_739 (434) | 34 procedures in total, 4 elements each |
// | Accounts data | 8_192 (2048) | 532_479 (133_119) | 64 accounts max, 8192 elements each |
// | Account delta | 532_480 (133_120) | 532_742 (133_185) | |
// | Input notes | 4_194_304 (1_048_576) | 6_356_991 (1_589_247) | nullifiers data segment + 1024 input notes |
// | | | | max, 2048 elements each |
// | Output notes | 16_777_216 (4_194_304) | 18_874_367 (4_718_591) | 1024 output notes max, 2048 elements each |
// | Link Map Memory | 33_554_432 (8_388_608) | 67_108_863 (16_777_215) | Enough for 2_097_151 key-value pairs |
// | Section | Start address | Size in elements | Comment |
// | :----------------: | :-----------: | :--------------: | ------------------------------------------ |
// | Bookkeeping | 0 | 89 | |
// | Global inputs | 400 | 40 | |
// | Block header | 800 | 44 | |
// | Partial blockchain | 1_200 | 132 | |
// | Kernel data | 1_600 | 140 | 34 procedures in total, 4 elements each |
// | Accounts data | 8_192 | 524_288 | 64 accounts max, 8192 elements each |
// | Account delta | 532_480 | 263 | |
// | Input notes | 4_194_304 | 2_162_688 | nullifiers data segment + 1024 input notes |
// | | | | max, 2048 elements each |
// | Output notes | 16_777_216 | 2_097_152 | 1024 output notes max, 2048 elements each |
// | Link Map Memory | 33_554_432 | 33_554_432 | Enough for 2_097_151 key-value pairs |

// Relative layout of one account
//
// Here the "end pointer" is the last memory pointer occupied by the current data
//
// TODO: Rearrange the memory sections that follow account procedures to be contiguous to it.
//
// | Section | Start address, pointer (word pointer) | End address, pointer (word pointer) | Comment |
// | ------------------ | :-----------------------------------: | :---------------------------------: | ----------------------------------- |
// | ID and nonce | 0 (0) | 3 (0) | |
// | Vault root | 4 (1) | 7 (1) | |
// | Storage commitment | 8 (2) | 11 (2) | |
// | Code commitment | 12 (3) | 15 (3) | |
// | Padding | 16 (4) | 27 (6) | |
// | Num procedures | 28 (7) | 31 (7) | |
// | Procedures roots | 32 (8) | 1_055 (263) | 256 procedures max, 4 elements each |
// | Padding | 2_080 (520) | 2_083 (520) | |
// | Proc tracking | 2_084 (521) | 2_339 (584) | 256 procedures max, 1 element each |
// | Num storage slots | 2_340 (585) | 2_343 (585) | |
// | Storage slot info | 2_344 (586) | 4_383 (1095) | 255 slots max, 8 elements each |
// | Initial slot info | 4_384 (1096) | 6_423 (1545) | Only present on the native account |
// | Padding | 6_424 (1545) | 8_191 (2047) | |
// | Section | Start address | Size in elements | Comment |
// | :----------------: | :-----------: | :--------------: | -------------------------------------- |
// | ID and nonce | 0 | 4 | |
// | Vault root | 4 | 4 | |
// | Storage commitment | 8 | 4 | |
// | Code commitment | 12 | 4 | |
// | Padding | 16 | 12 | |
// | Num procedures | 28 | 4 | |
// | Procedures roots | 32 | 1_024 | 256 procedures max, 4 elements each |
// | Padding | 1_056 | 4 | |
// | Proc tracking | 1_060 | 256 | 256 procedures max, 1 element each |
// | Num storage slots | 1_316 | 4 | |
// | Initial slot info | 1_320 | 2_040 | Only initialized on the native account |
// | Storage slot info | 3_360 | 2_040 | 255 slots max, 8 elements each |
// | Padding | 5_400 | 2_792 | |
//
// Storage slot info is laid out as [[0, slot_type, slot_id_suffix, slot_id_prefix], SLOT_VALUE].

// Relative layout of the native account's delta.
//
// Here the "end pointer" is the last memory pointer occupied by the current data
//
// For now each Storage Map pointer (a link map ptr) occupies a single element.
//
// | Section | Start address (word pointer) | End address (word pointer) | Comment |
// | ---------------------------- | :--------------------------: | :------------------------: | ----------------------------------- |
// | Fungible Asset Delta Ptr | 0 (0) | 3 (0) | |
// | Non-Fungible Asset Delta Ptr | 4 (1) | 7 (1) | |
// | Storage Map Delta Ptrs | 8 (2) | 263 (65) | Max 255 storage map deltas |
// | Section | Start address | Size in elements | Comment |
// | :--------------------------: | :-----------: | :--------------: | -------------------------- |
// | Fungible Asset Delta Ptr | 0 | 4 | |
// | Non-Fungible Asset Delta Ptr | 4 | 4 | |
// | Storage Map Delta Ptrs | 8 | 256 | Max 255 storage map deltas |

// BOOKKEEPING
// ------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -286,7 +278,7 @@ pub const NATIVE_ACCT_PROCEDURES_SECTION_PTR: MemoryAddress =

/// The offset at which the account procedures call tracking section begins relative to the start of
/// the account data segment.
pub const ACCT_PROCEDURES_CALL_TRACKING_OFFSET: MemoryAddress = 2084;
pub const ACCT_PROCEDURES_CALL_TRACKING_OFFSET: MemoryAddress = 1060;

/// The memory address at which the account procedures call tracking section begins in the native
/// account.
Expand All @@ -295,7 +287,7 @@ pub const NATIVE_ACCT_PROCEDURES_CALL_TRACKING_PTR: MemoryAddress =

/// The offset at which the number of storage slots contained in the account storage is stored
/// relative to the start of the account data segment.
pub const NUM_ACCT_STORAGE_SLOTS_OFFSET: MemoryAddress = 2340;
pub const NUM_ACCT_STORAGE_SLOTS_OFFSET: MemoryAddress = 1316;

/// The memory address at which number of storage slots contained in the account storage is stored
/// in the native account.
Expand All @@ -304,7 +296,7 @@ pub const NATIVE_NUM_ACCT_STORAGE_SLOTS_PTR: MemoryAddress =

/// The offset at which the account storage slots section begins relative to the start of the
/// account data segment.
pub const ACCT_STORAGE_SLOTS_SECTION_OFFSET: MemoryAddress = 2344;
pub const ACCT_STORAGE_SLOTS_SECTION_OFFSET: MemoryAddress = 3360;

/// The number of elements that each storage slot takes up in memory.
pub const ACCT_STORAGE_SLOT_NUM_ELEMENTS: u8 = 8;
Expand Down
Loading