Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

136 zkevm operations in bbf #145

Closed
wants to merge 63 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
33a540b
RW circuit implemented #95
ETatuzova Oct 24, 2024
05d7acc
L1 wrapper test fixed #95
ETatuzova Oct 24, 2024
e43cd85
Implemented all necessary changes, not tested
ayashunsky Oct 25, 2024
6b6df73
Bytecode updatec #95
ETatuzova Oct 25, 2024
72e4eeb
Merge branch '114-additional-bbf-constrain-processing-functions-for-z…
ETatuzova Oct 25, 2024
b7f8f21
Bytecode updated #95
ETatuzova Oct 25, 2024
220f91d
Fixes & dynamic selectors for lookups
ayashunsky Oct 26, 2024
5a43999
Merge branch '114-additional-bbf-constrain-processing-functions-for-z…
ETatuzova Oct 26, 2024
08ab7f8
#95 rw minor update
ETatuzova Oct 26, 2024
a3f921c
Implemented all necessary changes, not tested
ayashunsky Oct 25, 2024
ca3269e
Fixes & dynamic selectors for lookups
ayashunsky Oct 26, 2024
f4584f3
Rebase to master
ayashunsky Oct 27, 2024
0b47368
Merge with latest 114 branch #95
ETatuzova Oct 28, 2024
445c3dd
RW circuit optimizec #95
ETatuzova Oct 29, 2024
3415708
exp circuit in bbf
Valeh2012 Oct 29, 2024
fcf2392
Input types defined #95
ETatuzova Oct 30, 2024
28d4775
Input types updated #95
ETatuzova Oct 31, 2024
2af82c5
zkEVM skeleton #95
ETatuzova Nov 1, 2024
3810fcc
Merge with master #95
ETatuzova Nov 1, 2024
c904c37
opcodes assignment added #95
ETatuzova Nov 1, 2024
c7aacb9
Opcode constraints initialization started #95
ETatuzova Nov 2, 2024
b6fdce8
First opcode constraint #95
ETatuzova Nov 2, 2024
947ce29
ISZERO implemented #95
ETatuzova Nov 2, 2024
9a74b8e
Merge branch 'master' of github.com:NilFoundation/placeholder into HEAD
ETatuzova Nov 2, 2024
5d4d5ff
PUSHx implemented #95
ETatuzova Nov 3, 2024
498823f
Opcode length controller constraint added#95
ETatuzova Nov 4, 2024
4bc3e45
PUSHx SWAPx DUPx JUMP JUMPI JUMPDEST #95
ETatuzova Nov 4, 2024
93a85ee
New opcodes #95
ETatuzova Nov 5, 2024
b35dfc5
l1_wrapper removed to BBF #95
ETatuzova Nov 5, 2024
4271273
Minor fix #95
ETatuzova Nov 5, 2024
4eee515
New opcodes, reorder RW operations, RETURN copy event#95
ETatuzova Nov 7, 2024
41448b9
Merge branch 'master' of github.com:NilFoundation/placeholder into HEAD
ETatuzova Nov 7, 2024
f3573a8
Larger test #95
ETatuzova Nov 8, 2024
7018df1
Specialized copy test #95
ETatuzova Nov 8, 2024
578312c
Specialized opcode testing environment #95
ETatuzova Nov 8, 2024
4505f99
Mod_ops test added, lookup constraints amount decreased #95
ETatuzova Nov 11, 2024
37e1989
ADDMOD testing #95
ETatuzova Nov 11, 2024
5e9b214
call_id initialization fixed #95
ETatuzova Nov 11, 2024
3456f7c
Bitwise operations added #95
ETatuzova Nov 12, 2024
749f5b4
Merge branch 'master' of github.com:NilFoundation/placeholder into HEAD
ETatuzova Nov 12, 2024
8f8b038
ADDMOD support #95
ETatuzova Nov 12, 2024
3590ce0
Add hardhat test for modular operations. Fixed hardhat_input_generatr…
ETatuzova Nov 12, 2024
efa8552
Keccak test added, SCMP bug fixed #95
ETatuzova Nov 12, 2024
1f30f1a
CMP tests added. SLOAD fixed, bitwise lookup constraints amount decre…
ETatuzova Nov 13, 2024
741bd0e
Merge branch 'master' of github.com:NilFoundation/placeholder into HEAD
ETatuzova Nov 13, 2024
d73fb5a
Mulmod from 126 branch pulled, but it doesn't work #95
ETatuzova Nov 13, 2024
b16fbdf
Pull MULMOD from 136 branch #95
ETatuzova Nov 14, 2024
596a547
Copy circuit constraints added #95
ETatuzova Nov 14, 2024
2d2a8ec
Keccak support added #95
ETatuzova Nov 14, 2024
992b095
Merge with master branch #95
ETatuzova Nov 15, 2024
09729f9
ADD and SUB implemented #95
ETatuzova Nov 18, 2024
7c89dc3
Byte_ops test fixed #95
ETatuzova Nov 20, 2024
860d63e
MUL opcode #95
ETatuzova Nov 21, 2024
ccf5a54
MUL fixed, calldatacopy test fixed#95
ETatuzova Nov 22, 2024
5dad982
Shifts fixe, some tests fixed, MUL fixed #95
ETatuzova Nov 25, 2024
724ace0
SAR and NOT added #95
ETatuzova Nov 26, 2024
fb5c3f0
Added zero first row for copy circuit dynamic tables #95
ETatuzova Nov 27, 2024
3e66124
RW and copy blueprint tests are tested with proof system on simple ex…
ETatuzova Nov 27, 2024
ca1f330
BYTE finished #95
ETatuzova Nov 28, 2024
bf1e37d
Merge branch 'master' of github.com:NilFoundation/placeholder into HEAD
ETatuzova Nov 28, 2024
b06cb1a
DIV, MOD, SDIV, SMOD #95
ETatuzova Nov 28, 2024
a1d34d6
zkevm bbf signextend
Nov 29, 2024
e63d7a1
optimization zkevm bbf circuits operations
Dec 2, 2024
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
Prev Previous commit
Next Next commit
Keccak support added #95
ETatuzova committed Nov 14, 2024
commit 2d2a8ecef468926377ce120d479b8201cea8090f
10 changes: 3 additions & 7 deletions crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/copy.hpp
Original file line number Diff line number Diff line change
@@ -40,6 +40,8 @@ namespace nil {
using generic_component<FieldType, stage>::lookup_table;
public:
using typename generic_component<FieldType,stage>::TYPE;
using integral_type = boost::multiprecision::number<boost::multiprecision::backends::cpp_int_modular_backend<257>>;

struct input_type{
TYPE rlc_challenge;
typename std::conditional<stage == GenerationStage::ASSIGNMENT, zkevm_keccak_buffers, nullptr_t>::type bytecodes;
@@ -128,7 +130,6 @@ namespace nil {
std::vector<TYPE> rlc(max_copy);
std::vector<TYPE> rlc_challenge(max_copy);
std::vector<TYPE> is_last(max_copy);
std::vector<TYPE> length_inv(max_copy);

if constexpr (stage == GenerationStage::ASSIGNMENT) {
std::size_t current_row = 0;
@@ -148,8 +149,6 @@ namespace nil {
rlc[current_row + 1] = rlc[current_row] + bytes[current_row];
type_selector[current_row][copy_op_to_num(cp.source_type) - 1] = 1;
type_selector[current_row + 1][copy_op_to_num(cp.destination_type) - 1] = 1;
length_inv[current_row] = (length[current_row] - 1) == 0? 0: (length[current_row] - 1).inversed();
length_inv[current_row+1] = length_inv[current_row];

current_row += 2;
}
@@ -165,8 +164,7 @@ namespace nil {
allocate(bytes[i],6, i);
allocate(rlc[i],7, i);
allocate(rlc_challenge[i],8, i);
allocate(length_inv[i],9, i);
allocate(is_last[i],10, i);
allocate(is_last[i], 9, i);

TYPE memory_selector = type_selector[i][copy_op_to_num(copy_operand_type::memory) - 1];
TYPE keccak_selector = type_selector[i][copy_op_to_num(copy_operand_type::keccak) - 1];
@@ -210,8 +208,6 @@ namespace nil {
}
every.push_back(context_object.relativize(type_selector_sum * (type_selector_sum - 1), -1));
every.push_back(context_object.relativize(cp_type_constraint - cp_type[1], -1));
every.push_back(context_object.relativize(type_selector_sum * (length[1] - 1) * ((length[1] - 1) * length_inv[1] - 1), -1));
every.push_back(context_object.relativize(type_selector_sum * length_inv[1] * ((length[1] - 1) * length_inv[1] - 1), -1));
every.push_back(context_object.relativize((type_selector_sum - 1)* is_last[1], -1));
every.push_back(context_object.relativize((type_selector_sum - 1)* is_first[1], -1));

Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
@@ -46,16 +45,101 @@ namespace nil {
using generic_component<FieldType, stage>::lookup_table;
public:
using typename generic_component<FieldType,stage>::TYPE;
using integral_type = boost::multiprecision::number<boost::multiprecision::backends::cpp_int_modular_backend<257>>;

zkevm_keccak_bbf(context_type &context_object, const opcode_input_type<FieldType, stage> &current_state):
generic_component<FieldType,stage>(context_object, false)
{
TYPE offset;
TYPE length;
TYPE hash_hi;
TYPE hash_lo;
if constexpr( stage == GenerationStage::ASSIGNMENT ){
offset = w_lo<FieldType>(current_state.stack_top());
length = w_lo<FieldType>(current_state.stack_top(1));
std::size_t start_offset = std::size_t(integral_type(current_state.stack_top()));
std::size_t l = std::size_t(integral_type(current_state.stack_top(1)));
std::vector<std::uint8_t> buffer;
for( std::size_t i = 0; i < l; i++ ){
buffer.push_back(std::uint8_t(integral_type(current_state.memory(start_offset + i))));
}
auto hash_value = zkevm_keccak_hash(buffer);
hash_hi = w_hi<FieldType>(hash_value);
hash_lo = w_lo<FieldType>(hash_value);
}
allocate(offset, 32, 0);
allocate(length, 33, 0);
allocate(hash_hi, 34, 0);
allocate(hash_lo, 35, 0);
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() - 2); // GAS transition
// constrain(current_state.stack_size_next() - current_state.stack_size(0) - 1); // stack_size transition
constrain(current_state.stack_size_next() - current_state.stack_size(0) + 1); // 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) - 1); // rw_counter transition
constrain(current_state.rw_counter_next() - current_state.rw_counter(0) - 3 - length); // 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
offset // 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
TYPE(0),// hi bytes are 0
length // addr is smaller than maximum contract size
};
lookup(tmp, "zkevm_rw");
tmp = {
TYPE(1), // is_first
TYPE(0), // source_id_hi
current_state.call_id(0), // source_id_lo
TYPE(copy_op_to_num(copy_operand_type::memory)), // cp_type
offset,
length,
TYPE(0), // is_write
current_state.rw_counter(0) + 2 // addr is smaller than maximum contract size
};
lookup(tmp, "zkevm_copy");
tmp = {
TYPE(1), // is_first
hash_hi, // source_id_hi
hash_lo, // source_id_lo
TYPE(copy_op_to_num(copy_operand_type::keccak)), // cp_type
0,
length,
TYPE(1), // is_write
current_state.rw_counter(0) + 2 + length // addr is smaller than maximum contract size
};
lookup(tmp, "zkevm_copy");
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) + 2 + length,
TYPE(1),// is_write
hash_hi,
hash_lo
};
lookup(tmp, "zkevm_rw");
} else {
std::cout << "\tASSIGNMENT implemented" << std::endl;
}
@@ -66,7 +150,7 @@ namespace nil {
class zkevm_keccak_operation : public opcode_abstract<FieldType> {
public:
virtual std::size_t rows_amount() override {
return 2;
return 1;
}
virtual void fill_context(
typename generic_component<FieldType, GenerationStage::ASSIGNMENT>::context_type &context,