Skip to content
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

fix: minimum 1 bit for constant binary decomposition #1229

Merged
merged 3 commits into from
Jul 31, 2024

Conversation

gbotrel
Copy link
Collaborator

@gbotrel gbotrel commented Jul 29, 2024

Description

Fixes an edge case introduced by #1228 ; thanks to @wuestholz for reporting.

@gbotrel gbotrel added the fuzzing Issue found using a fuzzing tool label Jul 29, 2024
@gbotrel gbotrel requested a review from ivokub July 29, 2024 19:56
@ivokub
Copy link
Collaborator

ivokub commented Jul 31, 2024

Suggested edit:

diff --git a/internal/regression_tests/issue1227/issue_1227_test.go b/internal/regression_tests/issue1227/issue_1227_test.go
index 3315f54d..a9342995 100644
--- a/internal/regression_tests/issue1227/issue_1227_test.go
+++ b/internal/regression_tests/issue1227/issue_1227_test.go
@@ -8,17 +8,22 @@ import (
 )
 
 type Circuit struct {
-	X frontend.Variable
+	constVal int
+	X        frontend.Variable
 }
 
 func (circuit *Circuit) Define(api frontend.API) error {
-	api.AssertIsLessOrEqual(1, circuit.X)
+	api.AssertIsLessOrEqual(circuit.constVal, circuit.X)
 	return nil
 }
 
 func TestConstantPath(t *testing.T) {
 	assert := test.NewAssert(t)
-	assert.CheckCircuit(&Circuit{},
+	assert.CheckCircuit(&Circuit{constVal: 1},
 		test.WithValidAssignment(&Circuit{X: 1}),   // 1 <= 1 --> true
 		test.WithInvalidAssignment(&Circuit{X: 0})) // 1 <= 0 --> false
+	// test edge case where constant is 0
+	assert.CheckCircuit(&Circuit{constVal: 0},
+		test.WithValidAssignment(&Circuit{X: 1}), // 0 <= 1 --> true
+		test.WithValidAssignment(&Circuit{X: 0})) // 0 <= 0 --> true
 }

Copy link
Collaborator

@ivokub ivokub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Suggested edit for catching regressions in the future.

@gbotrel gbotrel merged commit d8ccab5 into master Jul 31, 2024
4 checks passed
@gbotrel gbotrel deleted the fix/mustBeLessOrEqVar branch July 31, 2024 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuzzing Issue found using a fuzzing tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants