Repository navigation
fix: validate child_order and use child positions consistently in Go and Rust - #433
Open
citizen-stig wants to merge 2 commits into
Open
citizen-stig wants to merge 2 commits into
citizen-stig wants to merge 2 commits into
Conversation
`child_order.len() - 1` in ensure_inner and ensure_right_most underflowed when the spec had no child_order, which panics with overflow checks on. Found by the new fuzz target; verification now fails instead. Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
Specs must now have a child_order that is a permutation of 0..n with n >= 2, checked in both Go and Rust when the existence proof is checked against the spec. Rust get_padding used the matched child_order value as the position, while Go used getPosition; they agreed only for [0, 1]. Rust now looks up positions the same way Go does. leftBranchesAreEmpty / rightBranchesAreEmpty (and the Rust equivalents) assumed an identity order: for orders like merk's [0, 2, 1] they gave wrong answers and Go panicked with slice bounds out of range. Both now share a helper that looks up each sibling in the prefix or suffix by its position. Results for [0, 1] are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This PR does not match any of the 1 configured review trigger rule. |
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.
Follow-up to #429, addressing #429 (review). Includes #429's commit until that merges.
Problem
get_paddingused the matchedchild_ordervalue as the position (find(|&&x| x == branch)returnsbranch), while GogetPaddingusesgetPosition. The two agree only for[0, 1].child_orderis a permutation does not fix that by itself:[1, 0]is a valid permutation and still diverges.leftBranchesAreEmpty/rightBranchesAreEmpty(and the Rust equivalents) assume an identity order in both implementations. For orders like merk's[0, 2, 1], which the proto documents, they return wrong answers, and Go panics withslice bounds out of range.Changes
child_orderis a permutation of0..nwithn >= 2when an existence proof is checked against the spec. This replaces the empty-only check from fix(rust): reject specs with empty child_order #429.getPositiondoes.[0, 1]are unchanged.Breaking
Specs whose
child_orderis not a permutation of0..nwithn >= 2(including[0]) are now rejected. All shipped specs use[0, 1].Tests
TestEmptyBranchMerkOrder/check_empty_branch_merk_ordercover[0, 2, 1]. Both fail on the old code (Go panics).TestRejectInvalidChildOrder/reject_invalid_child_ordercover[],[0],[0,0],[0,2],[1,2]and[-1,0].go test ./...,cargo test(44 passed) andcargo clippy --all-targetsall pass.Not in scope
Other Go/Rust differences found while auditing, to be fixed in separate PRs:
size == 1check.HashOp/LengthOpvalues as their defaults instead of rejecting them.max_depthin proof specs as 128 if left to 0 #371.🤖 Generated with Claude Code