Skip to content

Commit

Permalink
l1_wrapper removed to BBF #95
Browse files Browse the repository at this point in the history
  • Loading branch information
ETatuzova committed Nov 5, 2024
1 parent 93a85ee commit b35dfc5
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,36 @@ namespace nil {
zkevm_mload_bbf(context_type &context_object, const opcode_input_type<FieldType, stage> &current_state):
generic_component<FieldType,stage>(context_object, false)
{
TYPE address;
TYPE addr;
std::vector<TYPE> 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<TYPE> 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;
}
Expand All @@ -69,18 +88,18 @@ namespace nil {

template<typename FieldType>
class zkevm_mload_operation : public opcode_abstract<FieldType> {
public:
public:
virtual void fill_context(
typename generic_component<FieldType, GenerationStage::ASSIGNMENT>::context_type &context,
const opcode_input_type<FieldType, GenerationStage::ASSIGNMENT> &current_state
) {
//zkevm_mload_bbf<FieldType, GenerationStage::ASSIGNMENT> bbf_obj(context, current_state);
zkevm_mload_bbf<FieldType, GenerationStage::ASSIGNMENT> bbf_obj(context, current_state);
}
virtual void fill_context(
typename generic_component<FieldType, GenerationStage::CONSTRAINTS>::context_type &context,
const opcode_input_type<FieldType, GenerationStage::CONSTRAINTS> &current_state
) {
//zkevm_mload_bbf<FieldType, GenerationStage::CONSTRAINTS> bbf_obj(context, current_state);
zkevm_mload_bbf<FieldType, GenerationStage::CONSTRAINTS> bbf_obj(context, current_state);
}
virtual std::size_t rows_amount() override {
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace nil {
TYPE addr;
std::vector<TYPE> 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++){
Expand All @@ -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<TYPE>(value);
constrain(current_state.rw_counter_next() - current_state.rw_counter(0) - 34); // rw_counter transition
auto V_128 = chunks8_to_chunks128<TYPE>(value);

std::vector<TYPE> tmp;
tmp = {
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion crypto3/libs/blueprint/test/zkevm_bbf/bytecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

#include <nil/blueprint/blueprint/plonk/circuit.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/blueprint/zkevm_bbf/l1_wrapper.hpp>
#include <nil/blueprint/bbf/l1_wrapper.hpp>
#include <nil/blueprint/zkevm_bbf/bytecode.hpp>

#include "./test_l1_wrapper.hpp"
Expand Down
2 changes: 1 addition & 1 deletion crypto3/libs/blueprint/test/zkevm_bbf/copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#include <nil/blueprint/blueprint/plonk/circuit.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/blueprint/zkevm_bbf/l1_wrapper.hpp>
#include <nil/blueprint/bbf/l1_wrapper.hpp>
#include <nil/blueprint/zkevm_bbf/copy.hpp>

#include "./test_l1_wrapper.hpp"
Expand Down
2 changes: 1 addition & 1 deletion crypto3/libs/blueprint/test/zkevm_bbf/l1_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

#include <nil/blueprint/blueprint/plonk/circuit.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/blueprint/zkevm_bbf/l1_wrapper.hpp>
#include <nil/blueprint/bbf/l1_wrapper.hpp>
#include <nil/blueprint/zkevm_bbf/zkevm.hpp>
#include <nil/blueprint/zkevm_bbf/rw.hpp>
#include <nil/blueprint/zkevm_bbf/copy.hpp>
Expand Down
2 changes: 1 addition & 1 deletion crypto3/libs/blueprint/test/zkevm_bbf/rw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

#include <nil/blueprint/blueprint/plonk/circuit.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/blueprint/zkevm_bbf/l1_wrapper.hpp>
#include <nil/blueprint/bbf/l1_wrapper.hpp>
#include <nil/blueprint/zkevm_bbf/rw.hpp>

#include <nil/blueprint/zkevm_bbf/input_generators/hardhat_input_generator.hpp>
Expand Down

0 comments on commit b35dfc5

Please sign in to comment.