Skip to content

Commit ad9e097

Browse files
committed
end_call after stop fixed #279
1 parent 25107b5 commit ad9e097

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/input_generators/hardhat_input_generator.hpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,17 @@ namespace nil {
250250
if(opcode == "STOP") {
251251
// 0x00 -- no RW operations
252252
_call_stack.back().end = rw_counter - 1;
253+
_call_stack.back().returndata = {};
253254
_rw_operations.push_back(
254255
call_context_rw_operation(
255256
call_id,
256257
call_context_field::end,
257258
rw_counter - 1
258259
)
259260
);
261+
_rw_operations.push_back(call_context_w_operation(call_id, call_context_field::lastcall_returndata_offset, rw_counter++, 0));
262+
_rw_operations.push_back(call_context_w_operation(call_id, call_context_field::lastcall_returndata_length, rw_counter++, 0));
263+
_rw_operations.push_back(call_context_w_operation(call_id, call_context_field::lastcall_id, rw_counter++, rw_counter + 1));
260264
} else if(opcode == "ADD") {
261265
// 0x01
262266
_rw_operations.push_back(stack_rw_operation(call_id, stack.size()-1, rw_counter++, false, stack[stack.size()-1]));
@@ -541,21 +545,39 @@ namespace nil {
541545
} else if(opcode == "RETURNDATACOPY") {
542546
// 0x3e
543547
// std::cout << "Test me, please!" << std::endl;
544-
auto dest_offset = stack[stack.size()-1];
545-
auto offset = stack[stack.size()-2];
546-
auto length = stack[stack.size()-3];
548+
auto dest_offset = std::size_t(stack[stack.size()-1]);
549+
auto offset = std::size_t(stack[stack.size()-2]);
550+
auto length = std::size_t(stack[stack.size()-3]);
551+
auto lastcall_id = std::size_t(_call_stack.back().lastcall_id);
547552
_rw_operations.push_back(stack_rw_operation(call_id, stack.size()-1, rw_counter++, false, dest_offset));
548553
_rw_operations.push_back(stack_rw_operation(call_id, stack.size()-2, rw_counter++, false, offset));
549554
_rw_operations.push_back(stack_rw_operation(call_id, stack.size()-3, rw_counter++, false, length));
550555

551-
// TODO: add length read operations from last return data
556+
_rw_operations.push_back(
557+
call_context_r_operation(
558+
call_id, call_context_field::lastcall_id, rw_counter++, lastcall_id
559+
)
560+
);
561+
copy_event cpy = returndatacopy_copy_event(
562+
lastcall_id, offset, call_id, dest_offset, rw_counter, length
563+
);
564+
for( std::size_t ind = 0; ind < length; ind++){
565+
_rw_operations.push_back(
566+
returndata_rw_operation(
567+
lastcall_id, offset+ind, rw_counter++,
568+
offset+ind < _call_stack.back().returndata.size()? _call_stack.back().returndata[offset+ind] : 0
569+
)
570+
);
571+
cpy.push_byte(offset+ind < _call_stack.back().returndata.size()? _call_stack.back().returndata[offset+ind] : 0);
572+
}
552573
for( std::size_t ind = 0; ind < length; ind++){
553574
_rw_operations.push_back(
554575
memory_rw_operation(
555576
call_id, dest_offset+ind, rw_counter++, true, memory_next[std::size_t(dest_offset+ind)]
556577
)
557578
);
558579
}
580+
_copy_events.push_back(cpy);
559581
memory_size_before = memory_next.size();
560582
// Where will consistency check be done?
561583
} else if(opcode == "EXTCODEHASH") {
@@ -1433,6 +1455,7 @@ namespace nil {
14331455
// fill end of call
14341456
std::cout << "Appended" << std::endl;
14351457
_call_stack.pop_back();
1458+
_call_stack.back().returndata = {};
14361459
if( _call_stack.size() != 1){
14371460
_call_stack.back().was_accessed.insert(returned_call.was_accessed.begin(),returned_call.was_accessed.end());
14381461
_call_stack.back().was_written.insert(returned_call.was_written.begin(),returned_call.was_written.end());
@@ -1463,20 +1486,19 @@ namespace nil {
14631486
bytecode_hash = end_call_state.bytecode_hash;
14641487
call_context_address = end_call_state.call_context_address;
14651488
memory_size_before = memory_next.size();
1466-
_rw_operations.push_back(stack_rw_operation(call_id, stack_next.size()-1, rw_counter++, true, stack_next[stack_next.size()-1]));
14671489

14681490
if( _call_stack.size() > 1 ){
14691491
_rw_operations.push_back(call_context_r_operation(
14701492
call_id,
14711493
call_context_field::lastcall_returndata_length,
14721494
rw_counter++,
1473-
0
1495+
_call_stack.back().lastcall_returndatalength
14741496
));
14751497
_rw_operations.push_back(call_context_r_operation(
14761498
call_id,
14771499
call_context_field::lastcall_returndata_offset,
14781500
rw_counter++,
1479-
0
1501+
_call_stack.back().lastcall_returndataoffset
14801502
));
14811503
_rw_operations.push_back(call_context_r_operation(
14821504
call_id,
@@ -1485,6 +1507,7 @@ namespace nil {
14851507
returned_call.call_id
14861508
));
14871509
}
1510+
_rw_operations.push_back(stack_rw_operation(call_id, stack_next.size()-1, rw_counter++, true, stack_next[stack_next.size()-1]));
14881511
}
14891512
if( opcode == "RETURN"){
14901513
std::size_t offset = std::size_t(stack[stack.size()-1]); // Real value

crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/returndatacopy.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ namespace nil {
112112
current_state.memory_size(0) - memory_expansion_size); // memory_size transition
113113
constrain(current_state.rw_counter_next() -
114114
current_state.rw_counter(0) -
115-
3 - length); // rw_counter transition
115+
4 - 2 * length); // rw_counter transition
116116
std::vector<TYPE> tmp;
117117
tmp = rw_table<FieldType, stage>::stack_lookup(
118118
current_state.call_id(0),

crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/types/copy_event.hpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,24 @@ namespace nil {
257257
return cpy;
258258
}
259259

260-
copy_event returndatacopy_copy_event(){
260+
copy_event returndatacopy_copy_event(
261+
std::size_t lastcall_id,
262+
std::size_t offset,
263+
std::size_t caller_id,
264+
std::size_t dest_offset,
265+
std::size_t rw_counter,
266+
std::size_t length
267+
){
261268
copy_event cpy;
269+
cpy.source_type = copy_operand_type::returndata;
270+
cpy.source_id = lastcall_id;
271+
cpy.src_counter_1 = offset; // Before copy reading
272+
cpy.src_counter_2 = rw_counter;
273+
cpy.destination_type = copy_operand_type::memory;
274+
cpy.destination_id = caller_id;
275+
cpy.dst_counter_1 = dest_offset; // Before copy writing
276+
cpy.dst_counter_2 = rw_counter + length;
277+
cpy.length = length;
262278
return cpy;
263279
}
264280

crypto3/libs/blueprint/test/zkevm_bbf/hardhat.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ BOOST_AUTO_TEST_CASE(try_catch) {
409409
max_sizes.max_keccak_blocks = 20;
410410
max_sizes.max_bytecode = 3000;
411411
max_sizes.max_mpt = 0;
412-
max_sizes.max_rw = 6000;
413-
max_sizes.max_copy = 1000;
412+
max_sizes.max_rw = 8000;
413+
max_sizes.max_copy = 1500;
414414
max_sizes.max_zkevm_rows = 3000;
415415
max_sizes.max_exponentiations = 50;
416416
max_sizes.max_exp_rows = 500;
@@ -427,9 +427,9 @@ BOOST_AUTO_TEST_CASE(try_catch2) {
427427
max_sizes.max_keccak_blocks = 20;
428428
max_sizes.max_bytecode = 3000;
429429
max_sizes.max_mpt = 0;
430-
max_sizes.max_rw = 6000;
431-
max_sizes.max_copy = 1000;
432-
max_sizes.max_zkevm_rows = 3000;
430+
max_sizes.max_rw = 7000;
431+
max_sizes.max_copy = 1500;
432+
max_sizes.max_zkevm_rows = 5000;
433433
max_sizes.max_exponentiations = 50;
434434
max_sizes.max_exp_rows = 500;
435435
max_sizes.max_call_commits = 500;

0 commit comments

Comments
 (0)