1+ #include < cstdio>
12#include < gmock/gmock.h>
23#include < gtest/gtest.h>
34
@@ -1388,29 +1389,43 @@ TEST(EccAddMemoryConstrainingTest, InfinityRepresentations)
13881389 check_relation<ecc>(trace);
13891390 EXPECT_EQ (trace.get (C::ecc_double_op, 0 ), 1 );
13901391
1392+ ecc_simulator.add (memory, inf, inf_bb, dst_address);
1393+
1394+ // Set memory reads:
1395+ trace.set (0 ,
1396+ { { // Execution
1397+ { C::execution_sel, 1 },
1398+ { C::execution_sel_exec_dispatch_ecc_add, 1 },
1399+ { C::execution_rop_6_, dst_address + 3 },
1400+ { C::execution_register_0_, inf.x () },
1401+ { C::execution_register_1_, inf.y () },
1402+ { C::execution_register_2_, inf.is_infinity () ? 1 : 0 },
1403+ { C::execution_register_3_, inf_bb.x () },
1404+ { C::execution_register_4_, inf_bb.y () },
1405+ { C::execution_register_5_, inf_bb.is_infinity () ? 1 : 0 },
1406+ // GT - dst out of range check
1407+ { C::gt_sel, 1 },
1408+ { C::gt_input_a, dst_address + 2 },
1409+ { C::gt_input_b, AVM_HIGHEST_MEM_ADDRESS },
1410+ { C::gt_res, 0 } } });
1411+
1412+ builder.process_add_with_memory (ecc_add_memory_event_emitter.dump_events (), trace);
1413+
1414+ // The derived is_inf column must be true if the coordinates are (0, 0):
1415+ trace.set (C::ecc_add_mem_p_is_inf, 0 , 0 );
1416+ EXPECT_THROW_WITH_MESSAGE (check_relation<mem_aware_ecc>(trace, mem_aware_ecc::SR_P_CURVE_EQN ), " P_CURVE_EQN" );
1417+
1418+ // If is_if is set, the coordinates must be (0, 0):
1419+ trace.set (C::ecc_add_mem_q_x, 0 , 1 );
1420+ trace.set (C::ecc_add_mem_q_y, 0 , 2 );
1421+ EXPECT_THROW_WITH_MESSAGE (check_relation<mem_aware_ecc>(trace, mem_aware_ecc::SR_Q_INF_X_CHECK ), " Q_INF_X_CHECK" );
1422+ EXPECT_THROW_WITH_MESSAGE (check_relation<mem_aware_ecc>(trace, mem_aware_ecc::SR_Q_INF_Y_CHECK ), " Q_INF_Y_CHECK" );
1423+
13911424 // TODO(#AVM-266): Rework test when is_infinity flag is removed from point representations.
13921425 // We now derive is_inf from coordinates, whereas previously we remapped coordinates /from/ is_inf.
13931426 // The below test no longer makes sense since it checks we store non-(0,0) coordinates for an inf
13941427 // point, which we do not allow.
13951428
1396- // // Set memory reads:
1397- // trace.set(0,
1398- // { { // Execution
1399- // { C::execution_sel, 1 },
1400- // { C::execution_sel_exec_dispatch_ecc_add, 1 },
1401- // { C::execution_rop_6_, dst_address + 3 },
1402- // { C::execution_register_0_, inf.x() },
1403- // { C::execution_register_1_, inf.y() },
1404- // { C::execution_register_2_, inf.is_infinity() ? 1 : 0 },
1405- // { C::execution_register_3_, inf_bb.x() },
1406- // { C::execution_register_4_, inf_bb.y() },
1407- // { C::execution_register_5_, inf_bb.is_infinity() ? 1 : 0 },
1408- // // GT - dst out of range check
1409- // { C::gt_sel, 1 },
1410- // { C::gt_input_a, dst_address + 2 },
1411- // { C::gt_input_b, AVM_HIGHEST_MEM_ADDRESS },
1412- // { C::gt_res, 0 } } });
1413-
14141429 // builder.process_add_with_memory(ecc_add_memory_event_emitter.dump_events(), trace);
14151430
14161431 // // The original coordinates are stored in memory for the read...
@@ -1422,7 +1437,8 @@ TEST(EccAddMemoryConstrainingTest, InfinityRepresentations)
14221437 // check_relation<mem_aware_ecc>(trace);
14231438 // check_relation<ecc>(trace);
14241439 // check_all_interactions<EccTraceBuilder>(trace);
1425- // check_interaction<tracegen::ExecutionTraceBuilder, bb::avm2::perm_execution_dispatch_to_ecc_add_settings>(trace);
1440+ // check_interaction<tracegen::ExecutionTraceBuilder,
1441+ // bb::avm2::perm_execution_dispatch_to_ecc_add_settings>(trace);
14261442}
14271443
14281444} // namespace
0 commit comments