diff --git a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/l1_wrapper.hpp b/crypto3/libs/blueprint/include/nil/blueprint/bbf/l1_wrapper.hpp similarity index 100% rename from crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/l1_wrapper.hpp rename to crypto3/libs/blueprint/include/nil/blueprint/bbf/l1_wrapper.hpp diff --git a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/mload.hpp b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/mload.hpp index a96c9ad650..eb39c84d98 100644 --- a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/mload.hpp +++ b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/mload.hpp @@ -50,17 +50,36 @@ namespace nil { zkevm_mload_bbf(context_type &context_object, const opcode_input_type ¤t_state): generic_component(context_object, false) { - TYPE address; + TYPE addr; std::vector bytes(32); if constexpr( stage == GenerationStage::ASSIGNMENT ){ - //addr = w_to_16(current_state.stack_top())[15]; + auto address = w_to_16(current_state.stack_top())[15]; + for( std::size_t i = 0; i < 32; i++){ + //bytes[i] = TYPE(current_state.memory(addr + i)); + } + addr = address; } if constexpr( stage == GenerationStage::CONSTRAINTS ){ - // constrain(current_state.pc_next() - current_state.pc(0) - 1); // PC transition + 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.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.rw_counter_next() - current_state.rw_counter(0) - 32); // rw_counter transition + + constrain(current_state.rw_counter_next() - current_state.rw_counter(0) - 32); // rw_counter transition + // std::vector tmp; + // tmp = { + // TYPE(rw_op_to_num(rw_operation_type::stack)), + // current_state.call_id(0), + // current_state.stack_size(0) - 1, + // TYPE(0), // storage_key_hi + // TYPE(0), // storage_key_lo + // TYPE(0), // field + // current_state.rw_counter(0), + // TYPE(0), // is_write + // TYPE(0), // hi bytes are 0 + // addr // addr is smaller than maximum contract size + // }; + // lookup(tmp, "zkevm_rw"); } else { //std::cout << "\tASSIGNMENT implemented" << std::endl; } @@ -69,18 +88,18 @@ namespace nil { template class zkevm_mload_operation : public opcode_abstract { - public: + public: virtual void fill_context( typename generic_component::context_type &context, const opcode_input_type ¤t_state ) { - //zkevm_mload_bbf bbf_obj(context, current_state); + zkevm_mload_bbf bbf_obj(context, current_state); } virtual void fill_context( typename generic_component::context_type &context, const opcode_input_type ¤t_state ) { - //zkevm_mload_bbf bbf_obj(context, current_state); + zkevm_mload_bbf bbf_obj(context, current_state); } virtual std::size_t rows_amount() override { return 1; diff --git a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/mstore.hpp b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/mstore.hpp index 728c2ff4f3..cfa7b485f5 100644 --- a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/mstore.hpp +++ b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/mstore.hpp @@ -53,6 +53,7 @@ namespace nil { TYPE addr; std::vector value(32); if constexpr( stage == GenerationStage::ASSIGNMENT ){ + std::cout << current_state.stack_top(1) << std::endl; addr = w_to_16(current_state.stack_top())[15]; auto bytes = w_to_8(current_state.stack_top(1)); for( std::size_t i = 0; i < 32; i++){ @@ -68,8 +69,8 @@ namespace nil { //constrain(current_state.gas(0) - current_state.gas_next() - 1); // GAS transition constrain(current_state.stack_size(0) - current_state.stack_size_next() - 2); // stack_size transition //constrain(current_state.memory_size(0) - current_state.memory_size_next()); // memory_size transition - //constrain(current_state.rw_counter_next() - current_state.rw_counter(0) - 32); // rw_counter transition - auto V_128 = chunks16_to_chunks128(value); + constrain(current_state.rw_counter_next() - current_state.rw_counter(0) - 34); // rw_counter transition + auto V_128 = chunks8_to_chunks128(value); std::vector tmp; tmp = { @@ -85,35 +86,35 @@ namespace nil { addr // addr is smaller than maximum contract size }; lookup(tmp, "zkevm_rw"); - // tmp = { - // TYPE(rw_op_to_num(rw_operation_type::stack)), - // current_state.call_id(0), - // current_state.stack_size(0) - 2, - // TYPE(0), // storage_key_hi - // TYPE(0), // storage_key_lo - // TYPE(0), // field - // current_state.rw_counter(0) + 1, - // TYPE(0), // is_write - // V_128.first, // hi bytes are 0 - // V_128.second // addr is smaller than maximum contract size - // }; - // lookup(tmp, "zkevm_rw"); + tmp = { + TYPE(rw_op_to_num(rw_operation_type::stack)), + current_state.call_id(0), + current_state.stack_size(0) - 2, + TYPE(0), // storage_key_hi + TYPE(0), // storage_key_lo + TYPE(0), // field + current_state.rw_counter(0) + 1, + TYPE(0), // is_write + V_128.first, // hi bytes are 0 + V_128.second // addr is smaller than maximum contract size + }; + lookup(tmp, "zkevm_rw"); - // for( std::size_t i = 0; i < 32; i++){ - // tmp = { - // TYPE(rw_op_to_num(rw_operation_type::memory)), - // current_state.call_id(0), - // addr + i, - // TYPE(0), // storage_key_hi - // TYPE(0), // storage_key_lo - // TYPE(0), // field - // current_state.rw_counter(0) + 2 + i, - // TYPE(1), // is_write - // TYPE(0), // hi bytes are 0 - // value[i] // addr is smaller than maximum contract size - // }; - // lookup(tmp, "zkevm_rw"); - // } + for( std::size_t i = 0; i < 32; i++){ + tmp = { + TYPE(rw_op_to_num(rw_operation_type::memory)), + current_state.call_id(0), + addr + i, + TYPE(0), // storage_key_hi + TYPE(0), // storage_key_lo + TYPE(0), // field + current_state.rw_counter(0) + 2 + i, + TYPE(1), // is_write + TYPE(0), // hi bytes are 0 + value[i] // addr is smaller than maximum contract size + }; + lookup(tmp, "zkevm_rw"); + } } else { //std::cout << "\tASSIGNMENT implemented" << std::endl; } diff --git a/crypto3/libs/blueprint/test/zkevm_bbf/bytecode.cpp b/crypto3/libs/blueprint/test/zkevm_bbf/bytecode.cpp index 895e791fc3..7a8f994c0b 100644 --- a/crypto3/libs/blueprint/test/zkevm_bbf/bytecode.cpp +++ b/crypto3/libs/blueprint/test/zkevm_bbf/bytecode.cpp @@ -42,7 +42,7 @@ #include #include -#include +#include #include #include "./test_l1_wrapper.hpp" diff --git a/crypto3/libs/blueprint/test/zkevm_bbf/copy.cpp b/crypto3/libs/blueprint/test/zkevm_bbf/copy.cpp index 926e9d9b8b..98c8f29150 100644 --- a/crypto3/libs/blueprint/test/zkevm_bbf/copy.cpp +++ b/crypto3/libs/blueprint/test/zkevm_bbf/copy.cpp @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include "./test_l1_wrapper.hpp" diff --git a/crypto3/libs/blueprint/test/zkevm_bbf/l1_wrapper.cpp b/crypto3/libs/blueprint/test/zkevm_bbf/l1_wrapper.cpp index e0ff04c282..493b27369a 100644 --- a/crypto3/libs/blueprint/test/zkevm_bbf/l1_wrapper.cpp +++ b/crypto3/libs/blueprint/test/zkevm_bbf/l1_wrapper.cpp @@ -47,7 +47,7 @@ #include #include -#include +#include #include #include #include diff --git a/crypto3/libs/blueprint/test/zkevm_bbf/rw.cpp b/crypto3/libs/blueprint/test/zkevm_bbf/rw.cpp index eeae74927a..67f2e317aa 100644 --- a/crypto3/libs/blueprint/test/zkevm_bbf/rw.cpp +++ b/crypto3/libs/blueprint/test/zkevm_bbf/rw.cpp @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include