Write an unnamed opcode in ASM as its raw byte, 0xba - #4
Merged
Merged
Conversation
@smartledger/bsv 9.11.1 writes an opcode with no name as 0xba and reads it back from ASM. exactAsm wrote OP_UNKNOWN186, which nothing reads, so it refused any script holding one. It now writes 0xba; the read-back check still refuses such scripts where an older @smartledger/bsv is installed. Tests run against 9.11.1.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Owner
Author
|
Reviewed and checked locally:
On the |
This was referenced Sep 17, 2026
codenlighten
added a commit
to codenlighten/smartledger-bsv
that referenced
this pull request
Sep 17, 2026
toASM and toString wrote nothing for an empty data push. For one encoded with
OP_PUSHDATA1/2/4 (4c00), ASM dropped the push, so 514c0051 read back as 5151,
one stack element fewer, and toString wrote a bare OP_PUSHDATA1 that
fromString could not read. The empty push Script#add(Buffer.alloc(0)) builds,
and so buildDataOut(''), serializes to 0x00 but was written as nothing, so
6a00 read back as 6a.
ASM now writes an empty push minimally, as 0. toString writes
OP_PUSHDATA1 0 0x for the PUSHDATA encodings, which fromString already read,
and OP_0 otherwise, as it already did for 0x00 parsed from bytes. Four tests
had pinned the invisible form; they now assert the text reads back.
No reader changes. Of 4,000 generated scripts, the 909 whose text changed all
contain an empty push and all read back exactly; every text 9.11.1 wrote is
read the same way.
Reported in codenlighten/scriptmin#4.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #3, after @smartledger/bsv 9.11.1 (codenlighten/smartledger-bsv#175).
Change
toAsm(ops, { bare: true }), and soexactAsmand--asm -o, writes an opcode with no name (0xba–0xfc) as0xba, the form bsv 9.11.1 writes and reads. It used to writeOP_UNKNOWN186, which nothing reads, so every such script was refused.fromASM('0xba')throws, so the script is still refused, and the message now says which version reads it back.--explain,--jsonrewrites) still showsOP_UNKNOWN186.^9.11.1, so CI tests against it. The peer range stays^9.10.1.Tests
51ba6a05aabbccddee→OP_1 0xba OP_RETURN aabbccddee, and it reads back byte for byte.npm test: 28/28 on 9.11.1.Review of bsv 9.11.1 (#175)
Round-trip fuzz against the npm 9.11.1 package: every unnamed opcode, direct/
OP_PUSHDATA1/OP_PUSHDATA2/OP_PUSHDATA4pushes,OP_0, and the empty script.toASM→fromASM(29k scripts with minimal pushes)toString→fromString(29k scripts)toString→fromString, no emptyOP_PUSHDATA(25.5k)Every remaining
toStringfailure has the same cause, and 9.11.0 has it too: an empty push written withOP_PUSHDATA1/2/4(4c00) prints as a bareOP_PUSHDATA1with no length or data.fromStringthen throws (Cannot read properties of undefined (reading 'slice')orPushdata data must start with 0x) or misreads the next token. Writing it asOP_PUSHDATA1 0 0xwould needfromStringto accept an empty0x.