1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
29using simulation::AluEvent;
30using simulation::AluException;
31using simulation::DeduplicatingEventEmitter;
32using simulation::EventEmitter;
33using simulation::FieldGreaterThan;
34using simulation::FieldGreaterThanEvent;
35using simulation::GreaterThan;
36using simulation::GreaterThanEvent;
37using simulation::RangeCheck;
38using simulation::RangeCheckEvent;
40using tracegen::AluTraceBuilder;
41using tracegen::FieldGreaterThanTraceBuilder;
42using tracegen::GreaterThanTraceBuilder;
43using tracegen::PrecomputedTraceBuilder;
44using tracegen::RangeCheckTraceBuilder;
46using tracegen::TestTraceContainer;
54class AluIntegrationTest :
public ::testing::Test {
82 void process_events(TestTraceContainer& trace)
96TEST_F(AluIntegrationTest, addBasicCase)
103 TestTraceContainer
trace;
104 process_events(trace);
105 check_relation<alu>(trace);
106 check_all_interactions<AluTraceBuilder>(trace);
109TEST_F(AluIntegrationTest, addWithTagMismatch)
116 TestTraceContainer
trace;
117 process_events(trace);
118 check_relation<alu>(trace);
119 check_all_interactions<AluTraceBuilder>(trace);
124TEST_F(AluIntegrationTest, subBasicCase)
131 TestTraceContainer
trace;
132 process_events(trace);
133 check_relation<alu>(trace);
134 check_all_interactions<AluTraceBuilder>(trace);
137TEST_F(AluIntegrationTest, subWithTagMismatch)
144 TestTraceContainer
trace;
145 process_events(trace);
146 check_relation<alu>(trace);
147 check_all_interactions<AluTraceBuilder>(trace);
152TEST_F(AluIntegrationTest, mulBasicCase)
159 TestTraceContainer
trace;
160 process_events(trace);
161 check_relation<alu>(trace);
162 check_all_interactions<AluTraceBuilder>(trace);
165TEST_F(AluIntegrationTest, mulWithTagU128Mismatch)
172 TestTraceContainer
trace;
173 process_events(trace);
174 check_relation<alu>(trace);
175 check_all_interactions<AluTraceBuilder>(trace);
179TEST_F(AluIntegrationTest, mulU128FuzzBug1Cf0)
182 uint256_t a_ff =
uint256_t(
"0x000000000000000000000000000000003c18fbdb47886300e90ed3f8e4b4b4b1");
183 uint256_t b_ff =
uint256_t(
"0x000000000000000000000000000000008eb2fbdb4724e898de03c8ed45033bb1");
192 TestTraceContainer
trace;
193 process_events(trace);
195 EXPECT_EQ(
trace.
get(Column::alu_cf, 0), 0);
197 check_relation<alu>(trace);
198 check_all_interactions<AluTraceBuilder>(trace);
201TEST_F(AluIntegrationTest, mulU128Cf1)
204 uint256_t a_ff =
uint256_t(
"0x00000000000000000000000000000000ff18fbdb47886300fffed3f8e4b4b4b1");
205 uint256_t b_ff =
uint256_t(
"0x00000000000000000000000000000000ffb2fbdb4724e898fff3c8ed45033bb1");
214 TestTraceContainer
trace;
215 process_events(trace);
217 EXPECT_EQ(
trace.
get(Column::alu_cf, 0), 1);
219 check_relation<alu>(trace);
220 check_all_interactions<AluTraceBuilder>(trace);
225TEST_F(AluIntegrationTest, divBasicCase)
232 TestTraceContainer
trace;
233 process_events(trace);
234 check_relation<alu>(trace);
235 check_all_interactions<AluTraceBuilder>(trace);
238TEST_F(AluIntegrationTest, divWithTagU128Mismatch)
245 TestTraceContainer
trace;
246 process_events(trace);
247 check_relation<alu>(trace);
248 check_all_interactions<AluTraceBuilder>(trace);
251TEST_F(AluIntegrationTest, divWithTagU128MismatchDivByZero)
258 TestTraceContainer
trace;
259 process_events(trace);
260 check_relation<alu>(trace);
261 check_all_interactions<AluTraceBuilder>(trace);
264TEST_F(AluIntegrationTest, divWithTagFFDivByZero)
271 TestTraceContainer
trace;
272 process_events(trace);
273 check_relation<alu>(trace);
274 check_all_interactions<AluTraceBuilder>(trace);
277TEST_F(AluIntegrationTest, divWithTagU128DivByZero)
284 TestTraceContainer
trace;
285 process_events(trace);
286 check_relation<alu>(trace);
287 check_all_interactions<AluTraceBuilder>(trace);
292TEST_F(AluIntegrationTest, fdivBasicCase)
299 TestTraceContainer
trace;
300 process_events(trace);
301 check_relation<alu>(trace);
302 check_all_interactions<AluTraceBuilder>(trace);
305TEST_F(AluIntegrationTest, fdivWithTagNotFF)
312 TestTraceContainer
trace;
313 process_events(trace);
314 check_relation<alu>(trace);
315 check_all_interactions<AluTraceBuilder>(trace);
318TEST_F(AluIntegrationTest, fdivWithTagNotFFDivByZero)
325 TestTraceContainer
trace;
326 process_events(trace);
327 check_relation<alu>(trace);
328 check_all_interactions<AluTraceBuilder>(trace);
331TEST_F(AluIntegrationTest, fdivDivByZero)
338 TestTraceContainer
trace;
339 process_events(trace);
340 check_relation<alu>(trace);
341 check_all_interactions<AluTraceBuilder>(trace);
346TEST_F(AluIntegrationTest, eqBasicCase)
353 TestTraceContainer
trace;
354 process_events(trace);
355 check_relation<alu>(trace);
356 check_all_interactions<AluTraceBuilder>(trace);
359TEST_F(AluIntegrationTest, eqWithTagFFMismatch)
366 TestTraceContainer
trace;
367 process_events(trace);
368 check_relation<alu>(trace);
369 check_all_interactions<AluTraceBuilder>(trace);
372TEST_F(AluIntegrationTest, eqWithTagU128Mismatch)
379 TestTraceContainer
trace;
380 process_events(trace);
381 check_relation<alu>(trace);
382 check_all_interactions<AluTraceBuilder>(trace);
386TEST_F(AluIntegrationTest, ltBasicCase)
393 TestTraceContainer
trace;
394 process_events(trace);
395 check_relation<alu>(trace);
396 check_all_interactions<AluTraceBuilder>(trace);
399TEST_F(AluIntegrationTest, ltWithTagU64Mismatch)
406 TestTraceContainer
trace;
407 process_events(trace);
408 check_relation<alu>(trace);
409 check_all_interactions<AluTraceBuilder>(trace);
412TEST_F(AluIntegrationTest, ltWithTagFFMismatch)
419 TestTraceContainer
trace;
420 process_events(trace);
421 check_relation<alu>(trace);
422 check_all_interactions<AluTraceBuilder>(trace);
427TEST_F(AluIntegrationTest, lteBasicCase)
434 TestTraceContainer
trace;
435 process_events(trace);
436 check_relation<alu>(trace);
437 check_all_interactions<AluTraceBuilder>(trace);
440TEST_F(AluIntegrationTest, lteWithTagU32Mismatch)
447 TestTraceContainer
trace;
448 process_events(trace);
449 check_relation<alu>(trace);
450 check_all_interactions<AluTraceBuilder>(trace);
453TEST_F(AluIntegrationTest, lteWithTagFFMismatch)
460 TestTraceContainer
trace;
461 process_events(trace);
462 check_relation<alu>(trace);
463 check_all_interactions<AluTraceBuilder>(trace);
468TEST_F(AluIntegrationTest, opNotBasicCase)
474 TestTraceContainer
trace;
475 process_events(trace);
476 check_relation<alu>(trace);
477 check_all_interactions<AluTraceBuilder>(trace);
480TEST_F(AluIntegrationTest, opNotWithTagFF)
486 TestTraceContainer
trace;
487 process_events(trace);
488 check_relation<alu>(trace);
489 check_all_interactions<AluTraceBuilder>(trace);
494TEST_F(AluIntegrationTest, shlBasicCase)
501 TestTraceContainer
trace;
502 process_events(trace);
503 check_relation<alu>(trace);
504 check_all_interactions<AluTraceBuilder>(trace);
507TEST_F(AluIntegrationTest, shlWithOverflowEdgeCase)
514 TestTraceContainer
trace;
515 process_events(trace);
516 check_relation<alu>(trace);
517 check_all_interactions<AluTraceBuilder>(trace);
520TEST_F(AluIntegrationTest, shlWithOverflowLargeShift)
527 TestTraceContainer
trace;
528 process_events(trace);
529 check_relation<alu>(trace);
530 check_all_interactions<AluTraceBuilder>(trace);
533TEST_F(AluIntegrationTest, shlWithTagFF)
540 TestTraceContainer
trace;
541 process_events(trace);
542 check_relation<alu>(trace);
543 check_all_interactions<AluTraceBuilder>(trace);
546TEST_F(AluIntegrationTest, shlWithTagFFMismatch)
553 TestTraceContainer
trace;
554 process_events(trace);
555 check_relation<alu>(trace);
556 check_all_interactions<AluTraceBuilder>(trace);
559TEST_F(AluIntegrationTest, shlWithTagU16Mismatch)
566 TestTraceContainer
trace;
567 process_events(trace);
568 check_relation<alu>(trace);
569 check_all_interactions<AluTraceBuilder>(trace);
574TEST_F(AluIntegrationTest, shrBasicCase)
582 TestTraceContainer
trace;
583 process_events(trace);
584 check_relation<alu>(trace);
585 check_all_interactions<AluTraceBuilder>(trace);
588TEST_F(AluIntegrationTest, shrWithOverflowEdgeCase)
596 TestTraceContainer
trace;
597 process_events(trace);
598 check_relation<alu>(trace);
599 check_all_interactions<AluTraceBuilder>(trace);
602TEST_F(AluIntegrationTest, shrWithOverflowLargeShift)
610 TestTraceContainer
trace;
611 process_events(trace);
612 check_relation<alu>(trace);
613 check_all_interactions<AluTraceBuilder>(trace);
616TEST_F(AluIntegrationTest, shrWithTagFF)
623 TestTraceContainer
trace;
624 process_events(trace);
625 check_relation<alu>(trace);
626 check_all_interactions<AluTraceBuilder>(trace);
629TEST_F(AluIntegrationTest, shrWithTagFFMismatch)
636 TestTraceContainer
trace;
637 process_events(trace);
638 check_relation<alu>(trace);
639 check_all_interactions<AluTraceBuilder>(trace);
642TEST_F(AluIntegrationTest, shrWithTagU16Mismatch)
649 TestTraceContainer
trace;
650 process_events(trace);
651 check_relation<alu>(trace);
652 check_all_interactions<AluTraceBuilder>(trace);
656TEST_F(AluIntegrationTest, truncateBasicCase)
662 TestTraceContainer
trace;
663 process_events(trace);
664 check_relation<alu>(trace);
665 check_all_interactions<AluTraceBuilder>(trace);
DeduplicatingEventEmitter< GreaterThanEvent > gt_emitter
DeduplicatingEventEmitter< FieldGreaterThanEvent > field_gt_emitter
FieldGreaterThan field_gt
AluTraceBuilder alu_trace_builder
DeduplicatingEventEmitter< RangeCheckEvent > range_check_emitter
EventEmitter< AluEvent > alu_emitter
static TaggedValue from_tag(ValueTag tag, FF value)
MemoryValue lte(const MemoryValue &a, const MemoryValue &b) override
Check if the first memory value is less than or equal to the second and emit an event of type AluEven...
MemoryValue fdiv(const MemoryValue &a, const MemoryValue &b) override
Perform field division on two memory values and emit an event of type AluEvent.
MemoryValue truncate(const FF &a, MemoryTag dst_tag) override
Truncate a field element to a specific memory tag and emit an event of type AluEvent.
MemoryValue eq(const MemoryValue &a, const MemoryValue &b) override
Check if two memory values are equal and emit an event of type AluEvent.
MemoryValue lt(const MemoryValue &a, const MemoryValue &b) override
Check if the first memory value is less than the second and emit an event of type AluEvent.
MemoryValue shl(const MemoryValue &a, const MemoryValue &b) override
Perform left shift operation on a memory value and emit an event of type AluEvent.
MemoryValue add(const MemoryValue &a, const MemoryValue &b) override
Add two memory values and emit an event of type AluEvent.
MemoryValue sub(const MemoryValue &a, const MemoryValue &b) override
Subtract two memory values and emit an event of type AluEvent.
MemoryValue mul(const MemoryValue &a, const MemoryValue &b) override
Multiply two memory values and emit an event of type AluEvent.
MemoryValue shr(const MemoryValue &a, const MemoryValue &b) override
Perform right shift operation on a memory value and emit an event of type AluEvent.
MemoryValue op_not(const MemoryValue &a) override
Perform bitwise NOT operation on a memory value and emit an event of type AluEvent.
MemoryValue div(const MemoryValue &a, const MemoryValue &b) override
Divide two memory values and emit an event of type AluEvent.
const FF & get(Column col, uint32_t row) const
RangeCheckTraceBuilder range_check_builder
PrecomputedTraceBuilder precomputed_builder
FieldGreaterThanTraceBuilder field_gt_builder
GreaterThanTraceBuilder gt_builder
TEST_F(AvmRecursiveTests, GoblinRecursion)
A test of the Goblinized AVM recursive verifier.
constexpr uint128_t MASK_64
unsigned __int128 uint128_t