4#include <gmock/gmock.h>
5#include <gtest/gtest.h>
19using ::testing::ElementsAre;
20using ::testing::Return;
21using ::testing::ReturnRef;
22using ::testing::StrictMock;
24class DataCopySimulationTest :
public ::testing::Test {
26 DataCopySimulationTest()
28 ON_CALL(context, get_memory).WillByDefault(ReturnRef(mem));
31 EXPECT_CALL(context, get_memory());
32 EXPECT_CALL(execution_id_manager, get_execution_id());
33 EXPECT_CALL(context, get_context_id());
41 DataCopy
data_copy = DataCopy(execution_id_manager, gt, event_emitter);
46class NestedCdCopySimulationTest :
public DataCopySimulationTest {
48 NestedCdCopySimulationTest()
56 EXPECT_CALL(
context, get_parent_id());
57 EXPECT_CALL(
context, has_parent()).WillRepeatedly(Return(
true));
60 std::vector<FF>
calldata = { 1, 2, 3, 4, 5, 6, 7, 8 };
66TEST_F(NestedCdCopySimulationTest, CdZero)
69 uint32_t cd_copy_size = 0;
73 .WillOnce(Return(std::vector<FF>{}));
78 EXPECT_TRUE(c.as_ff().is_zero());
81TEST_F(NestedCdCopySimulationTest, CdCopyAll)
84 uint32_t cd_copy_size =
static_cast<uint32_t
>(
calldata.size());
86 EXPECT_CALL(context, get_calldata(
cd_offset, cd_copy_size)).WillOnce(Return(calldata));
92 std::vector<FF> calldata_in_memory;
93 for (uint32_t i = 0; i < cd_copy_size; ++i) {
95 calldata_in_memory.emplace_back(c.as_ff());
97 EXPECT_THAT(calldata_in_memory, ElementsAre(1, 2, 3, 4, 5, 6, 7, 8));
100TEST_F(NestedCdCopySimulationTest, CdCopyPartial)
103 uint32_t cd_copy_size = 2;
105 EXPECT_CALL(context, get_calldata(
cd_offset, cd_copy_size))
106 .WillOnce(Return(std::vector<FF>{ 1, 2 }));
111 std::vector<FF> calldata_in_memory;
112 for (uint32_t i = 0; i < cd_copy_size; ++i) {
114 calldata_in_memory.emplace_back(c.as_ff());
116 EXPECT_THAT(calldata_in_memory, ElementsAre(1, 2));
119TEST_F(NestedCdCopySimulationTest, CdFullWithPadding)
122 uint32_t cd_copy_size = 10;
124 std::vector<FF> expected_calldata = { 1, 2, 3, 4, 5, 6, 7, 8, 0, 0 };
125 EXPECT_CALL(context, get_calldata(
cd_offset, cd_copy_size)).WillOnce(Return(expected_calldata));
130 std::vector<FF> calldata_in_memory;
131 for (uint32_t i = 0; i < cd_copy_size; ++i) {
133 calldata_in_memory.emplace_back(c.as_ff());
135 EXPECT_THAT(calldata_in_memory, ElementsAre(1, 2, 3, 4, 5, 6, 7, 8, 0, 0));
138TEST_F(NestedCdCopySimulationTest, CdPartialWithPadding)
141 uint32_t cd_copy_size = 4;
144 std::vector<FF> expected_calldata = { 7, 8, 0, 0 };
146 EXPECT_CALL(context, get_calldata(
cd_offset, cd_copy_size)).WillOnce(Return(expected_calldata));
151 std::vector<FF> calldata_in_memory;
152 for (uint32_t i = 0; i < cd_copy_size; ++i) {
154 calldata_in_memory.emplace_back(c.as_ff());
156 EXPECT_THAT(calldata_in_memory, ElementsAre(7, 8, 0, 0));
159class RdCopySimulationTest :
public DataCopySimulationTest {
161 RdCopySimulationTest()
164 EXPECT_CALL(context, get_last_rd_addr()).WillRepeatedly(Return(child_rd_addr));
165 EXPECT_CALL(context, get_last_rd_size()).WillRepeatedly(Return(child_rd_size));
166 EXPECT_CALL(context, get_last_child_id()).WillRepeatedly(Return(child_context_id));
167 EXPECT_CALL(context, has_parent()).WillRepeatedly(Return(
true));
168 EXPECT_CALL(context, get_last_child_id()).WillRepeatedly(Return(2));
176TEST_F(RdCopySimulationTest, RdZero)
179 uint32_t rd_copy_size = 0;
180 uint32_t rd_offset = 0;
182 EXPECT_CALL(
context, get_returndata(rd_offset, rd_copy_size))
183 .WillOnce(Return(std::vector<FF>{}));
188 EXPECT_TRUE(c.as_ff().is_zero());
191TEST_F(RdCopySimulationTest, RdCopyAll)
194 uint32_t rd_copy_size =
static_cast<uint32_t
>(
returndata.size());
195 uint32_t rd_offset = 0;
197 EXPECT_CALL(context, get_returndata(rd_offset, rd_copy_size)).WillOnce(Return(
returndata));
202 std::vector<FF> returndata_in_memory;
203 for (uint32_t i = 0; i < rd_copy_size; ++i) {
205 returndata_in_memory.emplace_back(c.as_ff());
207 EXPECT_THAT(returndata_in_memory, ElementsAre(9, 10, 11, 12));
210TEST_F(RdCopySimulationTest, RdCopyPartial)
213 uint32_t rd_copy_size = 2;
214 uint32_t rd_offset = 1;
216 EXPECT_CALL(context, get_returndata(rd_offset, rd_copy_size))
217 .WillOnce(Return(std::vector<FF>{ 10, 11 }));
222 std::vector<FF> returndata_in_memory;
223 for (uint32_t i = 0; i < rd_copy_size; ++i) {
225 returndata_in_memory.emplace_back(c.as_ff());
227 EXPECT_THAT(returndata_in_memory, ElementsAre(10, 11));
230TEST_F(RdCopySimulationTest, RdFullWithPadding)
233 uint32_t rd_copy_size = 10;
234 uint32_t rd_offset = 0;
236 std::vector<FF> expected_returndata = { 9, 10, 11, 12, 0, 0, 0, 0, 0, 0 };
237 EXPECT_CALL(context, get_returndata(rd_offset, rd_copy_size)).WillOnce(Return(expected_returndata));
242 std::vector<FF> returndata_in_memory;
243 for (uint32_t i = 0; i < rd_copy_size; ++i) {
245 returndata_in_memory.emplace_back(c.as_ff());
247 EXPECT_THAT(returndata_in_memory, ElementsAre(9, 10, 11, 12, 0, 0, 0, 0, 0, 0));
250TEST_F(RdCopySimulationTest, RdPartialWithPadding)
253 uint32_t rd_copy_size = 4;
254 uint32_t rd_offset = 2;
256 std::vector<FF> expected_returndata = { 11, 12, 0, 0 };
258 EXPECT_CALL(context, get_returndata(rd_offset, rd_copy_size)).WillOnce(Return(expected_returndata));
263 std::vector<FF> returndata_in_memory;
264 for (uint32_t i = 0; i < rd_copy_size; ++i) {
266 returndata_in_memory.emplace_back(c.as_ff());
268 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