Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 11 additions & 45 deletions crypto3/libs/blueprint/include/nil/blueprint/lookup_library.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,55 +86,21 @@ namespace nil {
virtual std::size_t get_rows_number(){ return 256; }
};

class zkevm_opcode_table: public lookup_table_definition{
class opcode_push_size_table: public lookup_table_definition{
public:
static constexpr std::size_t opcodes_num = 149;

zkevm_opcode_table(): lookup_table_definition("zkevm_opcodes"){
this->subtables["full"] = {{0, 1, 2}, 0, opcodes_num};
this->subtables["opcodes_only"] = {{0}, 0, opcodes_num};
opcode_push_size_table(): lookup_table_definition("opcode_push_size") {
this->subtables["full"] = {{0, 1}, 0, 256};
}
virtual void generate(){
// opcodes
this->_table.push_back({
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, //12
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, //14
0x20, //1
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, //16
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, //11
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, //16
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, //16
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, //16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0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 //10
});

this->_table.push_back({});
for( std::size_t i = 0; i < opcodes_num; i++) this->_table[2].push_back(1);
virtual void generate(){
this->_table.resize(2);
for (size_t i = 0; i < 256; ++i) this->_table[0].push_back(i);

// unselected rows virtualization
this->_table[0].push_back(0);
this->_table[1].push_back(0);
this->_table[2].push_back(0);
this->_table[1].resize(256);
for (size_t i = 1; i <= 32; ++i) this->_table[1][0x5f + i] = i;
}
virtual std::size_t get_columns_number(){ return 1; }

virtual std::size_t get_columns_number(){ return 2; }
virtual std::size_t get_rows_number(){ return 256; }
};

Expand Down Expand Up @@ -574,7 +540,7 @@ namespace nil {
tables["keccak_normalize6_table"] = std::shared_ptr<lookup_table_definition>(new normalize_base8_table_type(6));
tables["keccak_chi_table"] = std::shared_ptr<lookup_table_definition>(new chi_table_type());
tables["byte_range_table"] = std::shared_ptr<lookup_table_definition>(new byte_range_table_type());
tables["zkevm_opcodes"] = std::shared_ptr<lookup_table_definition>(new zkevm_opcode_table());
tables["opcode_push_size"] = std::shared_ptr<lookup_table_definition>(new opcode_push_size_table());
tables["byte_and_xor_table"] = std::shared_ptr<lookup_table_definition>(new byte_and_xor_table_type());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ namespace nil::blueprint::bbf::zkevm_big_field{
std::vector<TYPE> tmp = {context_object.relativize(tag[0] * value[0], -1)};
context_object.relative_lookup(tmp, "byte_range_table/full", 0, max_bytecode_size - 1);
tmp = {context_object.relativize(std::vector<TYPE>({value[0] * is_opcode[0],
push_size[0] * is_opcode[0],
is_opcode[0]}), -1)};
context_object.relative_lookup(tmp, "zkevm_opcodes/full", 0, max_bytecode_size - 1);
push_size[0] * is_opcode[0]}), -1)};
context_object.relative_lookup(tmp, "opcode_push_size/full", 0, max_bytecode_size - 1);
tmp = {context_object.relativize(std::vector<TYPE>({
tag[1] + 1 - tag[1],
tag[0] * (1 - tag[1]) * value_rlc[0],
Expand All @@ -198,4 +197,4 @@ namespace nil::blueprint::bbf::zkevm_big_field{
}
};
};
}
}
Loading
Loading