4#include <gmock/gmock.h>
5#include <gtest/gtest.h>
20using ::testing::ElementsAre;
21using ::testing::Return;
22using ::testing::ReturnRef;
23using ::testing::StrictMock;
25class DataCopySimulationTest :
public ::testing::Test {
27 DataCopySimulationTest()
29 ON_CALL(context, get_memory).WillByDefault(ReturnRef(mem));
32 EXPECT_CALL(context, get_memory());
33 EXPECT_CALL(execution_id_manager, get_execution_id());
34 EXPECT_CALL(context, get_context_id());
42 DataCopy
data_copy = DataCopy(execution_id_manager, gt, event_emitter);
47class NestedCdCopySimulationTest :
public DataCopySimulationTest {
49 NestedCdCopySimulationTest()
57 EXPECT_CALL(
context, get_parent_id());
58 EXPECT_CALL(
context, has_parent()).WillRepeatedly(Return(
true));
61 std::vector<FF>
calldata = { 1, 2, 3, 4, 5, 6, 7, 8 };
67TEST_F(NestedCdCopySimulationTest, CdZero)
70 uint32_t cd_copy_size = 0;
74 .WillOnce(Return(std::vector<FF>{}));
79 EXPECT_TRUE(c.as_ff().is_zero());
82TEST_F(NestedCdCopySimulationTest, CdCopyAll)
85 uint32_t cd_copy_size =
static_cast<uint32_t
>(
calldata.size());
87 EXPECT_CALL(context, get_calldata(
cd_offset, cd_copy_size)).WillOnce(Return(calldata));
93 std::vector<FF> calldata_in_memory;
94 for (uint32_t i = 0; i < cd_copy_size; ++i) {
96 calldata_in_memory.emplace_back(c.as_ff());
98 EXPECT_THAT(calldata_in_memory, ElementsAre(1, 2, 3, 4, 5, 6, 7, 8));
101TEST_F(NestedCdCopySimulationTest, CdCopyPartial)
104 uint32_t cd_copy_size = 2;
106 EXPECT_CALL(context, get_calldata(
cd_offset, cd_copy_size))
107 .WillOnce(Return(std::vector<FF>{ 1, 2 }));
112 std::vector<FF> calldata_in_memory;
113 for (uint32_t i = 0; i < cd_copy_size; ++i) {
115 calldata_in_memory.emplace_back(c.as_ff());
117 EXPECT_THAT(calldata_in_memory, ElementsAre(1, 2));
120TEST_F(NestedCdCopySimulationTest, CdFullWithPadding)
123 uint32_t cd_copy_size = 10;
125 std::vector<FF> expected_calldata = { 1, 2, 3, 4, 5, 6, 7, 8, 0, 0 };
126 EXPECT_CALL(context, get_calldata(
cd_offset, cd_copy_size)).WillOnce(Return(expected_calldata));
131 std::vector<FF> calldata_in_memory;
132 for (uint32_t i = 0; i < cd_copy_size; ++i) {
134 calldata_in_memory.emplace_back(c.as_ff());
136 EXPECT_THAT(calldata_in_memory, ElementsAre(1, 2, 3, 4, 5, 6, 7, 8, 0, 0));
139TEST_F(NestedCdCopySimulationTest, CdPartialWithPadding)
142 uint32_t cd_copy_size = 4;
145 std::vector<FF> expected_calldata = { 7, 8, 0, 0 };
147 EXPECT_CALL(context, get_calldata(
cd_offset, cd_copy_size)).WillOnce(Return(expected_calldata));
152 std::vector<FF> calldata_in_memory;
153 for (uint32_t i = 0; i < cd_copy_size; ++i) {
155 calldata_in_memory.emplace_back(c.as_ff());
157 EXPECT_THAT(calldata_in_memory, ElementsAre(7, 8, 0, 0));
160class RdCopySimulationTest :
public DataCopySimulationTest {
162 RdCopySimulationTest()
165 EXPECT_CALL(context, get_last_rd_addr()).WillRepeatedly(Return(child_rd_addr));
166 EXPECT_CALL(context, get_last_rd_size()).WillRepeatedly(Return(child_rd_size));
167 EXPECT_CALL(context, get_last_child_id()).WillRepeatedly(Return(child_context_id));
168 EXPECT_CALL(context, has_parent()).WillRepeatedly(Return(
true));
169 EXPECT_CALL(context, get_last_child_id()).WillRepeatedly(Return(2));
177TEST_F(RdCopySimulationTest, RdZero)
180 uint32_t rd_copy_size = 0;
181 uint32_t rd_offset = 0;
183 EXPECT_CALL(
context, get_returndata(rd_offset, rd_copy_size))
184 .WillOnce(Return(std::vector<FF>{}));
189 EXPECT_TRUE(c.as_ff().is_zero());
192TEST_F(RdCopySimulationTest, RdCopyAll)
195 uint32_t rd_copy_size =
static_cast<uint32_t
>(
returndata.size());
196 uint32_t rd_offset = 0;
198 EXPECT_CALL(context, get_returndata(rd_offset, rd_copy_size)).WillOnce(Return(
returndata));
203 std::vector<FF> returndata_in_memory;
204 for (uint32_t i = 0; i < rd_copy_size; ++i) {
206 returndata_in_memory.emplace_back(c.as_ff());
208 EXPECT_THAT(returndata_in_memory, ElementsAre(9, 10, 11, 12));
211TEST_F(RdCopySimulationTest, RdCopyPartial)
214 uint32_t rd_copy_size = 2;
215 uint32_t rd_offset = 1;
217 EXPECT_CALL(context, get_returndata(rd_offset, rd_copy_size))
218 .WillOnce(Return(std::vector<FF>{ 10, 11 }));
223 std::vector<FF> returndata_in_memory;
224 for (uint32_t i = 0; i < rd_copy_size; ++i) {
226 returndata_in_memory.emplace_back(c.as_ff());
228 EXPECT_THAT(returndata_in_memory, ElementsAre(10, 11));
231TEST_F(RdCopySimulationTest, RdFullWithPadding)
234 uint32_t rd_copy_size = 10;
235 uint32_t rd_offset = 0;
237 std::vector<FF> expected_returndata = { 9, 10, 11, 12, 0, 0, 0, 0, 0, 0 };
238 EXPECT_CALL(context, get_returndata(rd_offset, rd_copy_size)).WillOnce(Return(expected_returndata));
243 std::vector<FF> returndata_in_memory;
244 for (uint32_t i = 0; i < rd_copy_size; ++i) {
246 returndata_in_memory.emplace_back(c.as_ff());
248 EXPECT_THAT(returndata_in_memory, ElementsAre(9, 10, 11, 12, 0, 0, 0, 0, 0, 0));
251TEST_F(RdCopySimulationTest, RdPartialWithPadding)
254 uint32_t rd_copy_size = 4;
255 uint32_t rd_offset = 2;
257 std::vector<FF> expected_returndata = { 11, 12, 0, 0 };
259 EXPECT_CALL(context, get_returndata(rd_offset, rd_copy_size)).WillOnce(Return(expected_returndata));
264 std::vector<FF> returndata_in_memory;
265 for (uint32_t i = 0; i < rd_copy_size; ++i) {
267 returndata_in_memory.emplace_back(c.as_ff());
269 EXPECT_THAT(returndata_in_memory, ElementsAre(11, 12, 0, 0));
static TaggedValue from(T value)
void cd_copy(ContextInterface &context, const uint32_t cd_copy_size, const uint32_t cd_offset, const MemoryAddress dst_addr) override
Writes calldata into dst_addr. There is slight difference in how enqueued and nested contexts,...
void rd_copy(ContextInterface &context, const uint32_t rd_copy_size, const uint32_t rd_offset, const MemoryAddress dst_addr) override
Copies returndata from the last executed context to the dst_addr.
const MemoryValue & get(MemoryAddress index) const override
ExecutionIdManager execution_id_manager
EventEmitter< DataCopyEvent > event_emitter
StrictMock< MockContext > context
TEST_F(IPATest, ChallengesAreZero)
std::vector< FF > calldata
uint32_t child_context_id
std::vector< FF > returndata