Asset introspection pushes LE64 instead of scriptNum#49
Conversation
🔍 PR Review — Asset introspection pushes LE64 instead of scriptNumCorrectness fix: ✅ This is a solid and necessary change. What looks good
Observations
VerdictClean, well-motivated fix with thorough test coverage. The only design question worth discussing is the asymmetric stack depth on lookup (point 2 above). Everything else LGTM. |
| // opcodeInspectOutAssetLookup pops gidx, txid, and output index o, then looks up the asset amount. | ||
| // Pushes the amount if found, or -1 if not found. | ||
| // Found: pushes 1 (success flag) then the amount as 8-byte LE64. | ||
| // Not found: pushes 0 (failure flag only — no amount on stack). |
There was a problem hiding this comment.
| // Not found: pushes 0 (failure flag only — no amount on stack). | |
| // Not found: pushes -1 (failure flag only — no amount on stack). |
why not -1 to be consistent with other opcodes ?
| // opcodeInspectInAssetLookup pops gidx, txid, and input index i, then looks up the asset amount. | ||
| // Pushes the amount if found, or -1 if not found. | ||
| // Found: pushes 1 (success flag) then the amount as 8-byte LE64. | ||
| // Not found: pushes 0 (failure flag only — no amount on stack). |
There was a problem hiding this comment.
| // Not found: pushes 0 (failure flag only — no amount on stack). | |
| // Not found: pushes -1 (failure flag only — no amount on stack). |
|
let's update also README (and the spec : https://github.com/ArkLabsHQ/arkade-assets/tree/master in parallel) |
|
The the reason I don't really like -1 is that OP_IF doesn't accept it (not minimal encoding) and that OP_VERIFY doesn't fail on -1. Assets with amount of 0 aren't a problem, since flag value is unrelated to the amount value. |
|
I think it would be overall a better idea an cleaner to use 0 values, since they're actually falsy. Currently there are 3 more opcodes that use -1 as a sentinel value for missing stuff:
OP_INSPECT_X_SCRIPTPUBKEY opcodes are a special case here and can be left the way it is. Others can use a missing 0 flag to stay consistent. Only the opcodes relating to asset amounts need the two stack element handling. Also I agree with the comment raised by Arkana:
I think pushing 2 elements for these consistently makes it more ergonomic without too much overhead. |
🔍 PR Review (updated commits) — Asset introspection pushes LE64 instead of scriptNumReviewing new changes since What changed since last reviewThe feedback on asymmetric stack depth has been addressed:
All of these are improvements over the initial version. ✅ Minor observations
Test coverageNew tests for large amounts (3B, 7B, 10B sums), LE64→ VerdictThe updated commits address all prior feedback. Consistent stack shapes, clean LE64 encoding, solid test coverage. LGTM pending the spec updates in arkade-assets. |
🔍 PR Review (commit
|
|
Updated the missing-value handling to use explicit tagged results with the What changed:
Why:
Example: |
|
Follow-up review ( Good correction. The previous commits pushed the flag first (buried under the payload), requiring scripts to Affected opcodes and their new stack-top layout (top → bottom):
Tests updated consistently — the assertions now pop the flag first, verify it, then check the values underneath. LGTM on this commit. |
This PR fixes asset amount handling in asset introspection opcodes by moving amount values from
scriptNumto 8-byte little-endian (LE64) stack values, and updates lookup semantics to a flag+value pattern.Why
Asset amounts are defined as
uint64, but previously they were pushed asscriptNum(int64) and later parsed with a 4-byteMakeScriptNumlimit viaPopInt(). That created correctness bugs for larger amounts:2^63-1could wrap on cast toint642^31-1could fail withErrNumberTooBigwhen re-read as script numbersWhat changed
asset_opcodes.goand switched amount pushes to LE64 for:OP_INSPECTASSETGROUP(input/output amount fields)OP_INSPECTASSETGROUPSUMOP_INSPECTOUTASSETATOP_INSPECTINASSETATOP_INSPECTOUTASSETLOOKUPOP_INSPECTINASSETLOOKUP1then<amount LE64>0onlytest/utils_test.goto compare asset sums as LE64.Script ergonomics improvement (Issue #40)
Using asset lookup amounts is now simpler and more consistent with 64-bit ops, matching the direction in Issue #40:
-1sentinel handling boilerplateOP_SCRIPTNUMTOLE64conversion step beforeOP_ADD64/OP_MUL64/ comparisonsOP_VERIFY), with amount already in LE64Edge cases covered
Added explicit tests for large amounts and arithmetic/comparison interoperability:
OP_ADD64OP_GREATERTHANOREQUAL64Breaking change / migration note
This is a breaking stack-shape/encoding change for scripts using asset amount outputs:
scriptNum.flag + amount(found) orflagonly (not found), replacing the old-1sentinel behavior.