refactor: Clean exitPaths in base.ts#338
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughCompute each tap leaf script once and select decoders via new isScriptValid checks instead of exception-driven decode fallbacks; tapscript decoders gained centralized validation helpers (including getVerifyIndex and CLTV locktime handling), and per-leaf decode errors are caught and logged with console.debug. Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/script/base.ts`:
- Around line 129-138: The truthiness check on
CSVMultisigTapscript.isScriptValid and
ConditionCSVMultisigTapscript.isScriptValid is incorrect because those functions
can return Error objects (which are truthy); change each conditional to first
assign the result to a variable (e.g., const isValid =
CSVMultisigTapscript.isScriptValid(script)) and then explicitly check if isValid
is an instance of Error (skip/continue) or if it is === true before calling
CSVMultisigTapscript.decode(script); apply the same pattern for
ConditionCSVMultisigTapscript to avoid calling decode when validation failed.
In `@src/script/tapscript.ts`:
- Around line 744-747: The error message for the locktime type check is
misleading: when inspecting const locktime = asm[0] the code rejects strings and
numbers but currently says "expected locktime number"; change that message to
accurately state the expected type (e.g., "Invalid script: expected locktime as
Uint8Array" or "Invalid script: expected locktime buffer") so it matches the
expectation of MinimalScriptNum.decode and clarifies that a Uint8Array/Buffer is
required; update the message in the locktime type-check branch that references
locktime/asm[0].
- Around line 416-418: In isScriptValid replace the thrown exception with an
Error return so the function respects its boolean | Error contract: change the
branch that currently does "throw new Error(`Invalid script: too short (expected
at least 3)`)” to instead "return new Error(...)" so callers receive an Error
value; locate this in the asm length check inside isScriptValid in tapscript.ts
and mirror the style used by the other validation branches.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e8085457-74a8-43b6-ad60-0930e21fbb93
📒 Files selected for processing (2)
src/script/base.tssrc/script/tapscript.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/script/tapscript.ts`:
- Around line 744-747: The validation in Script.decode erroneously rejects
numeric locktimes (asm[0]) even though encode emits a number for single-byte
locktimes; update Script.decode to accept both number and byte-array forms for
locktime (do not treat typeof locktime === "number" as invalid) and mirror
CSVMultisigTapscript.isScriptValid/its decode handling: allow numbers, reject
only strings, and normalize the numeric case into the same internal
representation used elsewhere (or convert numbers to the expected byte
representation before further processing).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1f671979-c4aa-44ce-ae18-e11aed0f2076
📒 Files selected for processing (2)
src/script/base.tssrc/script/tapscript.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/script/tapscript.ts`:
- Around line 535-540: The reverse scan that finds the delimiter currently
continues after finding a "VERIFY", causing verifyIndex to point to the leftmost
match; change the loop that sets verifyIndex in the function using the asm
reverse-scan so it breaks immediately when asm[i] === "VERIFY" (i.e., stop on
the first match from the end) and apply the identical early-break change to the
reverse-scans in ConditionCSVMultisigTapscript.decode() and
ConditionMultisigTapscript.decode() so validation and decoding use the same
rightmost VERIFY delimiter.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 30fee71b-646b-4189-b52c-099eb3ea2b67
📒 Files selected for processing (1)
src/script/tapscript.ts
🔍 Review:
|
🔍 Arkana Review —
|
Review: Clean exitPaths in base.tsProtocol correctness: ✅ Security analysis:
Key improvements:
Minor note: Ensure the ✅ Ready to merge. |
@louisinger, @Kukks, @pietro909
Summary by CodeRabbit