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

Draft
wants to merge 63 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions crypto3/libs/blueprint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set_target_properties(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} PROPERTIES
EXPORT_NAME ${CURRENT_PROJECT_NAME})

target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../test_tools/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>)

Expand Down
393 changes: 393 additions & 0 deletions crypto3/libs/blueprint/include/nil/blueprint/bbf/exp.hpp

Large diffs are not rendered by default.

130 changes: 130 additions & 0 deletions crypto3/libs/blueprint/include/nil/blueprint/bbf/exp_table.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2024 Valeh Farzaliyev <[email protected]>
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// 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.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//---------------------------------------------------------------------------//
// @file Declaration of interfaces for PLONK BBF exp table class
//---------------------------------------------------------------------------//

#ifndef CRYPTO3_BLUEPRINT_PLONK_BBF_EXP_TABLE_HPP
#define CRYPTO3_BLUEPRINT_PLONK_BBF_EXP_TABLE_HPP

#include <boost/multiprecision/cpp_int.hpp>
#include <functional>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/blueprint/blueprint/plonk/circuit.hpp>
#include <nil/blueprint/component.hpp>
#include <nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp>
// #include <nil/blueprint/manifest.hpp>
#include <nil/blueprint/bbf/generic.hpp>
#include <nil/blueprint/zkevm/zkevm_word.hpp>

namespace nil {
namespace blueprint {
namespace bbf {

class exp_table_input_type {
typedef std::vector<std::array<zkevm_word_type, 3>> data_type;

public:
void add_triplet(zkevm_word_type a, zkevm_word_type d, zkevm_word_type A) {
triplets.push_back({a, d, A});
}
void add_triplets(data_type _triplets){
triplets = _triplets;
}

const data_type &get_triplets() const { return triplets; }

private:
data_type triplets;
};

template<typename FieldType, GenerationStage stage>
class exp_table : public generic_component<FieldType, stage> {
using typename generic_component<FieldType, stage>::context_type;
using generic_component<FieldType, stage>::allocate;
using generic_component<FieldType, stage>::copy_constrain;
using generic_component<FieldType, stage>::constrain;
using generic_component<FieldType, stage>::lookup;
using generic_component<FieldType, stage>::lookup_table;

public:
using typename generic_component<FieldType, stage>::TYPE;
using word_type = zkevm_word_type;
constexpr static std::size_t num_chunks = 2;

std::size_t max_exponentiations;
std::vector<std::array<TYPE, num_chunks>> base = std::vector<std::array<TYPE, num_chunks>>(max_exponentiations);
std::vector<std::array<TYPE, num_chunks>> exponent = std::vector<std::array<TYPE, num_chunks>>(max_exponentiations);
std::vector<std::array<TYPE, num_chunks>> exponentiation = std::vector<std::array<TYPE, num_chunks>>(max_exponentiations);

public:
exp_table(context_type &context_object, const exp_table_input_type &input,
std::size_t max_exponentiations_, bool make_links = true)
: max_exponentiations(max_exponentiations_),
generic_component<FieldType, stage>(context_object) {
if constexpr (stage == GenerationStage::ASSIGNMENT) {
auto triplets = input.get_triplets();
BOOST_ASSERT(triplets.size() <= max_exponentiations);

std::size_t i = 0;
for (i = 0; i < triplets.size(); i++) {
base[i][0] = w_hi<FieldType>(triplets[i][0]);
base[i][1] = w_lo<FieldType>(triplets[i][0]);
exponent[i][0] = w_hi<FieldType>(triplets[i][1]);
exponent[i][1] = w_lo<FieldType>(triplets[i][1]);
exponentiation[i][0] = w_hi<FieldType>(triplets[i][2]);
exponentiation[i][1] = w_lo<FieldType>(triplets[i][2]);
}

// if there are unused rows, fill in with valid exp triplets (0^1 = 0)
while (i < max_exponentiations) {
base[i][0] = 0;
base[i][1] = 0;

exponent[i][0] = 0;
exponent[i][1] = 1;

exponentiation[i][0] = 0;
exponentiation[i][1] = 0;

i++;
}

}

for (std::size_t i = 0; i < max_exponentiations; i++) {
for (std::size_t j = 0; j < num_chunks; j++) {
allocate(base[i][j], j, i);
allocate(exponent[i][j], num_chunks + j, i);
allocate(exponentiation[i][j], 2 * num_chunks + j, i);
}
}

lookup_table("exp_table", {0, 1, 2, 3, 4, 5}, 0, max_exponentiations);
};
};
} // namespace bbf
} // namespace blueprint
} // namespace nil

#endif // CRYPTO3_BLUEPRINT_PLONK_BBF_EXP_TABLE_HPP
Loading
Loading