-
Notifications
You must be signed in to change notification settings - Fork 615
fix: smt_verification: negative bitvecs, changed gates indicies. acir_formal_proofs: noir-style signed division #11649
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
711e138
fix_negative
defkit 55b1bfe
Merge remote-tracking branch 'origin/master' into sn/fix_negative_bv_…
defkit f2ed1bb
smt solver goes brrrrrrr
defkit 691f4a6
dummy commit to restart CI that failed for no reason...
defkit a33a3de
battle between me and CI. Im losing
defkit 6be0d4c
comments
defkit b7076d5
Merge remote-tracking branch 'origin/master' into sn/fix_negative_bv_…
defkit e9646d8
bitvec extracts brrrbimbimbambam
defkit 53387ac
delete truncate func
defkit fc4163f
clear test
defkit cfabdea
tests + readme
defkit 536af25
added comments
defkit ee568cb
amogus
defkit 3f0a4b1
Merge remote-tracking branch 'origin/master' into sn/fix_negative_bv_…
defkit 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 |
|---|---|---|
|
|
@@ -44,20 +44,51 @@ smt_circuit::STerm shr(smt_circuit::STerm v0, smt_circuit::STerm v1, smt_solver: | |
| return res; | ||
| } | ||
|
|
||
| smt_circuit::STerm truncate(smt_circuit::STerm v0, uint32_t bit_size, smt_solver::Solver* solver) | ||
| { | ||
| smt_circuit::STerm power = smt_terms::BVConst(std::to_string(bit_size), solver, 10); | ||
| auto mask = pow2_8(power, solver); | ||
| return v0 & (mask - 1); | ||
| } | ||
|
|
||
| smt_circuit::STerm shl64(smt_circuit::STerm v0, smt_circuit::STerm v1, smt_solver::Solver* solver) | ||
| { | ||
| auto shifted = shl(v0, v1, solver); | ||
| // 2^64 - 1 | ||
| auto mask = smt_terms::BVConst("18446744073709551615", solver, 10); | ||
| auto res = shifted & mask; | ||
| /*auto mask = smt_terms::BVConst("18446744073709551615", solver, 10); | ||
|
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. are these comments necessary? |
||
| auto res = shifted & mask;*/ | ||
| auto res = truncate(shifted, 64, solver); | ||
| return res; | ||
| } | ||
|
|
||
| smt_circuit::STerm shl32(smt_circuit::STerm v0, smt_circuit::STerm v1, smt_solver::Solver* solver) | ||
| { | ||
| auto shifted = shl(v0, v1, solver); | ||
| // 2^32 - 1 | ||
| auto mask = smt_terms::BVConst("4294967295", solver, 10); | ||
| auto res = shifted & mask; | ||
| auto res = truncate(shifted, 32, solver); | ||
| return res; | ||
| } | ||
|
|
||
| smt_circuit::STerm idiv(smt_circuit::STerm v0, smt_circuit::STerm v1, uint32_t bit_size, smt_solver::Solver* solver) | ||
| { | ||
| // highest bit of v0 and v1 is sign bit | ||
| smt_circuit::STerm exponent = smt_terms::BVConst(std::to_string(bit_size), solver, 10); | ||
| // because pow(2, 0) == 1 | ||
| auto mask_abs_value = pow2_8(exponent - 1, solver); | ||
| auto sign_bit_v0 = v0 & mask_abs_value; | ||
| auto sign_bit_v1 = v1 & mask_abs_value; | ||
| auto res_sign_bit = sign_bit_v0 ^ sign_bit_v1; | ||
| auto abs_value_v0 = truncate(v0, bit_size - 1, solver); | ||
| auto abs_value_v1 = truncate(v1, bit_size - 1, solver); | ||
| auto abs_res = abs_value_v0 / abs_value_v1; | ||
|
|
||
| // if abs_value_v0 == 0 then res = 0 | ||
| // in our context we use idiv only once, so static name for the division result okay. | ||
| auto res = smt_terms::BVVar("res_signed_division", solver); | ||
| auto condition = smt_terms::Bool(abs_value_v0, solver) == smt_terms::Bool(smt_terms::BVConst("0", solver, 10)); | ||
| auto eq1 = condition & (smt_terms::Bool(res, solver) == smt_terms::Bool(smt_terms::BVConst("0", solver, 10))); | ||
| auto eq2 = !condition & (smt_terms::Bool(res, solver) == smt_terms::Bool(res_sign_bit | abs_res, solver)); | ||
|
|
||
| (eq1 | eq2).assert_term(); | ||
|
|
||
| return res; | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -30,18 +30,18 @@ UltraCircuit::UltraCircuit( | |
| // add gate in its normal state to solver | ||
|
|
||
| size_t arith_cursor = 0; | ||
| while (arith_cursor < this->selectors[1].size()) { | ||
|
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. Please add an entry to |
||
| arith_cursor = this->handle_arithmetic_relation(arith_cursor, 1); | ||
| while (arith_cursor < this->selectors[2].size()) { | ||
| arith_cursor = this->handle_arithmetic_relation(arith_cursor, 2); | ||
| } | ||
|
|
||
| size_t lookup_cursor = 0; | ||
| while (lookup_cursor < this->selectors[5].size()) { | ||
| lookup_cursor = this->handle_lookup_relation(lookup_cursor, 5); | ||
| while (lookup_cursor < this->selectors[1].size()) { | ||
| lookup_cursor = this->handle_lookup_relation(lookup_cursor, 1); | ||
| } | ||
|
|
||
| size_t elliptic_cursor = 0; | ||
| while (elliptic_cursor < this->selectors[3].size()) { | ||
| elliptic_cursor = this->handle_elliptic_relation(elliptic_cursor, 3); | ||
| while (elliptic_cursor < this->selectors[4].size()) { | ||
| elliptic_cursor = this->handle_elliptic_relation(elliptic_cursor, 4); | ||
| } | ||
|
|
||
| // size_t delta_range_cursor = 0; | ||
|
|
@@ -88,7 +88,7 @@ size_t UltraCircuit::handle_arithmetic_relation(size_t cursor, size_t idx) | |
|
|
||
| std::vector<bb::fr> boolean_gate = { 1, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }; | ||
| bool boolean_gate_flag = | ||
| (boolean_gate == selectors[1][cursor]) && (w_l_idx == w_r_idx) && (w_o_idx == 0) && (w_4_idx == 0); | ||
| (boolean_gate == selectors[idx][cursor]) && (w_l_idx == w_r_idx) && (w_o_idx == 0) && (w_4_idx == 0); | ||
| if (boolean_gate_flag) { | ||
| (Bool(w_l) == Bool(STerm(0, this->solver, this->type)) | Bool(w_l) == Bool(STerm(1, this->solver, this->type))) | ||
| .assert_term(); | ||
|
|
@@ -292,7 +292,7 @@ size_t UltraCircuit::handle_elliptic_relation(size_t cursor, size_t idx) | |
| y_add_identity == 0; // scaling_factor = 1 | ||
| } | ||
|
|
||
| bb::fr curve_b = this->selectors[3][cursor][11]; | ||
| bb::fr curve_b = this->selectors[idx][cursor][11]; | ||
| auto x_pow_4 = (y1_sqr - curve_b) * x_1; | ||
| auto y1_sqr_mul_4 = y1_sqr + y1_sqr; | ||
| y1_sqr_mul_4 += y1_sqr_mul_4; | ||
|
|
||
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
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.
Regarding the
pow2_8, you should use bit_extraction rather then direct& 1value