Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ under the rules before Chronicle as well as after it.
- **ASM cannot hold every script.** It does not record how data was pushed, so
`--asm -o` refuses a result with a non-minimal push (optimized code is
minimal, but `OP_0 OP_IF` blocks and data after `OP_RETURN` are kept
verbatim), a truncated push, an unnamed opcode, or only data pushes, rather
verbatim), a truncated push, an unnamed opcode with `@smartledger/bsv` older
than 9.11.1, or only data pushes, rather
than write a different script.
Hex and `--binary` output are always exact.
- **Signatures commit to the script.** `OP_CHECKSIG` signs the script code, so
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
"@smartledger/bsv": "^9.10.1"
},
"devDependencies": {
"@smartledger/bsv": "^9.11.0"
"@smartledger/bsv": "^9.11.1"
}
}
7 changes: 5 additions & 2 deletions src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ function toAsm (ops, { maxData = 0, bare = false } = {}) {
const shown = maxData && hex.length > maxData * 2 ? hex.slice(0, maxData * 2) + '…' : hex
return op.code >= OP.OP_PUSHDATA1 && !bare ? `${opName(op.code)}:${shown}` : shown
}
// An opcode with no name is written as its raw byte, as @smartledger/bsv
// writes it (and reads it back from 9.11.1).
if (bare && !NAMES[op.code]) return '0x' + op.code.toString(16).padStart(2, '0')
return opName(op.code)
}).join(' ')
}
Expand Down Expand Up @@ -229,8 +232,8 @@ function exactAsm (buf) {
? 'it contains a truncated push'
: ops.some(o => isPush(o) && o.code !== TAIL && opSize(pushOp(pushValue(o))) !== opSize(o))
? 'a push is not minimally encoded, and ASM cannot say how data was pushed'
: /OP_UNKNOWN|\bOP_INVALIDOPCODE\b/.test(asm) || ops.some(o => o.code >= 0 && !isPush(o) && !NAMES[o.code])
? 'it uses an opcode that has no name in ASM'
: ops.some(o => o.code >= 0 && !isPush(o) && !NAMES[o.code])
? 'it uses an opcode that has no name, which @smartledger/bsv reads back from ASM only from 9.11.1'
: !/\bOP_/.test(asm)
? 'it is only data pushes, and ASM with no opcodes reads back as hex'
: 'its ASM reads back as a different script'
Expand Down
2 changes: 2 additions & 0 deletions test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ test('ASM output reads back byte for byte, or is refused', () => {
assert.ok(toBuffer(exactAsm(buf)).equals(buf), src)
}
assert.throws(() => exactAsm(Buffer.from('4c03aabbcc51', 'hex')), /not minimally encoded/)
// An unnamed opcode is written as its raw byte, 0xba.
assert.strictEqual(exactAsm(Buffer.from('51ba6a05aabbccddee', 'hex')), 'OP_1 0xba OP_RETURN aabbccddee')
assert.throws(() => exactAsm(Buffer.from('516a05aabb', 'hex')), /truncated push/)
assert.throws(() => exactAsm(Buffer.from('4c50' + 'ab'.repeat(80), 'hex')), /only data pushes/)

Expand Down
Loading