-
Notifications
You must be signed in to change notification settings - Fork 265
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
feat: Several Updates in SMT verification module (part 1) #10437
Merged
+414
−77
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6cb7fb2
Added post processing functionality to symbolic circuit
Sarkoxed 3910c9e
Added finalized flag to schema
Sarkoxed 855a907
Use post processing to calculate final witness for standard standard …
Sarkoxed c6ab952
Adding comments + switching to get_random_uint32
Sarkoxed d59ead6
switching to engine
Sarkoxed ab5fd16
Adding a description for circuit simulation
Sarkoxed 82fe2bf
Adding comments to the tests
Sarkoxed c474fb7
adding one extra comment
Sarkoxed 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 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 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
211 changes: 182 additions & 29 deletions
211
barretenberg/cpp/src/barretenberg/smt_verification/circuit/standard_circuit.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -376,3 +376,144 @@ TEST(standard_circuit, check_double_xor_bug) | |
Solver s(circuit_info.modulus, default_solver_config, 16, 64); | ||
StandardCircuit circuit(circuit_info, &s, TermType::BVTerm); | ||
} | ||
|
||
// Check that witness provided by the solver is the same as builder's witness | ||
// Check that all the optimized out values are initialized and computed properly during post proccessing | ||
TEST(standard_circuit, optimized_range_witness) | ||
{ | ||
uint32_t rbit = engine.get_random_uint8() & 1; | ||
uint32_t num_bits = 32 + rbit; | ||
info(num_bits); | ||
|
||
StandardCircuitBuilder builder; | ||
field_t a = witness_t(&builder, engine.get_random_uint256() % (uint256_t(1) << num_bits)); | ||
builder.create_range_constraint(a.get_witness_index(), num_bits); | ||
builder.set_variable_name(a.get_witness_index(), "a"); | ||
|
||
CircuitSchema circuit_info = unpack_from_buffer(builder.export_circuit()); | ||
Solver s(circuit_info.modulus, default_solver_config, 16, 64); | ||
StandardCircuit circuit(circuit_info, &s, TermType::BVTerm); | ||
|
||
circuit["a"] == a.get_value(); | ||
|
||
bool res = smt_timer(&s); | ||
ASSERT_TRUE(res); | ||
auto model_witness = default_model_single({ "a" }, circuit, "optimized_range_check.out"); | ||
|
||
ASSERT_EQ(model_witness.size(), builder.get_num_variables()); | ||
for (size_t i = 0; i < model_witness.size(); i++) { | ||
ASSERT_EQ(model_witness[i], builder.variables[i]); | ||
} | ||
} | ||
|
||
// Check that witness provided by the solver is the same as builder's witness | ||
// Check that all the optimized out values are initialized and computed properly during post proccessing | ||
TEST(standard_circuit, optimized_logic_witness) | ||
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. What is this test doing? |
||
{ | ||
StandardCircuitBuilder builder; | ||
uint_ct a = witness_t(&builder, engine.get_random_uint32()); | ||
builder.set_variable_name(a.get_witness_index(), "a"); | ||
uint_ct b = witness_t(&builder, engine.get_random_uint32()); | ||
builder.set_variable_name(b.get_witness_index(), "b"); | ||
uint_ct c = a ^ b; | ||
uint_ct d = a & b; | ||
builder.set_variable_name(c.get_witness_index(), "c"); | ||
builder.set_variable_name(d.get_witness_index(), "d"); | ||
|
||
CircuitSchema circuit_info = unpack_from_buffer(builder.export_circuit()); | ||
Solver s(circuit_info.modulus, default_solver_config, 16, 64); | ||
StandardCircuit circuit(circuit_info, &s, TermType::BVTerm); | ||
|
||
circuit["a"] == a.get_value(); | ||
circuit["b"] == b.get_value(); | ||
|
||
bool res = smt_timer(&s); | ||
ASSERT_TRUE(res); | ||
auto model_witness = default_model_single({ "a", "b", "c", "d" }, circuit, "optimized_xor_check.out"); | ||
|
||
ASSERT_EQ(model_witness.size(), builder.get_num_variables()); | ||
for (size_t i = 0; i < model_witness.size(); i++) { | ||
ASSERT_EQ(model_witness[i], builder.variables[i]); | ||
} | ||
} | ||
|
||
// Check that witness provided by the solver is the same as builder's witness | ||
// Check that all the optimized out values are initialized and computed properly during post proccessing | ||
TEST(standard_circuit, optimized_shr_witness) | ||
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. What are all these tests doing? |
||
{ | ||
StandardCircuitBuilder builder; | ||
uint_ct a = witness_t(&builder, engine.get_random_uint32()); | ||
builder.set_variable_name(a.get_witness_index(), "a"); | ||
uint_ct b = a >> 0; | ||
for (uint32_t i = 1; i < 32; i++) { | ||
b = a >> i; | ||
} | ||
|
||
CircuitSchema circuit_info = unpack_from_buffer(builder.export_circuit()); | ||
Solver s(circuit_info.modulus, default_solver_config, 16, 64); | ||
StandardCircuit circuit(circuit_info, &s, TermType::BVTerm); | ||
|
||
circuit["a"] == a.get_value(); | ||
bool res = smt_timer(&s); | ||
ASSERT_TRUE(res); | ||
auto model_witness = default_model_single({ "a" }, circuit, "optimized_xor_check.out"); | ||
|
||
ASSERT_EQ(model_witness.size(), builder.get_num_variables()); | ||
for (size_t i = 0; i < model_witness.size(); i++) { | ||
EXPECT_EQ(model_witness[i], builder.variables[i]); | ||
} | ||
} | ||
|
||
// Check that witness provided by the solver is the same as builder's witness | ||
// Check that all the optimized out values are initialized and computed properly during post proccessing | ||
TEST(standard_circuit, optimized_shl_witness) | ||
{ | ||
StandardCircuitBuilder builder; | ||
uint_ct a = witness_t(&builder, engine.get_random_uint32()); | ||
builder.set_variable_name(a.get_witness_index(), "a"); | ||
uint_ct b = a << 0; | ||
for (uint32_t i = 1; i < 32; i++) { | ||
b = a << i; | ||
} | ||
|
||
CircuitSchema circuit_info = unpack_from_buffer(builder.export_circuit()); | ||
Solver s(circuit_info.modulus, default_solver_config, 16, 64); | ||
StandardCircuit circuit(circuit_info, &s, TermType::BVTerm); | ||
|
||
circuit[a.get_witness_index()] == a.get_value(); | ||
bool res = smt_timer(&s); | ||
ASSERT_TRUE(res); | ||
auto model_witness = default_model_single({ "a" }, circuit, "optimized_xor_check.out"); | ||
|
||
ASSERT_EQ(model_witness.size(), builder.get_num_variables()); | ||
for (size_t i = 0; i < model_witness.size(); i++) { | ||
EXPECT_EQ(model_witness[i], builder.variables[i]); | ||
} | ||
} | ||
|
||
// Check that witness provided by the solver is the same as builder's witness | ||
// Check that all the optimized out values are initialized and computed properly during post proccessing | ||
TEST(standard_circuit, optimized_ror_witness) | ||
{ | ||
StandardCircuitBuilder builder; | ||
uint_ct a = witness_t(&builder, engine.get_random_uint32()); | ||
builder.set_variable_name(a.get_witness_index(), "a"); | ||
uint_ct b = a.ror(0); | ||
for (uint32_t i = 1; i < 32; i++) { | ||
b = a.ror(i); | ||
} | ||
|
||
CircuitSchema circuit_info = unpack_from_buffer(builder.export_circuit()); | ||
Solver s(circuit_info.modulus, default_solver_config, 16, 64); | ||
StandardCircuit circuit(circuit_info, &s, TermType::BVTerm); | ||
|
||
circuit[a.get_witness_index()] == a.get_value(); | ||
bool res = smt_timer(&s); | ||
ASSERT_TRUE(res); | ||
auto model_witness = default_model_single({ "a" }, circuit, "optimized_xor_check.out"); | ||
|
||
ASSERT_EQ(model_witness.size(), builder.get_num_variables()); | ||
for (size_t i = 0; i < model_witness.size(); i++) { | ||
EXPECT_EQ(model_witness[i], builder.variables[i]); | ||
} | ||
} |
This file contains 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 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.
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.
What does this test do?