Add missing OP_CAT result size check#100
Merged
Merged
Conversation
There was a problem hiding this comment.
✅ Approved — clean consensus fix
Verdict: Approve. This is a correct, well-tested fix for a real consensus violation and DoS vector.
Code review
pkg/arkade/opcode.go:2157-2162 — the fix:
- Check placement is correct: before
appendand beforePushByteArray, so the oversized element never touches the stack. - Uses
>(not>=), so 520-byte results are correctly allowed. Matches theMaxScriptElementSizesemantics used everywhere else. len(x1)+len(x2)cannot overflow: individual elements are already capped at 520 by the engine push-data check (engine.go:289), so the sum maxes at 1040 — well withinintrange.- Pattern exactly matches the existing checks in
opcodeInspectPacket(opcode.go:2937) andopcodeInspectInputPacket(opcode.go:2999). Consistent. - No other element-producing opcodes are missing this check: AND/OR/XOR require equal-length operands and produce same-size output; Substr/Left/Right only shrink; BigNum ops go through
PushBigNumwhich is bounded bymaxBigNumLen.
pkg/arkade/opcode_test.go — unit tests:
result_at_max_element_size: 260+260=520 valid boundary. ✓result_exceeds_max_element_size: 300+300=600ErrElementTooBig. ✓
pkg/arkade/engine_test.go — integration test:
OP_CAT_growth_limit: 200→400→800 viaOP_DUP OP_CATloop. Proves the exponential-growth DoS path is killed. ✓
pkg/arkade/opcode_test.go:1518 — fuzz harness update:
ErrElementTooBigadded tobyteTransformPropertyCheckeraccepted errors. Prevents false-positive fuzz failures. ✓
Cross-repo impact
None. Internal opcode handler change only. No public API, proto, or type changes.
🤖 Reviewed by Arkana
louisinger
approved these changes
Jun 16, 2026
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.
Enforce stack element size limit in OP_CAT
Problem:
OP_CATconcatenated two operands and pushed the result without checking it againstMaxScriptElementSize(520 bytes). Two valid ≤520-byte elements could produce up to 1040 bytes, and repeatedOP_DUP OP_CATdoubles the element each round — an unbounded exponential-growth DoS and a consensus-rule violation. It was the only element-producing opcode missing this check (all splice/bitwise/arithmetic/hash/introspection ops are already bounded).Fix: Reject the operation with
ErrElementTooBigwhenlen(x1)+len(x2) > MaxScriptElementSize, matching the pattern already used by the packet-introspection opcodes.Tests:
OP_CAT_growth_limitproves the repeated-doubling attack now fails.