Skip to content

Commit

Permalink
gate argument draft #46
Browse files Browse the repository at this point in the history
  • Loading branch information
SK0M0R0H authored and NickVolynkin committed Aug 11, 2023
1 parent 3bd51f0 commit bfc2f80
Show file tree
Hide file tree
Showing 8 changed files with 1,592 additions and 223 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ cmake-build-debug/
deploy/artifacts
deploy/cache
deploy/node_modules
deploy/typechain-types
deploy/typechain-types

#python
__pycache__/
28 changes: 28 additions & 0 deletions deploy/contracts/circuit_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ "_test_name":"Test name",
"arithmetization_params":[15,5,5,30],
"columns_rotations":[[-1,0,1],[-1,0,1],[-1,0,1],[-1,0,1],[-1,0,1],[-1,0,1],[-1,0,1],[-1,0,1],[-1,0,1],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0]],
"modulus":28948022309329048855892746252171976963363056481941560715954676764349967630337,
"r":13,
"m":2,
"lambda":2,
"batches_num":4,
"step_list":[1,1,1,1,1,1,1,1,1,1,1,1,1],
"D_omegas":[
26495698845590383240609604404074423972849566255661802313591097233811292788392,
13175653644678658737556805326666943932741525539026001701374450696535194715445,
18589158034707770508497743761528839450567399299956641192723316341154428793508,
5207999989657576140891498154897385491612440083899963290755562031717636435093,
21138537593338818067112636105753818200833244613779330379839660864802343411573,
22954361264956099995527581168615143754787441159030650146191365293282410739685,
23692685744005816481424929253249866475360293751445976741406164118468705843520,
7356716530956153652314774863381845254278968224778478050456563329565810467774,
17166126583027276163107155648953851600645935739886150467584901586847365754678,
3612152772817685532768635636100598085437510685224817206515049967552954106764,
14450201850503471296781915119640920297985789873634237091629829669980153907901,
199455130043951077247265858823823987229570523056509026484192158816218200659,
24760239192664116622385963963284001971067308018068707868888628426778644166363
],
"rows_amount":16384,
"max_degree":16383,
"omega":26495698845590383240609604404074423972849566255661802313591097233811292788392
}
1,142 changes: 1,142 additions & 0 deletions deploy/contracts/gate/gate0.sol

Large diffs are not rendered by default.

285 changes: 285 additions & 0 deletions deploy/contracts/gate/gate15.sol

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions deploy/contracts/gate/gate_argument.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@

// SPDX-License-Identifier: Apache-2.0.
//---------------------------------------------------------------------------//
// Copyright (c) 2022 Mikhail Komarov <nemo@nil.foundation>
// Copyright (c) 2022 Aleksei Moskvin <alalmoskvin@nil.foundation>
// Copyright (c) 2023 Elena Tatuzova <alalmoskvin@nil.foundation>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//---------------------------------------------------------------------------//
pragma solidity >=0.8.4;

import "../../../contracts/types.sol";
import "../../../contracts/basic_marshalling.sol";
import "../../../contracts/commitments/batched_lpc_verifier.sol";
import "../../../contracts/interfaces/gate_argument.sol";

import "./gate0.sol";
import "./gate15.sol";


contract template_gate_argument_split_gen is IGateArgument{
uint256 constant GATES_N = 17;

struct local_vars_type{
// 0x0
uint256 constraint_eval;
// 0x20
uint256 gate_eval;
// 0x40
uint256 gates_evaluation;
// 0x60
uint256 theta_acc;

//0x80
uint256[][] witness_evaluations;
//a0
uint256[] constant_evaluations;
//c0
uint256[] selector_evaluations;

}

// TODO: columns_rotations could be hard-coded
function evaluate_gates_be(
bytes calldata blob,
uint256 eval_proof_combined_value_offset,
types.gate_argument_params memory gate_params,
types.arithmetization_params memory ar_params,
int256[][] calldata columns_rotations
) external pure returns (uint256 gates_evaluation) {
local_vars_type memory local_vars;


local_vars.witness_evaluations = new uint256[][](ar_params.witness_columns);
for (uint256 i = 0; i < ar_params.witness_columns;) {
local_vars.witness_evaluations[i] = new uint256[](columns_rotations[i].length);
for (uint256 j = 0; j < columns_rotations[i].length;) {
local_vars.witness_evaluations[i][j] = batched_lpc_verifier.get_variable_values_z_i_j_from_proof_be(
blob, eval_proof_combined_value_offset, i, j
);
unchecked{j++;}
}
unchecked{i++;}
}

local_vars.constant_evaluations = new uint256[](ar_params.constant_columns);
for (uint256 i = 0; i < ar_params.constant_columns;) {
local_vars.constant_evaluations[i] = batched_lpc_verifier.get_fixed_values_z_i_j_from_proof_be(
blob, eval_proof_combined_value_offset, ar_params.permutation_columns + ar_params.permutation_columns + i, 0
);

unchecked{i++;}
}

local_vars.selector_evaluations = new uint256[](ar_params.selector_columns);
for (uint256 i = 0; i < ar_params.selector_columns;) {
local_vars.selector_evaluations[i] = batched_lpc_verifier.get_fixed_values_z_i_j_from_proof_be(
blob, eval_proof_combined_value_offset, ar_params.permutation_columns + ar_params.permutation_columns + ar_params.constant_columns + i, 0
);
unchecked{i++;}
}


local_vars.theta_acc = 1;
local_vars.gates_evaluation = 0;

(local_vars.gates_evaluation, local_vars.theta_acc) = template_gate0.evaluate_gate_be(gate_params, local_vars);
(local_vars.gates_evaluation, local_vars.theta_acc) = template_gate15.evaluate_gate_be(gate_params, local_vars);


gates_evaluation = local_vars.gates_evaluation;
}
}
Loading

0 comments on commit bfc2f80

Please sign in to comment.