Repository navigation
fix(crypto): address audit findings in crypto module - #67
Federico2014 wants to merge 33 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
There was a problem hiding this comment.
All reported issues were addressed across 7 files (changes from recent commits).
Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 7 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
86ed474 to
3ffe91d
Compare
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
d16a321 to
3ed3ab1
Compare
ce09822 to
513467a
Compare
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
513467a to
cf8f5d4
Compare
What does this PR do?
Harden crypto helpers and keystore handling, and make BN128 coordinate and scalar-input assumptions explicit.
Keccak / digest engine
DigestEngineoverride. Reject null or incompatible destinations before modifying them, checking the Keccak type, algorithm, digest length, and internal block length.Keystore / wallet
CipherException; address/private-key consistency remains the caller's responsibility during creation.dklen.CREATE_NEWand 0600 permissions. Serialize through the creating channel, force the temporary file contents, close the channel, and replace the destination using the existing atomic-move/fallback behavior. Do not reopen the temporary path for writing.0xprefix inStringUtil.isHexadecimal, while rejecting non-ASCII hex.Blake2bf / ECKey / JCE
v = 29/30) separately from the precompile's component restrictions.vinECDSASignature.equalsandhashCode; makeMissingPrivateKeyExceptionanIllegalStateExceptionand clarify recovery exceptions.TronCastleProviderexplicitly in provider-less key-generation and raw-signature helpers, avoiding the JDK default provider's secp256k1 limitations.BN128 safety contracts
G2Homogeneousrunning-point type in the flipped Miller loop, initialized from an affine point, to keep homogeneous coordinates separate from Jacobian group operations.BN128.mul.Why are these changes required?
These changes address crypto audit findings: incomplete digest-state copies, retained buffers, lossy credential decoding, unsafe temporary-path reopening, and malformed inputs reaching cryptographic routines. They also make coordinate and validation contracts explicit.
Directory crash durability is outside this PR's scope. The wallet-write changes protect temporary-file creation and writing while preserving the base branch's directory handling.
This PR has been tested by:
Local validation used macOS with an x86_64/JDK 8 runtime:
WalletUtilsWriteTest,KeystoreCliUtilsTest,KeystoreNewTest,KeystoreImportTest, andKeystoreUpdateTest.FpTest,Fp12Test,PairingCheckTest, andIstanbulTest.altBn128PairingEnergyChangeTest. 17 tests passed../gradlew clean build -x test, the CI Checkstyle tasks (:framework:checkstyleMain :framework:checkstyleTest :plugins:checkstyleMain), the Math usage check, andgit diff --checkpassed.These focused runs overlap and do not represent a full-suite or multi-platform result.
Follow up
Extra details
Consensus impact
Review of
66540cd113againstrelease_v4.8.3at8d18edc4a6found no reachable change to block or transaction acceptance, TVM outputs, or Energy pricing. On this evidence, the change does not require a protocol activation height.z = 1check.The focused tests and differential comparisons above support this assessment. Historical block replay and mixed-version node validation have not been performed for this revision.
Compatibility and upgrade impact
dklen = 16. The new reader rejects both forms. If an SR uses such a file, startup fails withWITNESS_KEYSTORE_LOAD. Before upgrading an SR, unlock a copy of its configured keystore offline with the new version and verify the derived witness key address.Wallet.decrypt. CLI password files and piped input require valid UTF-8. Imported files with an absent or empty address can still be decrypted by path when their other fields are valid, but keystore discovery skips them.0600atomically at file creation. A temporary-file sync failure preserves the existing wallet. As on the base branch, directory entries can be lost after sudden power loss, and the wallet directory must be trusted.WalletUtils.getWalletFileNameis now private. Blake2bf cloning is unsupported.ECDSASignature.equalsandhashCodeinclude the recovery bytev, which can change deduplication results. The protected KeccakcopyStateparameter changes toDigestEngine. Downstream callers or subclasses using these APIs may need source changes or recompilation.