We have a few places where we check whether an account ID is zero. It'd be nice to have a small helper that implements this for more clarity to replace code like dup.1 eq.0 dup.1 eq.0 and with exec.account_id::testz.
So, we should add helpers in the account_id module that tests whether an account ID is zero, one that consumes the inputs and one that doesn't (mirroring miden::core::word::{eqz, testz}):
#! Returns a boolean indicating whether the given account_id limbs are both zero.
#!
#! Inputs: [account_id_suffix, account_id_prefix]
#! Outputs: [is_zero, account_id_suffix, account_id_prefix]
#!
#! Where:
#! - account_id_{suffix,prefix} are the suffix and prefix felts of an account ID.
#! - is_zero is a boolean indicating whether the account ID is zero.
pub proc testz
#! Returns a boolean indicating whether the given account_id limbs are both zero.
#!
#! Inputs: [account_id_suffix, account_id_prefix]
#! Outputs: [is_zero]
#!
#! Where:
#! - account_id_{suffix,prefix} are the suffix and prefix felts of an account ID.
#! - is_zero is a boolean indicating whether the account ID is zero.
pub proc eqz
Maybe it makes sense to rename is_equal to eq for consistency?
Then update the following places in MASM code where account IDs are checked for being zero:
Direct Zero Checks (manual dup + eq.0 pattern)
(This includes PR #2712)
- crates/miden-protocol/asm/kernels/transaction/api.masm:1502
dup.1 eq.0 dup.1 eq.0 and not assert.err=ERR_FOREIGN_ACCOUNT_ID_IS_ZERO
- Asserts foreign account ID is not zero by testing both elements.
- crates/miden-standards/asm/standards/access/ownable2step.masm:253
dup.1 eq.0 dup.1 eq.0 and
- Checks if nominated owner is zero (cancellation of ownership transfer).
- crates/miden-standards/asm/standards/access/ownable2step.masm:297
dup.1 eq.0 dup.1 eq.0 and
- Checks if nominated owner is zero to verify a transfer exists.
Using account_id::is_equal with pushed zeros
- crates/miden-protocol/asm/kernels/transaction/lib/account.masm:1831
dup.1 dup.1 push.0 push.0 exec.account_id::is_equal
- Compares account ID with (0, 0) to detect uninitialized memory blocks when loading foreign
accounts.
- crates/miden-agglayer/asm/agglayer/bridge/bridge_config.masm:219-222
dup.3 dup.3 push.0.0 exec.account_id::is_equal
assertz.err=ERR_TOKEN_NOT_REGISTERED
- Validates that a faucet ID from registry is not zero (token is registered).
We have a few places where we check whether an account ID is zero. It'd be nice to have a small helper that implements this for more clarity to replace code like
dup.1 eq.0 dup.1 eq.0 andwithexec.account_id::testz.So, we should add helpers in the
account_idmodule that tests whether an account ID is zero, one that consumes the inputs and one that doesn't (mirroringmiden::core::word::{eqz, testz}):Maybe it makes sense to rename
is_equaltoeqfor consistency?Then update the following places in MASM code where account IDs are checked for being zero:
Direct Zero Checks (manual dup + eq.0 pattern)
(This includes PR #2712)
dup.1 eq.0 dup.1 eq.0 and not assert.err=ERR_FOREIGN_ACCOUNT_ID_IS_ZERO
dup.1 eq.0 dup.1 eq.0 and
dup.1 eq.0 dup.1 eq.0 and
Using account_id::is_equal with pushed zeros
dup.1 dup.1 push.0 push.0 exec.account_id::is_equal
accounts.
dup.3 dup.3 push.0.0 exec.account_id::is_equal
assertz.err=ERR_TOKEN_NOT_REGISTERED