// Hand-optimized TASM baseline: std.crypto.auth
// Implements: verify_preimage, verify_digest_preimage, lock_and_read_kernel
//
// Calling convention: arguments pushed left-to-right (first arg deepest).
// Digest = 5 field elements (d0 deepest, d4 on top of the group).
//
// Instruction count rules:
//   - Comments (// ...) NOT counted
//   - Labels (ending with :) NOT counted
//   - halt NOT counted
//   - Blank lines NOT counted
//   - Everything else counted (including return)

// ---------------------------------------------------------------
// verify_preimage(expected: Digest)
//   14 instructions
//
// Stack on entry: [exp4 exp3 exp2 exp1 exp0 ...]
// Algorithm: divine 1 secret, pad 9 zeros, hash, assert match
// After hash: [comp4..comp0 exp4..exp0 ...] -- assert_vector ready
// ---------------------------------------------------------------
__verify_preimage:
    divine 1
    push 0
    push 0
    push 0
    push 0
    push 0
    push 0
    push 0
    push 0
    push 0
    hash
    assert_vector
    pop 5
    return

// ---------------------------------------------------------------
// verify_digest_preimage(expected: Digest)
//   10 instructions
//
// Stack on entry: [exp4 exp3 exp2 exp1 exp0 ...]
// Algorithm: divine 5-element secret, pad 5 zeros, hash, assert
// ---------------------------------------------------------------
__verify_digest_preimage:
    divine 5
    push 0
    push 0
    push 0
    push 0
    push 0
    hash
    assert_vector
    pop 5
    return

// ---------------------------------------------------------------
// lock_and_read_kernel(lock_postimage: Digest) -> Digest
//   3 instructions
//
// Stack on entry: [d4 d3 d2 d1 d0 ...]
// Algorithm: verify digest preimage, read kernel hash from public input
// Stack on exit: [k4 k3 k2 k1 k0 ...]
// ---------------------------------------------------------------
__lock_and_read_kernel:
    call __verify_digest_preimage
    read_io 5
    return

Neighbours