-
Notifications
You must be signed in to change notification settings - Fork 10
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
Vectors of vectors removed #34
Draft
nkaskov
wants to merge
4
commits into
17-calldata-gas-marshalling-reduce
Choose a base branch
from
29-remove-vectors-of-vectors
base: 17-calldata-gas-marshalling-reduce
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,9 +175,17 @@ library batched_lpc_verifier { | |
basic_marshalling.skip_octet_vector_32_be_check(blob, offset), i, j); | ||
} | ||
|
||
function eval4_to_eval(uint256[4] memory eval4) internal pure returns (uint256[] memory result){ | ||
result = new uint256[](eval4[0]); | ||
for( uint256 i = 0; i < eval4[0];){ | ||
result[i] = eval4[i+1]; | ||
unchecked{ i++; } | ||
} | ||
} | ||
|
||
uint256 constant PRECOMPUTE_EVAL3_SIZE = 5; | ||
function parse_verify_proof_be(bytes calldata blob, | ||
uint256 offset, uint256[][] memory evaluation_points, | ||
uint256 offset, uint256[4][] memory evaluation_points, | ||
types.transcript_data memory tr_state, types.fri_params_type memory fri_params) | ||
internal returns (bool result) { | ||
profiling.start_block("LPC::parse_verify_proof_be"); | ||
|
@@ -196,18 +204,29 @@ library batched_lpc_verifier { | |
|
||
z_offset = basic_marshalling.skip_length(skip_to_z(blob, offset)); | ||
if( fri_params.step_list[0] != 1){ | ||
uint256[] memory eval; | ||
uint256[4] memory eval4; | ||
uint256[] memory V; | ||
uint256[] memory U; | ||
uint256 i; | ||
|
||
for (polynom_index = 0; polynom_index < fri_params.leaf_size;) { | ||
eval = evaluation_points.length == 1? eval = evaluation_points[0]: eval = evaluation_points[polynom_index]; | ||
fri_params.batched_U[polynom_index] = polynomial.interpolate( | ||
eval4 = evaluation_points.length == 1? evaluation_points[0]: evaluation_points[polynom_index]; | ||
U = polynomial.interpolate( | ||
blob, | ||
eval, | ||
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] = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible that eval4[0] < 1? Because this one will be re-set again in the next loop |
||
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++; } | ||
} | ||
|
||
|
@@ -216,46 +235,56 @@ library batched_lpc_verifier { | |
if( evaluation_points.length == 1 && polynom_index !=0 ) | ||
fri_params.batched_V[polynom_index] = fri_params.batched_V[0]; | ||
else{ | ||
eval = evaluation_points[polynom_index]; | ||
fri_params.batched_V[polynom_index] = new uint256[](1); | ||
fri_params.batched_V[polynom_index][0] = 1; | ||
for (point_index = 0; point_index < eval.length;) { | ||
fri_params.lpc_z[0] = fri_params.modulus - eval[point_index]; | ||
fri_params.batched_V[polynom_index] = polynomial.mul_poly( | ||
fri_params.batched_V[polynom_index], | ||
eval4 = evaluation_points[polynom_index]; | ||
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]; | ||
V = polynomial.mul_poly( | ||
V, | ||
fri_params.lpc_z, | ||
fri_params.modulus | ||
); | ||
unchecked{ point_index++; } | ||
} | ||
fri_params.batched_V[polynom_index][0] = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same question about size of eval4[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++; } | ||
} | ||
} else { | ||
// Compute number of polynoms with 2 and 3 evaluation points | ||
// Compute number of polynomials with 2 and 3 evaluation points | ||
uint256 eval3 = 1; | ||
uint256 eval2 = 1; | ||
bool found; | ||
|
||
for(point_index = 0; point_index < evaluation_points.length;){ | ||
if( evaluation_points[point_index].length == 3){ | ||
if( evaluation_points[point_index][0] == 3){ | ||
unchecked{eval3++;} | ||
} | ||
if (evaluation_points[point_index].length == 2){ | ||
if (evaluation_points[point_index][0] == 2){ | ||
unchecked{eval2++;} | ||
} | ||
unchecked{point_index++;} | ||
} | ||
fri_params.precomputed_indices = new uint256[](eval3 > eval2? eval3: eval2); | ||
fri_params.precomputed_indices = new uint256[](eval3+eval2); | ||
|
||
// Compute number of different sets of evaluation points | ||
if( eval3 != 0 ){ | ||
for(point_index = 0; point_index < evaluation_points.length;){ | ||
if( evaluation_points[point_index].length == 3){ | ||
if( evaluation_points[point_index][0] == 3){ | ||
found = false; | ||
for(ind = 1; ind < fri_params.precomputed_indices[0] + 1;){ | ||
if(evaluation_points[fri_params.precomputed_indices[ind]][0] == evaluation_points[point_index][0]&& | ||
evaluation_points[fri_params.precomputed_indices[ind]][1] == evaluation_points[point_index][1]&& | ||
evaluation_points[fri_params.precomputed_indices[ind]][2] == evaluation_points[point_index][2]){ | ||
if( evaluation_points[fri_params.precomputed_indices[ind]][1] == evaluation_points[point_index][1] && | ||
evaluation_points[fri_params.precomputed_indices[ind]][2] == evaluation_points[point_index][2] && | ||
evaluation_points[fri_params.precomputed_indices[ind]][3] == evaluation_points[point_index][3] ){ | ||
found = true; | ||
break; | ||
} | ||
|
@@ -268,15 +297,15 @@ library batched_lpc_verifier { | |
} | ||
unchecked{point_index++;} | ||
} | ||
fri_params.precomputed_eval3_points = new uint256[][](fri_params.precomputed_indices[0]); | ||
fri_params.precomputed_points = new uint256[5][](fri_params.precomputed_indices[0]); | ||
fri_params.precomputed_eval3_data = new uint256[9][](fri_params.precomputed_indices[0]); | ||
for(ind = 1; ind < fri_params.precomputed_indices[0] + 1;){ | ||
point_index = fri_params.precomputed_indices[ind]; | ||
fri_params.precomputed_eval3_points[point_index] = new uint256[](PRECOMPUTE_EVAL3_SIZE); | ||
fri_params.precomputed_eval3_points[point_index][0] = evaluation_points[point_index][0]; | ||
fri_params.precomputed_eval3_points[point_index][1] = evaluation_points[point_index][1]; | ||
fri_params.precomputed_eval3_points[point_index][2] = evaluation_points[point_index][2]; | ||
fri_params.precomputed_eval3_points[point_index][3] = 0; | ||
fri_params.precomputed_points[point_index][0] = evaluation_points[point_index][0]; | ||
fri_params.precomputed_points[point_index][1] = evaluation_points[point_index][1]; | ||
fri_params.precomputed_points[point_index][2] = evaluation_points[point_index][2]; | ||
fri_params.precomputed_points[point_index][3] = evaluation_points[point_index][3]; | ||
fri_params.precomputed_points[point_index][4] = 0; | ||
unchecked{ind++;} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure that this always will be 4? Maybe, it makes sense to set a constant for this