fix(abi,utils): harden decoder input bounds and crypto argument valid - #219
Merged
kuny0707 merged 2 commits intoJul 22, 2026
Merged
Conversation
…ation ABI decoder (abi): lengths and offsets read from untrusted return data / event logs are bounds-checked before use. decodeUintAsInt rejects values above Integer.MAX_VALUE; dynamic bytes and array lengths are capped by the remaining input before shifting or pre-allocation; slot and parameter-window reads share a checkWindowBounds helper covering both the constructor-reflection and runtime-TypeReference struct decoding engines; offset arithmetic uses Math.multiplyExact. Malformed input now fails fast with IllegalArgumentException instead of integer overflow, StringIndexOutOfBoundsException, NegativeArraySizeException, or an oversized memory pre-allocation. Covered by TypeDecoderDoSTest. SECP256K1 utilities (utils): no-op assert argument checks are replaced with production-active Preconditions validation, PrivateKey.toString() is redacted (explicit export via toStringWithPrivateKey()), and PrivateKey.create tolerates an optional 0x prefix.
… precedence The array rejection in decodeArrayElements checks four conditions but reported only the length; the message now includes length, offset and input length. Parenthesize the 0x-prefix condition in PrivateKey.create to make the evaluation order explicit.
317787106
approved these changes
Jul 22, 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.
What does this PR do?
abimodule): adds bounds checks, applied before use, for the lengths and offsets read from untrusted return data / event logs. Malformed input now fails fast with a uniformIllegalArgumentExceptioninstead of integer overflow,StringIndexOutOfBoundsException,NegativeArraySizeException, or an oversized memory pre-allocation (DoS).utilsmodule): replaces the no-opassertargument checks with production-activePreconditionsvalidation, and redactsPrivateKey.toString()so the raw key can no longer leak through logs (explicit export moved totoStringWithPrivateKey()).Why are these changes required?
This PR has been tested by:
Follow up
Extra details
assert→Preconditionschange, the following arguments go from "silently accepted" to "throwing" in production:Signature.decoderequires exactly 65 bytes,PublicKeyrequires exactly 64 bytes,recoverFromSignaturerequiresrecId ≥ 0and non-negativer/s, etc. This is the fail-fast behavior the audit asked for and is an expected behavior change.PrivateKey.toString()now returns a redacted constant. Any code that relied ontoString()to export/persist the raw private key should switch totoStringWithPrivateKey()(which returns hex without the0xprefix).PrivateKey.create(String)still requires 64 hex chars (an optional0xprefix is allowed); calls that previously passed an invalid length by relying on the no-opassertwill now fail explicitly.