Skip to content

Add account_id MASM helper to test for zero #2863

@PhilippGackstatter

Description

@PhilippGackstatter

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)

  1. 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
  2. Asserts foreign account ID is not zero by testing both elements.
  3. crates/miden-standards/asm/standards/access/ownable2step.masm:253
    dup.1 eq.0 dup.1 eq.0 and
  4. Checks if nominated owner is zero (cancellation of ownership transfer).
  5. crates/miden-standards/asm/standards/access/ownable2step.masm:297
    dup.1 eq.0 dup.1 eq.0 and
  6. Checks if nominated owner is zero to verify a transfer exists.

Using account_id::is_equal with pushed zeros

  1. crates/miden-protocol/asm/kernels/transaction/lib/account.masm:1831
    dup.1 dup.1 push.0 push.0 exec.account_id::is_equal
  2. Compares account ID with (0, 0) to detect uninitialized memory blocks when loading foreign
    accounts.
  3. 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
  4. Validates that a faucet ID from registry is not zero (token is registered).

Metadata

Metadata

Assignees

No one assigned

    Labels

    kernelsRelated to transaction, batch, or block kernels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions