-
Notifications
You must be signed in to change notification settings - Fork 593
fix!: claude-generated pre-audit for bitwise in avm - soundness bug and edge-case tests #19247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -579,5 +579,91 @@ TEST(BitwiseConstrainingTest, ExecBitwiseDispatchOnErrorFF) | |
| check_interaction<ExecutionTraceBuilder, lookup_execution_dispatch_to_bitwise_settings>(trace); | ||
| } | ||
|
|
||
| // ========================================================================= | ||
| // Audit-generated edge case tests | ||
| // ========================================================================= | ||
|
|
||
| // Tests that start_sha256 must be boolean (0 or 1). | ||
| // This test verifies that the constraint `start_sha256 * (1 - start_sha256) = 0` is enforced. | ||
| TEST(BitwiseConstrainingTest, NegativeStartSha256NonBoolean) | ||
| { | ||
| // Test with start_sha256 = 2 (non-boolean value) | ||
| TestTraceContainer trace({ | ||
| { | ||
| { C::bitwise_start_sha256, 2 }, // Non-boolean value should fail | ||
| }, | ||
| }); | ||
|
|
||
| // Subrelation 3 is: start_sha256 * (1 - start_sha256) = 0 | ||
| EXPECT_THROW_WITH_MESSAGE(check_relation<bitwise>(trace, 3UL), ""); | ||
| } | ||
|
|
||
| // Tests that start_keccak must be boolean | ||
| TEST(BitwiseConstrainingTest, NegativeStartKeccakNonBoolean) | ||
| { | ||
| TestTraceContainer trace({ | ||
| { | ||
| { C::bitwise_start_keccak, 2 }, // Non-boolean value should fail | ||
| }, | ||
| }); | ||
|
|
||
| // Subrelation 2 is: start_keccak * (1 - start_keccak) = 0 | ||
| EXPECT_THROW_WITH_MESSAGE(check_relation<bitwise>(trace, 2UL), ""); | ||
| } | ||
|
|
||
| // Edge case: XOR of identical values should yield 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think that the 3 following tests are really edge cases (we precompute) but we can keep them as "sanity test vectors". |
||
| TEST(BitwiseConstrainingTest, XorIdenticalValuesYieldsZero) | ||
| { | ||
| TestTraceContainer trace; | ||
| BitwiseTraceBuilder builder; | ||
|
|
||
| std::vector<simulation::BitwiseEvent> events = { | ||
| { .operation = BitwiseOperation::XOR, | ||
| .a = MemoryValue::from<uint32_t>(0xDEADBEEF), | ||
| .b = MemoryValue::from<uint32_t>(0xDEADBEEF), | ||
| .res = 0 }, // x XOR x = 0 | ||
| }; | ||
|
|
||
| builder.process(events, trace); | ||
|
|
||
| check_relation<bitwise>(trace); | ||
| } | ||
|
|
||
| // Edge case: OR with all 1s should yield all 1s | ||
| TEST(BitwiseConstrainingTest, OrWithMaxValue) | ||
| { | ||
| TestTraceContainer trace; | ||
| BitwiseTraceBuilder builder; | ||
|
|
||
| std::vector<simulation::BitwiseEvent> events = { | ||
| { .operation = BitwiseOperation::OR, | ||
| .a = MemoryValue::from<uint32_t>(0xFFFFFFFF), | ||
| .b = MemoryValue::from<uint32_t>(0x12345678), | ||
| .res = 0xFFFFFFFF }, | ||
| }; | ||
|
|
||
| builder.process(events, trace); | ||
|
|
||
| check_relation<bitwise>(trace); | ||
| } | ||
|
|
||
| // Edge case: AND with 0 should yield 0 | ||
| TEST(BitwiseConstrainingTest, AndWithZero) | ||
| { | ||
| TestTraceContainer trace; | ||
| BitwiseTraceBuilder builder; | ||
|
|
||
| std::vector<simulation::BitwiseEvent> events = { | ||
| { .operation = BitwiseOperation::AND, | ||
| .a = MemoryValue::from<uint32_t>(0xDEADBEEF), | ||
| .b = MemoryValue::from<uint32_t>(0x00000000), | ||
| .res = 0 }, | ||
| }; | ||
|
|
||
| builder.process(events, trace); | ||
|
|
||
| check_relation<bitwise>(trace); | ||
| } | ||
|
|
||
| } // namespace | ||
| } // namespace bb::avm2::constraining | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to keep these two boolean checks then we should use an alias for the sub-relation instead of calling
check_relation<bitwise>(trace, 3UL)with an integer literal.