Skip to content

Commit

Permalink
Columns_rotations [][] => [4][] #29
Browse files Browse the repository at this point in the history
  • Loading branch information
e.tatuzova committed Jan 19, 2023
1 parent 54f3aa4 commit 8fed5d8
Show file tree
Hide file tree
Showing 63 changed files with 286 additions and 309 deletions.
17 changes: 16 additions & 1 deletion contracts/algebra/polynomial.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ library polynomial {
return result;
}

/*
evaluate fixed length polynomial
*/
function evaluate4(uint256[4] memory coeffs, uint256 point, uint256 modulus)
internal pure returns (uint256) {
uint256 result;

for( uint256 i = 0; i < 4;){
result = mulmod(result, point, modulus);
result = addmod(result, coeffs[3 - i], modulus);
unchecked{i++;}
}
return result;
}

function evaluate_by_ptr(bytes calldata blob, uint256 offset, uint256 len, uint256 point, uint256 modulus)
internal pure returns (uint256) {
uint256 result;
Expand Down Expand Up @@ -126,7 +141,7 @@ library polynomial {

function mul_poly(uint256[] memory a, uint256[] memory b, uint256 modulus)
internal pure returns (uint256[] memory result) {
uint256[] memory result = new uint256[](a.length + b.length - 1);
result = new uint256[](a.length + b.length - 1);
for (uint256 i = 0; i < b.length;) {
for (uint256 j = 0; j < a.length;) {
assembly {
Expand Down
7 changes: 4 additions & 3 deletions contracts/commitments/batched_fri_verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,18 @@ library batched_fri_verifier {
y_ij = basic_marshalling.get_i_j_uint256_from_vector_of_vectors(blob, offset, i, j);
}

function y_to_y0_for_first_step(uint256 x, uint256 y, uint256[] memory batched_U, uint256[] memory batched_V, uint256 modulus)
function y_to_y0_for_first_step(uint256 x, uint256 y, uint256[4] memory batched_U, uint256[4] memory batched_V, uint256 modulus)
internal view returns(uint256 result){
uint256 U_evaluated_neg;
uint256 V_evaluated_inv;
U_evaluated_neg = modulus - polynomial.evaluate(

U_evaluated_neg = modulus - polynomial.evaluate4(
batched_U,
x,
modulus
);
V_evaluated_inv = field.inverse_static(
polynomial.evaluate(
polynomial.evaluate4(
batched_V,
x,
modulus
Expand Down
30 changes: 25 additions & 5 deletions contracts/commitments/batched_lpc_verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,28 @@ library batched_lpc_verifier {
z_offset = basic_marshalling.skip_length(skip_to_z(blob, offset));
if( fri_params.step_list[0] != 1){
uint256[4] memory eval4;
uint256[] memory V;
uint256[] memory U;
uint256 i;

for (polynom_index = 0; polynom_index < fri_params.leaf_size;) {
eval4 = evaluation_points.length == 1? evaluation_points[0]: evaluation_points[polynom_index];
fri_params.batched_U[polynom_index] = polynomial.interpolate(
U = polynomial.interpolate(
blob,
eval4_to_eval(eval4),
z_offset,
fri_params.modulus
);
z_offset = basic_marshalling.skip_vector_of_uint256_be(blob, z_offset);

fri_params.batched_U[polynom_index][0] =
fri_params.batched_U[polynom_index][1] =
fri_params.batched_U[polynom_index][2] =
fri_params.batched_U[polynom_index][3] = 0;
for(i = 0; i < eval4[0];){
fri_params.batched_U[polynom_index][i] = U[i];
unchecked{ i++; }
}
unchecked{ polynom_index++; }
}

Expand All @@ -225,17 +236,26 @@ library batched_lpc_verifier {
fri_params.batched_V[polynom_index] = fri_params.batched_V[0];
else{
eval4 = evaluation_points[polynom_index];
fri_params.batched_V[polynom_index] = new uint256[](1);
fri_params.batched_V[polynom_index][0] = 1;
V = new uint256[](1);
V[0] = 1;
for (point_index = 0; point_index < eval4[0];) {
fri_params.lpc_z[0] = fri_params.modulus - eval4[point_index+1];
fri_params.batched_V[polynom_index] = polynomial.mul_poly(
fri_params.batched_V[polynom_index],
V = polynomial.mul_poly(
V,
fri_params.lpc_z,
fri_params.modulus
);
unchecked{ point_index++; }
}
fri_params.batched_V[polynom_index][0] =
fri_params.batched_V[polynom_index][1] =
fri_params.batched_V[polynom_index][2] =
fri_params.batched_V[polynom_index][3] = 0;
for(i = 0; i <= eval4[0];){
fri_params.batched_V[polynom_index][i] = V[i];
unchecked{ i++; }
}
//require(false, logging.uint2hexstr(eval4[0]));
}
unchecked{ polynom_index++; }
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ library mina_base_gate0 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ library mina_base_gate1 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate10.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library mina_base_gate10 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate11.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library mina_base_gate11 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate12.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library mina_base_gate12 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate13.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library mina_base_gate13 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate14.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ library mina_base_gate14 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate15.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ library mina_base_gate15 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate16.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library mina_base_gate16 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate16_1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library mina_base_gate16_1 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate17.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library mina_base_gate17 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate18.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ library mina_base_gate18 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library mina_base_gate2 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ library mina_base_gate3 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate4.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ library mina_base_gate4 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate5.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library mina_base_gate5 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate6.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library mina_base_gate6 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate7.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ library mina_base_gate7 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate8.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ library mina_base_gate8 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_base/mina_base_gate9.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library mina_base_gate9 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
21 changes: 13 additions & 8 deletions contracts/components/mina_base_split_gen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,43 +53,48 @@ library mina_base_split_gen {
bytes calldata blob,
types.gate_argument_local_vars memory gate_params,
types.arithmetization_params memory ar_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) internal returns (uint256 gates_evaluation) {
// TODO: check witnesses number in proof
profiling.start_block("mina_base_split_gen:evaluate_gates_be");

gate_params.witness_evaluations = new uint256[][](ar_params.witness_columns);
gate_params.offset = batched_lpc_verifier.skip_to_z(blob, gate_params.eval_proof_witness_offset);
for (uint256 i = 0; i < ar_params.witness_columns; i++) {
gate_params.witness_evaluations[i] = new uint256[](columns_rotations[i].length);
for (uint256 j = 0; j < columns_rotations[i].length; j++) {
for (uint256 i = 0; i < ar_params.witness_columns;) {
gate_params.witness_evaluations[i] = new uint256[](uint256(columns_rotations[i][0]));
for (uint256 j = 0; j < uint256(columns_rotations[i][0]);) {
gate_params.witness_evaluations[i][j] = basic_marshalling.get_i_j_uint256_from_vector_of_vectors(blob, gate_params.offset, i, j);
unchecked{j++;}
}
unchecked{i++;}
}

gate_params.selector_evaluations = new uint256[](GATES_N);
gate_params.offset = batched_lpc_verifier.skip_to_z(blob, gate_params.eval_proof_selector_offset);
for (uint256 i = 0; i < GATES_N; i++) {
for (uint256 i = 0; i < GATES_N; ) {
gate_params.selector_evaluations[i] = basic_marshalling.get_i_j_uint256_from_vector_of_vectors(
blob,
gate_params.offset,
i + ar_params.permutation_columns + ar_params.permutation_columns + ar_params.constant_columns,
0
);
unchecked{i++;}
}

gate_params.constant_evaluations = new uint256[][](ar_params.constant_columns);
gate_params.offset = batched_lpc_verifier.skip_to_z(blob, gate_params.eval_proof_constant_offset);
for (uint256 i = 0; i < ar_params.constant_columns; i++) {
gate_params.constant_evaluations[i] = new uint256[](columns_rotations[i].length);
for (uint256 j = 0; j < columns_rotations[i].length; j++) {
for (uint256 i = 0; i < ar_params.constant_columns;) {
gate_params.constant_evaluations[i] = new uint256[](uint256(columns_rotations[i][0]));
for (uint256 j = 0; j < uint256(columns_rotations[i][0]);) {
gate_params.constant_evaluations[i][j] = basic_marshalling.get_i_j_uint256_from_vector_of_vectors(
blob,
gate_params.offset,
i + ar_params.permutation_columns + ar_params.permutation_columns,
j
);
unchecked{j++;}
}
unchecked{i++;}
}

gate_params.theta_acc = 1;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_scalar/mina_scalar_gate0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ library mina_scalar_gate0 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_scalar/mina_scalar_gate1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ library mina_scalar_gate1 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_scalar/mina_scalar_gate10.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library mina_scalar_gate10 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_scalar/mina_scalar_gate11.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library mina_scalar_gate11 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
2 changes: 1 addition & 1 deletion contracts/components/mina_scalar/mina_scalar_gate12.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library mina_scalar_gate12 {
// TODO: columns_rotations could be hard-coded
function evaluate_gate_be(
types.gate_argument_local_vars memory gate_params,
int256[][] memory columns_rotations
int256[4][] memory columns_rotations
) external pure returns (uint256 gates_evaluation, uint256 theta_acc) {
gates_evaluation = gate_params.gates_evaluation;
theta_acc = gate_params.theta_acc;
Expand Down
Loading

0 comments on commit 8fed5d8

Please sign in to comment.