Skip to content

Commit

Permalink
fix: address suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
tomyrd committed Oct 23, 2024
1 parent 9d24ebe commit 7b9383f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions miden-lib/asm/kernels/transaction/api.masm
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ end
#! The input block height delta is added to the reference block in order to output an upper limit
#! up until which the transaction will be considered valid (not expired).
#!
#! Inputs: [block_height_delta, ...]
#! Inputs: [KERNEL_PROCEDURE_HASH, block_height_delta, ...]
#! Output: [...]
#!
#! Where:
Expand All @@ -1091,7 +1091,7 @@ end
#! Gets the transaction expiration delta.
#!
#! Inputs: [...]
#! Output: [block_height_delta, ...]
#! Output: [KERNEL_PROCEDURE_HASH, block_height_delta, ...]
#!
#! Where:
#! - block_height_delta is the stored expiration time delta (1 to 0xFFFF).
Expand Down
16 changes: 14 additions & 2 deletions miden-lib/asm/kernels/transaction/lib/tx.masm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const.EXPIRY_UPPER_LIMIT=0xFFFF+1
# The note type must be PUBLIC, unless the high bits are `0b11`. (See the table below.)
const.ALL_NOTE_TYPES_ALLOWED=3 # 0b11

# Max U32 value, used for initializing the expiration block number
const.MAX_BLOCK_NUM=0xFFFFFFFF

# ERRORS
# =================================================================================================

Expand Down Expand Up @@ -227,8 +230,17 @@ end
#! Where:
#! - block_height_delta is the stored expiration time delta (1 to 0xFFFF).
export.get_expiration_delta
exec.memory::get_expiration_block_num exec.get_block_number
sub
exec.memory::get_expiration_block_num
# => [stored_expiration_block_num]

dup eq.MAX_BLOCK_NUM
if.true
# The delta was not set
drop push.0
else
# Calculate the delta
exec.get_block_number sub
end
end


Expand Down
14 changes: 9 additions & 5 deletions miden-lib/asm/miden/tx.masm
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,15 @@ export.execute_foreign_procedure
# => [<values returned from the foreign procedure>]
end

#! Updates the transaction expiration block delta.
#! Updates the transaction expiration delta.
#!
#! The input block_height_delta is added to the block reference number in order to determine an upper
#! limit at which the transaction will be considered valid (not expired).
#! This value can be later decreased, but not increased.
#! The transaction expiration delta specifies how close to the transaction's reference block the
#! transaction must be included into the chain. For example, if the transaction's reference block
#! is 100 and transaction expiration delta is 10, the transaction can be included into the chain
#! by block 110. If this does not happen, the transaction is considered expired and cannot be
#! included into the chain.
#!
#! Once set, transaction expiration delta can be decreased, but not increased.
#!
#! Inputs: [block_height_delta, ...]
#! Output: [...]
Expand All @@ -225,7 +229,7 @@ export.update_expiration_block_delta
dropw dropw dropw dropw
end

#! Gets the transaction expiration delta.
#! Returns the transaction expiration delta, or 0 if the delta has not been set.
#!
#! Inputs: [...]
#! Output: [block_height_delta, ...]
Expand Down
2 changes: 1 addition & 1 deletion miden-lib/src/transaction/procedures/kernel_v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ pub const KERNEL0_PROCEDURES: [Digest; 34] = [
// update_expiration_block_num
digest!(0x268af21ef3c89bcc, 0x4142290b918c7df8, 0x4d220ca00ecb6ec2, 0xa36b719508d30cb2),
// get_expiration_delta
digest!(0x4f8ba89ed03ed171, 0x847f80cf50f96733, 0xf41141e83cb42597, 0x6f21b93bdafe7270),
digest!(0xc315b9b152b64c75, 0x4eb3b30ec94a0887, 0xa8bb394f6805a266, 0xa05857dac130cf87),
];
4 changes: 4 additions & 0 deletions miden-tx/src/tests/kernel_tests/test_epilogue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,13 @@ fn test_no_expiration_delta_set() {
let code_template = "
use.kernel::prologue
use.kernel::epilogue
use.kernel::tx
begin
exec.prologue::prepare_transaction
exec.tx::get_expiration_delta assertz
exec.epilogue::finalize_transaction
end
";
Expand Down

0 comments on commit 7b9383f

Please sign in to comment.