1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
22using ::testing::TestWithParam;
25using simulation::UpdateCheckEvent;
27using tracegen::TestTraceContainer;
28using tracegen::UpdateCheckTraceBuilder;
36TEST(UpdateCheckConstrainingTest, EmptyRow)
41UpdateCheckEvent never_written = {
42 .address = 0xdeadbeef,
43 .current_class_id = 1,
44 .original_class_id = 1,
45 .current_timestamp = 100,
48UpdateCheckEvent never_updated = {
49 .address = 0xdeadbeef,
50 .current_class_id = 1,
51 .original_class_id = 1,
52 .current_timestamp = 100,
56UpdateCheckEvent update_from_original_next_timestamp = {
57 .address = 0xdeadbeef,
58 .current_class_id = 1,
59 .original_class_id = 1,
60 .current_timestamp = 100,
62 .update_preimage_metadata =
FF(
static_cast<uint64_t
>(1234) << 32) + 101,
63 .update_preimage_pre_class_id = 0,
64 .update_preimage_post_class_id = 2,
67UpdateCheckEvent update_next_timestamp = {
68 .address = 0xdeadbeef,
69 .current_class_id = 2,
70 .original_class_id = 1,
71 .current_timestamp = 100,
73 .update_preimage_metadata =
FF(
static_cast<uint64_t
>(1234) << 32) + 101,
74 .update_preimage_pre_class_id = 2,
75 .update_preimage_post_class_id = 3,
78UpdateCheckEvent update_previous_timestamp = {
79 .address = 0xdeadbeef,
80 .current_class_id = 3,
81 .original_class_id = 1,
82 .current_timestamp = 100,
84 .update_preimage_metadata =
FF(
static_cast<uint64_t
>(1234) << 32) + 99,
85 .update_preimage_pre_class_id = 2,
86 .update_preimage_post_class_id = 3,
89UpdateCheckEvent update_current_timestamp = {
90 .address = 0xdeadbeef,
91 .current_class_id = 3,
92 .original_class_id = 1,
93 .current_timestamp = 100,
95 .update_preimage_metadata =
FF(
static_cast<uint64_t
>(1234) << 32) + 100,
96 .update_preimage_pre_class_id = 2,
97 .update_preimage_post_class_id = 3,
103 update_from_original_next_timestamp,
104 update_next_timestamp,
105 update_previous_timestamp,
106 update_current_timestamp,
109class UpdateCheckPositiveConstrainingTest :
public TestWithParam<UpdateCheckEvent> {};
111TEST_P(UpdateCheckPositiveConstrainingTest, PositiveTest)
113 const auto&
event = GetParam();
114 TestTraceContainer
trace({ { { C::precomputed_first_row, 1 } } });
115 UpdateCheckTraceBuilder update_check_builder;
116 update_check_builder.process({
event },
trace);
117 check_relation<update_check_relation>(
trace);
121 UpdateCheckPositiveConstrainingTest,
122 ::testing::ValuesIn(positive_tests));
124TEST(UpdateCheckConstrainingTest, HashIsZeroCheck)
127 TestTraceContainer
trace({
129 { C::precomputed_first_row, 1 },
130 { C::update_check_sel, 1 },
131 { C::update_check_update_hash, 27 },
132 { C::update_check_hash_not_zero, 1 },
133 { C::update_check_update_hash_inv,
FF(27).invert() },
137 check_relation<update_check_relation>(
trace, update_check_relation::SR_HASH_IS_ZERO_CHECK);
140 trace.
set(C::update_check_hash_not_zero, 0, 0);
143 check_relation<update_check_relation>(
trace, update_check_relation::SR_HASH_IS_ZERO_CHECK),
144 "HASH_IS_ZERO_CHECK");
147TEST(UpdateCheckConstrainingTest, NeverUpdatedCheck)
150 TestTraceContainer
trace({
152 { C::precomputed_first_row, 1 },
153 { C::update_check_hash_not_zero, 0 },
154 { C::update_check_current_class_id, 1 },
155 { C::update_check_original_class_id, 1 },
159 check_relation<update_check_relation>(
trace, update_check_relation::SR_NEVER_UPDATED_CHECK);
162 trace.
set(C::update_check_current_class_id, 0, 2);
165 check_relation<update_check_relation>(
trace, update_check_relation::SR_NEVER_UPDATED_CHECK),
166 "NEVER_UPDATED_CHECK");
169TEST(UpdateCheckConstrainingTest, UpdateMetadataDecomposition)
172 TestTraceContainer
trace({
174 { C::precomputed_first_row, 1 },
175 { C::update_check_hash_not_zero, 1 },
176 { C::update_check_update_hi_metadata, 1234 },
177 { C::update_check_timestamp_of_change, 101 },
178 { C::update_check_update_preimage_metadata,
FF(
static_cast<uint64_t
>(1234) << 32) + 101 },
182 check_relation<update_check_relation>(
trace, update_check_relation::SR_UPDATE_METADATA_DECOMPOSITION);
185 trace.
set(C::update_check_timestamp_of_change, 0, 102);
188 check_relation<update_check_relation>(
trace, update_check_relation::SR_UPDATE_METADATA_DECOMPOSITION),
189 "UPDATE_METADATA_DECOMPOSITION");
192TEST(UpdateCheckConstrainingTest, UpdatePreClassIsZero)
196 TestTraceContainer
trace({
198 { C::precomputed_first_row, 1 },
199 { C::update_check_hash_not_zero, 1 },
200 { C::update_check_update_preimage_pre_class_id, 27 },
201 { C::update_check_update_pre_class_id_is_zero, 0 },
202 { C::update_check_update_pre_class_inv,
FF(27).invert() },
206 check_relation<update_check_relation>(
trace, update_check_relation::SR_UPDATE_PRE_CLASS_IS_ZERO);
209 trace.
set(C::update_check_update_pre_class_id_is_zero, 0, 1);
212 check_relation<update_check_relation>(
trace, update_check_relation::SR_UPDATE_PRE_CLASS_IS_ZERO),
213 "UPDATE_PRE_CLASS_IS_ZERO");
216TEST(UpdateCheckConstrainingTest, UpdatePostClassIsZero)
220 TestTraceContainer
trace({
222 { C::precomputed_first_row, 1 },
223 { C::update_check_hash_not_zero, 1 },
224 { C::update_check_update_preimage_post_class_id, 27 },
225 { C::update_check_update_post_class_id_is_zero, 0 },
226 { C::update_check_update_post_class_inv,
FF(27).invert() },
230 check_relation<update_check_relation>(
trace, update_check_relation::SR_UPDATE_POST_CLASS_IS_ZERO);
233 trace.
set(C::update_check_update_post_class_id_is_zero, 0, 1);
236 check_relation<update_check_relation>(
trace, update_check_relation::SR_UPDATE_POST_CLASS_IS_ZERO),
237 "UPDATE_POST_CLASS_IS_ZERO");
240TEST(UpdateCheckConstrainingTest, FutureUpdateClassIdAssignment)
244 TestTraceContainer
trace({
246 { C::precomputed_first_row, 1 },
247 { C::update_check_hash_not_zero, 1 },
248 { C::update_check_timestamp_is_lt_timestamp_of_change, 1 },
249 { C::update_check_original_class_id, 42 },
250 { C::update_check_update_preimage_pre_class_id, 27 },
251 { C::update_check_update_pre_class_id_is_zero, 0 },
252 { C::update_check_current_class_id, 27 },
256 check_relation<update_check_relation>(
trace, update_check_relation::SR_FUTURE_UPDATE_CLASS_ID_ASSIGNMENT);
259 trace.
set(C::update_check_update_pre_class_id_is_zero, 0, 1);
260 trace.
set(C::update_check_update_preimage_pre_class_id, 0, 0);
263 check_relation<update_check_relation>(
trace, update_check_relation::SR_FUTURE_UPDATE_CLASS_ID_ASSIGNMENT),
264 "FUTURE_UPDATE_CLASS_ID_ASSIGNMENT");
267 trace.
set(C::update_check_current_class_id, 0, 42);
268 check_relation<update_check_relation>(
trace, update_check_relation::SR_FUTURE_UPDATE_CLASS_ID_ASSIGNMENT);
271TEST(UpdateCheckConstrainingTest, PastUpdateClassIdAssignment)
276 TestTraceContainer
trace({
278 { C::precomputed_first_row, 1 },
279 { C::update_check_hash_not_zero, 1 },
280 { C::update_check_timestamp_is_lt_timestamp_of_change, 0 },
281 { C::update_check_original_class_id, 42 },
282 { C::update_check_update_preimage_post_class_id, 27 },
283 { C::update_check_update_post_class_id_is_zero, 0 },
284 { C::update_check_current_class_id, 27 },
288 check_relation<update_check_relation>(
trace, update_check_relation::SR_PAST_UPDATE_CLASS_ID_ASSIGNMENT);
291 trace.
set(C::update_check_update_post_class_id_is_zero, 0, 1);
292 trace.
set(C::update_check_update_preimage_post_class_id, 0, 0);
295 check_relation<update_check_relation>(
trace, update_check_relation::SR_PAST_UPDATE_CLASS_ID_ASSIGNMENT),
296 "PAST_UPDATE_CLASS_ID_ASSIGNMENT");
299 trace.
set(C::update_check_current_class_id, 0, 42);
300 check_relation<update_check_relation>(
trace, update_check_relation::SR_PAST_UPDATE_CLASS_ID_ASSIGNMENT);
INSTANTIATE_TEST_SUITE_P(AcirTests, AcirIntegrationSingleTest, testing::Values("a_1327_concrete_in_generic", "a_1_mul", "a_2_div", "a_3_add", "a_4_sub", "a_5_over", "a_6", "a_6_array", "a_7", "a_7_function", "aes128_encrypt", "arithmetic_binary_operations", "array_dynamic", "array_dynamic_blackbox_input", "array_dynamic_main_output", "array_dynamic_nested_blackbox_input", "array_eq", "array_if_cond_simple", "array_len", "array_neq", "array_sort", "array_to_slice", "array_to_slice_constant_length", "assert", "assert_statement", "assign_ex", "bigint", "bit_and", "bit_not", "bit_shifts_comptime", "bit_shifts_runtime", "blake3", "bool_not", "bool_or", "break_and_continue", "brillig_acir_as_brillig", "brillig_array_eq", "brillig_array_to_slice", "brillig_arrays", "brillig_assert", "brillig_bit_shifts_runtime", "brillig_blake2s", "brillig_blake3", "brillig_calls", "brillig_calls_array", "brillig_calls_conditionals", "brillig_conditional", "brillig_cow", "brillig_cow_assign", "brillig_cow_regression", "brillig_ecdsa_secp256k1", "brillig_ecdsa_secp256r1", "brillig_embedded_curve", "brillig_fns_as_values", "brillig_hash_to_field", "brillig_identity_function", "brillig_keccak", "brillig_loop", "brillig_nested_arrays", "brillig_not", "brillig_oracle", "brillig_pedersen", "brillig_recursion", "brillig_references", "brillig_schnorr", "brillig_sha256", "brillig_signed_cmp", "brillig_signed_div", "brillig_slices", "brillig_to_be_bytes", "brillig_to_bits", "brillig_to_bytes_integration", "brillig_to_le_bytes", "brillig_top_level", "brillig_uninitialized_arrays", "brillig_wrapping", "cast_bool", "closures_mut_ref", "conditional_1", "conditional_2", "conditional_regression_421", "conditional_regression_547", "conditional_regression_661", "conditional_regression_short_circuit", "conditional_regression_underflow", "custom_entry", "databus", "debug_logs", "diamond_deps_0", "double_verify_nested_proof", "double_verify_proof", "ecdsa_secp256k1", "ecdsa_secp256r1", "ecdsa_secp256r1_3x", "eddsa", "embedded_curve_ops", "field_attribute", "generics", "global_consts", "hash_to_field", "hashmap", "higher_order_functions", "if_else_chain", "import", "inline_never_basic", "integer_array_indexing", "keccak256", "main_bool_arg", "main_return", "merkle_insert", "missing_closure_env", "modules", "modules_more", "modulus", "nested_array_dynamic", "nested_array_dynamic_simple", "nested_array_in_slice", "nested_arrays_from_brillig", "no_predicates_basic", "no_predicates_brillig", "no_predicates_numeric_generic_poseidon", "operator_overloading", "pedersen_check", "pedersen_commitment", "pedersen_hash", "poseidon_bn254_hash", "poseidonsponge_x5_254", "pred_eq", "prelude", "references", "regression", "regression_2660", "regression_3051", "regression_3394", "regression_3607", "regression_3889", "regression_4088", "regression_4124", "regression_4202", "regression_4449", "regression_4709", "regression_5045", "regression_capacity_tracker", "regression_mem_op_predicate", "regression_method_cannot_be_found", "regression_struct_array_conditional", "schnorr", "sha256", "sha2_byte", "side_effects_constrain_array", "signed_arithmetic", "signed_comparison", "signed_division", "simple_2d_array", "simple_add_and_ret_arr", "simple_array_param", "simple_bitwise", "simple_comparison", "simple_mut", "simple_not", "simple_print", "simple_program_addition", "simple_radix", "simple_shield", "simple_shift_left_right", "slice_coercion", "slice_dynamic_index", "slice_loop", "slices", "strings", "struct", "struct_array_inputs", "struct_fields_ordering", "struct_inputs", "submodules", "to_be_bytes", "to_bytes_consistent", "to_bytes_integration", "to_le_bytes", "trait_as_return_type", "trait_impl_base_type", "traits_in_crates_1", "traits_in_crates_2", "tuple_inputs", "tuples", "type_aliases", "u128", "u16_support", "unconstrained_empty", "unit_value", "unsafe_range_constraint", "witness_compression", "xor"))
TEST_P(AcirIntegrationSingleTest, DISABLED_ProveAndVerifyProgram)
void set(Column col, uint32_t row, const FF &value)
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessage)
TEST(TxExecutionConstrainingTest, WriteTreeValue)
IndexedLeaf< PublicDataLeafValue > PublicDataTreeLeafPreimage
TestTraceContainer empty_trace()
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept