diff --git a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/return.hpp b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/return.hpp index f04d915c5..1bba02034 100644 --- a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/return.hpp +++ b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/return.hpp @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -49,16 +50,38 @@ namespace nil { using typename generic_component::TYPE; zkevm_return_bbf(context_type &context_object, const opcode_input_type ¤t_state): - generic_component(context_object, false) - { - TYPE offset; - TYPE length; + generic_component(context_object, false){ + using Memory_Cost = typename bbf::memory_cost; + + TYPE offset, length, current_mem, next_mem, memory_expansion, S; if constexpr( stage == GenerationStage::ASSIGNMENT ){ offset = w_lo(current_state.stack_top()); length = w_lo(current_state.stack_top(1)); + current_mem = current_state.memory_size; + next_mem = std::max(offset + length, current_mem); + S = next_mem > current_mem; } allocate(offset, 32, 0); allocate(length, 33, 0); + allocate(current_mem, 34, 0); + allocate(next_mem, 35, 0); + allocate(S, 36, 0); + + std::vector memory_cost_lookup_area_1 = {32, 33, 34, + 35, 36, 37}; + std::vector memory_cost_lookup_area_2 = {38, 39, 40, + 41, 42, 43}; + allocate(memory_expansion,45,0); + + context_type current_memory_ct = + context_object.subcontext(memory_cost_lookup_area_1, 1, 1); + context_type next_memory_ct = + context_object.subcontext(memory_cost_lookup_area_2, 1, 1); + + Memory_Cost current_memory = + Memory_Cost(current_memory_ct, current_mem); + Memory_Cost next_memory = Memory_Cost(next_memory_ct, next_mem); + memory_expansion = next_memory.cost - current_memory.cost; if constexpr( stage == GenerationStage::CONSTRAINTS ){ std::vector tmp; tmp = { @@ -113,7 +136,7 @@ namespace nil { // constrain(current_state.pc_next() - current_state.pc(0) - 1); // PC transition // constrain(current_state.gas(0) - current_state.gas_next() - 1); // GAS transition // constrain(current_state.stack_size(0) - current_state.stack_size_next()); // stack_size transition - // constrain(current_state.memory_size(0) - current_state.memory_size_next()); // memory_size transition + // constrain(current_state.memory_size(0) - current_state.memory_size_next() - memory_extension); // memory_size transition // constrain(current_state.rw_counter_next() - current_state.rw_counter(0)); // rw_counter transition } else { // std::cout << "\tASSIGNMENT implemented" << std::endl;