Skip to content

Commit

Permalink
Fix compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
storojs72 committed Jul 31, 2023
1 parent a4f2ffd commit 9bfa385
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/blocks/PolyEvalInstance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ library PolyEvalInstanceLib {
uint256 e;
}

function pad(PolyEvalInstance[] memory p) public returns (PolyEvalInstance[] memory) {
function pad(PolyEvalInstance[] memory p) public pure returns (PolyEvalInstance[] memory) {
uint256 j;
uint256 i;
uint256 x_length_max;
Expand Down
32 changes: 20 additions & 12 deletions src/verifier/Step5.sol
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ library Step5Lib {
function compute_powers_of_rho_primary(
Abstractions.RelaxedR1CSSNARK storage proof,
KeccakTranscriptLib.KeccakTranscript memory transcript
) public returns (KeccakTranscriptLib.KeccakTranscript memory, uint256[] memory) {
) public view returns (KeccakTranscriptLib.KeccakTranscript memory, uint256[] memory) {
uint256 i = 0;
uint256[] memory evals = new uint256[](proof.eval_input_arr.length + proof.eval_output2_arr.length);

Expand Down Expand Up @@ -254,7 +254,7 @@ library Step5Lib {
function compute_powers_of_rho_secondary(
Abstractions.RelaxedR1CSSNARK storage proof,
KeccakTranscriptLib.KeccakTranscript memory transcript
) public returns (KeccakTranscriptLib.KeccakTranscript memory, uint256[] memory) {
) public view returns (KeccakTranscriptLib.KeccakTranscript memory, uint256[] memory) {
uint256 i = 0;
uint256[] memory evals = new uint256[](proof.eval_input_arr.length + proof.eval_output2_arr.length);

Expand Down Expand Up @@ -294,7 +294,7 @@ library Step5Lib {
Abstractions.RelaxedR1CSSNARK storage proof,
uint256[] memory powers_of_rho,
uint256[] memory r_sat
) public returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
) public view returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
require(
proof.comm_output_arr.length == proof.eval_output_arr.length,
"[Step5::compute_u_vec_1_primary] proof.comm_output_arr.length != proof.eval_output_arr.length"
Expand Down Expand Up @@ -330,7 +330,7 @@ library Step5Lib {
Abstractions.RelaxedR1CSSNARK storage proof,
uint256[] memory powers_of_rho,
uint256[] memory r_sat
) public returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
) public view returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
require(
proof.comm_output_arr.length == proof.eval_output_arr.length,
"[Step5::compute_u_vec_1_secondary] proof.comm_output_arr.length != proof.eval_output_arr.length"
Expand Down Expand Up @@ -366,7 +366,7 @@ library Step5Lib {
Abstractions.RelaxedR1CSSNARK storage proof,
uint256[] memory powers_of_rho,
uint256[] memory r_sat
) public returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
) public view returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
require(
proof.comm_output_arr.length == proof.claims_product_arr.length,
"[Step5::compute_u_vec_2_primary] proof.comm_output_arr.length == proof.claims_product_arr.length"
Expand Down Expand Up @@ -408,7 +408,7 @@ library Step5Lib {
Abstractions.RelaxedR1CSSNARK storage proof,
uint256[] memory powers_of_rho,
uint256[] memory r_sat
) public returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
) public view returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
require(
proof.comm_output_arr.length == proof.claims_product_arr.length,
"[Step5::compute_u_vec_2_secondary] proof.comm_output_arr.length == proof.claims_product_arr.length"
Expand Down Expand Up @@ -450,7 +450,7 @@ library Step5Lib {
Abstractions.RelaxedR1CSSNARK storage proof,
uint256[] memory powers_of_rho,
uint256[] memory r_prod
) public returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
) public view returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
require(
proof.comm_output_arr.length == proof.eval_output2_arr.length,
"[Step5::compute_u_vec_3_primary] proof.comm_output_arr.length == proof.eval_output2_arr.length"
Expand Down Expand Up @@ -486,7 +486,7 @@ library Step5Lib {
Abstractions.RelaxedR1CSSNARK storage proof,
uint256[] memory powers_of_rho,
uint256[] memory r_prod
) public returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
) public view returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
require(
proof.comm_output_arr.length == proof.eval_output2_arr.length,
"[Step5::compute_u_vec_3_secondary] proof.comm_output_arr.length == proof.eval_output2_arr.length"
Expand Down Expand Up @@ -523,7 +523,7 @@ library Step5Lib {
Abstractions.VerifierKeyS1 storage vk,
KeccakTranscriptLib.KeccakTranscript memory transcript,
uint256[] memory r_prod
) public returns (KeccakTranscriptLib.KeccakTranscript memory, PolyEvalInstanceLib.PolyEvalInstance memory) {
) public view returns (KeccakTranscriptLib.KeccakTranscript memory, PolyEvalInstanceLib.PolyEvalInstance memory) {
uint256[] memory eval_vec = new uint256[](8);
eval_vec[0] = proof.eval_row;
eval_vec[1] = proof.eval_row_read_ts;
Expand Down Expand Up @@ -571,7 +571,7 @@ library Step5Lib {
Abstractions.VerifierKeyS2 storage vk,
KeccakTranscriptLib.KeccakTranscript memory transcript,
uint256[] memory r_prod
) public returns (KeccakTranscriptLib.KeccakTranscript memory, PolyEvalInstanceLib.PolyEvalInstance memory) {
) public view returns (KeccakTranscriptLib.KeccakTranscript memory, PolyEvalInstanceLib.PolyEvalInstance memory) {
uint256[] memory eval_vec = new uint256[](8);
eval_vec[0] = proof.eval_row;
eval_vec[1] = proof.eval_row_read_ts;
Expand Down Expand Up @@ -620,7 +620,11 @@ library Step5Lib {
KeccakTranscriptLib.KeccakTranscript memory transcript,
uint256[] memory r_sat,
uint256[] memory r_prod
) public returns (KeccakTranscriptLib.KeccakTranscript memory, PolyEvalInstanceLib.PolyEvalInstance[] memory) {
)
public
view
returns (KeccakTranscriptLib.KeccakTranscript memory, PolyEvalInstanceLib.PolyEvalInstance[] memory)
{
PolyEvalInstanceLib.PolyEvalInstance[] memory u_vec_items = new PolyEvalInstanceLib.PolyEvalInstance[](4);

uint256[] memory powers_of_rho;
Expand All @@ -640,7 +644,11 @@ library Step5Lib {
KeccakTranscriptLib.KeccakTranscript memory transcript,
uint256[] memory r_sat,
uint256[] memory r_prod
) public returns (KeccakTranscriptLib.KeccakTranscript memory, PolyEvalInstanceLib.PolyEvalInstance[] memory) {
)
public
view
returns (KeccakTranscriptLib.KeccakTranscript memory, PolyEvalInstanceLib.PolyEvalInstance[] memory)
{
PolyEvalInstanceLib.PolyEvalInstance[] memory u_vec_items = new PolyEvalInstanceLib.PolyEvalInstance[](4);

uint256[] memory powers_of_rho;
Expand Down
2 changes: 1 addition & 1 deletion src/verifier/Step6.sol
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ library Step6Lib {
uint256[] memory r_prod_unpad,
uint256 U_x,
uint256 U_y
) public returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
) public view returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
uint256[] memory x = new uint256[](r_prod_unpad.length - 1);
for (uint256 index = 0; index < r_prod_unpad.length - 1; index++) {
x[index] = r_prod_unpad[index + 1];
Expand Down
13 changes: 8 additions & 5 deletions src/verifier/Step7.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ library Step7Lib {
function compute_c_secondary(
Abstractions.RelaxedR1CSSNARK calldata proof,
KeccakTranscriptLib.KeccakTranscript memory transcript
) public returns (KeccakTranscriptLib.KeccakTranscript memory, uint256) {
) public pure returns (KeccakTranscriptLib.KeccakTranscript memory, uint256) {
uint256[] memory eval_vec = new uint256[](9);
eval_vec[0] = proof.eval_Az;
eval_vec[1] = proof.eval_Bz;
Expand Down Expand Up @@ -128,7 +128,7 @@ library Step7Lib {
function compute_c_primary(
Abstractions.RelaxedR1CSSNARK calldata proof,
KeccakTranscriptLib.KeccakTranscript memory transcript
) public returns (KeccakTranscriptLib.KeccakTranscript memory, uint256) {
) public pure returns (KeccakTranscriptLib.KeccakTranscript memory, uint256) {
uint256[] memory eval_vec = new uint256[](9);
eval_vec[0] = proof.eval_Az;
eval_vec[1] = proof.eval_Bz;
Expand Down Expand Up @@ -158,6 +158,7 @@ library Step7Lib {

function compute_rho_primary(KeccakTranscriptLib.KeccakTranscript memory transcript)
public
pure
returns (KeccakTranscriptLib.KeccakTranscript memory, uint256)
{
uint8[] memory label = new uint8[](1);
Expand All @@ -172,6 +173,7 @@ library Step7Lib {

function compute_rho_secondary(KeccakTranscriptLib.KeccakTranscript memory transcript)
public
pure
returns (KeccakTranscriptLib.KeccakTranscript memory, uint256)
{
uint8[] memory label = new uint8[](1);
Expand All @@ -188,7 +190,7 @@ library Step7Lib {
PolyEvalInstanceLib.PolyEvalInstance[] memory u_vec_padded,
uint256 rho,
uint256 modulus
) public returns (uint256, uint256, uint256[] memory) {
) public pure returns (uint256, uint256, uint256[] memory) {
require(u_vec_padded.length >= 1, "u_vec_padded.length is empty");

uint256 num_rounds_z = u_vec_padded[0].x.length;
Expand Down Expand Up @@ -217,6 +219,7 @@ library Step7Lib {

function compute_u_vec_padded(PolyEvalInstanceLib.PolyEvalInstance[] memory u_vec)
public
pure
returns (PolyEvalInstanceLib.PolyEvalInstance[] memory)
{
return PolyEvalInstanceLib.pad(u_vec);
Expand All @@ -229,7 +232,7 @@ library Step7Lib {
uint256 U_comm_E_y,
uint256[] memory r_sat,
uint256 c
) public returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
) public view returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
uint256[] memory eval_vec = new uint256[](9);
eval_vec[0] = proof.eval_Az;
eval_vec[1] = proof.eval_Bz;
Expand Down Expand Up @@ -262,7 +265,7 @@ library Step7Lib {
uint256 U_comm_E_y,
uint256[] memory r_sat,
uint256 c
) public returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
) public view returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
uint256[] memory eval_vec = new uint256[](9);
eval_vec[0] = proof.eval_Az;
eval_vec[1] = proof.eval_Bz;
Expand Down
27 changes: 21 additions & 6 deletions test/pp-spartan-step-5.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ contract PpSpartanStep5Computations is Test {
uint256[] memory powers_of_rho,
uint256[] memory eval_output_arr,
uint256[] memory r_sat
) private returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
) private view returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
require(comm_output_arr.length == powers_of_rho.length);
require(eval_output_arr.length == powers_of_rho.length);

Expand Down Expand Up @@ -560,6 +560,7 @@ contract PpSpartanStep5Computations is Test {

function load_data_for_u_vec_computation()
private
pure
returns (
uint256[] memory,
uint256[] memory,
Expand Down Expand Up @@ -688,7 +689,7 @@ contract PpSpartanStep5Computations is Test {
uint256[] memory powers_of_rho,
uint256[] memory r_sat,
uint256[] memory claims_product_arr
) private returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
) private view returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
require(comm_output_arr.length == powers_of_rho.length);
require(claims_product_arr.length == powers_of_rho.length);

Expand Down Expand Up @@ -744,7 +745,7 @@ contract PpSpartanStep5Computations is Test {
uint256[] memory powers_of_rho,
uint256[] memory eval_output2_arr,
uint256[] memory rand_ext
) private returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
) private view returns (PolyEvalInstanceLib.PolyEvalInstance memory) {
require(comm_output_arr.length == powers_of_rho.length);
require(eval_output2_arr.length == powers_of_rho.length);

Expand Down Expand Up @@ -979,11 +980,25 @@ contract PpSpartanStep5Computations is Test {
uint256[] memory rho = new uint256[](num_claims);
(transcript, rho[0]) = KeccakTranscriptLib.squeeze(transcript, ScalarFromUniformLib.curveVesta(), label);
rho[0] = Field.reverse256(rho[0]);
console.logBytes32(bytes32(rho[0]));

for (uint256 index = 1; index < num_claims; index++) {
rho[index] = mulmod(rho[index - 1], rho[0], Vesta.P_MOD);
console.logBytes32(bytes32(rho[index]));
}

uint256[] memory rho_expected = new uint256[](10);
rho_expected[0] = 0x3c504078ca4d63f647b80e830b1595e92e689186ed80b7248e7bf2cbf05529f8;
rho_expected[1] = 0x360409f4189ed0b22a1ebc94802ef545af64f49f9a9eceb96caae1e263f048ac;
rho_expected[2] = 0x31cf45ecf85012858998c5440f28d444650c407491501ae25e3c7ed3fec4f804;
rho_expected[3] = 0x3e8a7142425bb426663f45368a77051c9b95a61b3ce918bfed7ff8b59707d0bf;
rho_expected[4] = 0x3703b5f474684a4a95f8c6a7f82d41262a87647a64f50745a7acfcfa3089b147;
rho_expected[5] = 0x1ef3028b22b2db6a0f3664d886858b81a71d8034346c226ca4b4ffbb93c25b13;
rho_expected[6] = 0x020b242d85f14483cbfb7f7e418abc7344b07119a13efd764d403b2b6c48dcc0;
rho_expected[7] = 0x0d5041a6c3c71686e8a49d1474bf738c2fee3b927ea2d754e011f89e938a1fbe;
rho_expected[8] = 0x3db6301b8b6df899f7116be8d5b0d26831e57399de1d51ee85026a67ca4cb16d;
rho_expected[9] = 0x3d960468d708028d987abc5ac7de00c42b6375029c4123a7c4e0537d2d6cd805;

assertEq(rho.length, rho_expected.length);
for (uint256 index = 0; index < rho.length; index++) {
assertEq(rho[index], rho_expected[index]);
}
}
}
13 changes: 8 additions & 5 deletions test/pp-spartan-step-7.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import "src/blocks/Sumcheck.sol";
import "src/NovaVerifierAbstractions.sol";

contract PpSpartanStep7Computations is Test {
function finalVerification(uint256 left, uint256 right) private returns (bool) {
function finalVerification(uint256 left, uint256 right) private pure returns (bool) {
return left == right;
}

function testFinalVerification() public {
function testFinalVerification() public pure {
uint256 claim_batch_final = 0x03c54cc9b90ea2e26e195ebf06841c63239b4f29f1fe29acf76db79efa88c58c;
uint256 claim_batch_final_expected = 0x03c54cc9b90ea2e26e195ebf06841c63239b4f29f1fe29acf76db79efa88c58c;

Expand All @@ -24,6 +24,7 @@ contract PpSpartanStep7Computations is Test {

function load_data_for_claim_batch_final_right()
public
pure
returns (uint256[] memory, PolyEvalInstanceLib.PolyEvalInstance[] memory, uint256[] memory, uint256[] memory)
{
uint256[] memory r_z = new uint256[](17);
Expand Down Expand Up @@ -596,6 +597,7 @@ contract PpSpartanStep7Computations is Test {

function compute_c(KeccakTranscriptLib.KeccakTranscript memory transcript, uint256[] memory eval_vec)
private
pure
returns (KeccakTranscriptLib.KeccakTranscript memory, uint256)
{
uint8[] memory input = Abstractions.toTranscriptBytes(eval_vec);
Expand All @@ -616,6 +618,7 @@ contract PpSpartanStep7Computations is Test {

function compute_rho(KeccakTranscriptLib.KeccakTranscript memory transcript)
private
pure
returns (KeccakTranscriptLib.KeccakTranscript memory, uint256)
{
uint8[] memory label = new uint8[](1);
Expand Down Expand Up @@ -654,7 +657,7 @@ contract PpSpartanStep7Computations is Test {
assertEq(expected, rho);
}

function load_u_vec() private returns (PolyEvalInstanceLib.PolyEvalInstance[] memory) {
function load_u_vec() private pure returns (PolyEvalInstanceLib.PolyEvalInstance[] memory) {
uint256[] memory x;
PolyEvalInstanceLib.PolyEvalInstance[] memory u_vec = new PolyEvalInstanceLib.PolyEvalInstance[](7);

Expand Down Expand Up @@ -836,7 +839,7 @@ contract PpSpartanStep7Computations is Test {
return u_vec;
}

function load_u_vec_padded() private returns (PolyEvalInstanceLib.PolyEvalInstance[] memory) {
function load_u_vec_padded() private pure returns (PolyEvalInstanceLib.PolyEvalInstance[] memory) {
uint256[] memory x;
PolyEvalInstanceLib.PolyEvalInstance[] memory u_vec_padded = new PolyEvalInstanceLib.PolyEvalInstance[](7);

Expand Down Expand Up @@ -1122,7 +1125,7 @@ contract PpSpartanStep7Computations is Test {
function compute_sc_proof_batch_verification_input(
PolyEvalInstanceLib.PolyEvalInstance[] memory u_vec_padded,
uint256 rho
) private returns (uint256, uint256) {
) private pure returns (uint256, uint256) {
require(u_vec_padded.length >= 1, "u_vec_padded.length is empty");

uint256 num_rounds_z = u_vec_padded[0].x.length;
Expand Down

0 comments on commit 9bfa385

Please sign in to comment.