Repository navigation
Read Merkle paths and ASM the way @bsv/sdk 4.1.1 does - #16
Merged
Merged
Conversation
- A single-level path pairs the right-most node of each height with itself when it has no right neighbour, so full-block paths with an odd node count prove their root (MerklePath.ts:34, :380, :430, :671). - BUMP flags are read as a bitmask: bit 0 is a duplicate, otherwise bit 1 marks a txid. @bsv/sdk writes flags 3 for a marked duplicate. - Nodes above level zero must be siblings of a level-zero hash's ancestors (legalOffsetsOnly); new MerklePathError.illegalOffset. - MerklePath.verify returns false for a coinbase (offset 0) proof until the tracker's current height is 100 blocks above it. - Equal change distribution gives the division remainder to the last change output instead of paying it as fee. - Tests use the @bsv/sdk valid and invalid BUMP vectors and block 125632.
- New ScriptASMDialect.typeScript and ScriptASMStyle.typeScript, now the defaults. They use the OP.ts names (OP_0, OP_1, OP_SUBSTR..OP_RSHIFTNUM, OP_NOP9..OP_NOP77, OP_SMALLDATA), so ASM crossing between the SDKs keeps its bytes. BRC-106 and Go output stay available. - The TypeScript dialect reads -1, odd-length hex and OP_PUSHDATA1/2/4 <length> <hex>, which keeps its push opcode. - The TypeScript style prints zero-length pushes as OP_0 and names a top-level OP_RETURN, reading the bytes after it leniently. - New Opcode.typeScriptName and ScriptError.invalidASMPushDataLength. - COMP-022 records the decision.
…4.1.1 SPVProofVerifier.verify(_:rootTransactionID:...) now returns false when the walk reaches a proven coinbase (offset 0) less than 100 blocks below the tracker's currentHeight(), as @bsv/sdk Transaction.verify does through MerklePath.verify. The tip is fetched once, only when such a proof is reached. BEEF.verify still checks roots only, like Beef.verify. ChainTracker.currentHeight() now says it must be the real chain tip. ASM in the default TypeScript dialect: - raw data tokens must be lowercase, as @bsv/sdk rejects uppercase; the data token of OP_PUSHDATA* still accepts either case, as @bsv/sdk does - a trailing OP_PUSHDATA1/2/4 (or "OP_PUSHDATA1 0") is an empty push - the OP_PUSHDATA* length must be plain decimal, without leading zeros - docs and COMP-022 no longer say Swift writes exactly what 4.1.1 writes, list where it follows the unmerged @bsv/sdk fixes, and state that the lenient OP_RETURN tail is lossy for malformed pushes Also: the 32-bit push-length guard runs after the truncated-length check, invalidFlags is marked deprecated, legal offsets are only built for levels that hold nodes, and COMP-025 notes that a duplicate's txid bit is not kept. The previous Merkle commit also made applyFee give the change remainder to the last change output.
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.
Before: Swift rejected some BUMPs that @bsv/sdk 4.1.1 writes, accepted coinbase proofs under 100 blocks deep, and read and wrote ASM in a dialect that differs from TS (OP_FALSE/OP_TRUE, numbers as opcodes).
After: Merkle paths, coinbase maturity and ASM match @bsv/sdk 4.1.1 by default, with the remaining deliberate differences listed in COMP-022.
How: flags are read as a bitmask, upper-level offsets are checked like TS, full SPV verification checks coinbase maturity against
ChainTracker.currentHeight(), and the default ASM style and dialect are now.typeScript.Behaviour changes
asm()defaults to.typeScript: printsOP_0/OP_1, 0xb6 asOP_LSHIFTNUM, 0xb8 asOP_NOP9, zero-length pushes asOP_0; a malformed push after a top-level OP_RETURN prints lossily instead of throwing (usestyle: .canonicalfor the strict check).Script(asm:)defaults to.typeScript:1is data, odd hex gets a leading zero, raw hex must be lowercase,0and-1are opcodes,OP_PUSHDATA1/2/4 <len> <hex>keeps its opcode with a plain decimal length, a trailingOP_PUSHDATA*is an empty push, empty text is an empty script.MerklePathError.illegalOffset,ScriptError.invalidASMPushDataLength,.typeScriptonScriptASMStyleandScriptASMDialect.MerklePathError.invalidFlagsis deprecated and never thrown; a duplicate's txid bit is not kept when written back out.illegalOffsetfor upper-level nodes no level-zero hash needs.MerklePath.verifyand fullSPVProofVerifier.verifyreturn false for a coinbase proof under 100 blocks deep, soChainTracker.currentHeight()must return the real chain tip.BEEF.verifyis unchanged, as in TS.applyFeegives the equal-split change remainder to the last change output instead of the fee.Testing
swift testin swift:6.1 (Linux): 862 tests passed, XCTest 132 passed, 0 failures; only the live-network and opt-in tests skipped. Merged with main (PR 15 error text) and added theillegalOffsetdescription.