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

feat: add PlonkVerifier contracts and tests #722

Merged
merged 34 commits into from
Nov 15, 2023
Merged

feat: add PlonkVerifier contracts and tests #722

merged 34 commits into from
Nov 15, 2023

Conversation

alxiong
Copy link
Contributor

@alxiong alxiong commented Oct 24, 2023

Resolves #702

Bug Fixes

In this PR, we have fixed two bugs:

  • in 69079d9, we fix the discrepancy introduced in an updated version of Jellyfish. This is not technically a bug, but an inconsistency of types due to jellyfish's update on arkwork dep, which further affect the Transcript.state computation.
  • in 1d7c6c6, we add a missing validity check on zetaOmega field of a plonk proof. This is important since all of the following computation assume these fields are valid. (credit to @sveitser for spotting it, and we have added automated fuzz-test to detect such error)

@alxiong alxiong self-assigned this Oct 24, 2023
@alxiong alxiong marked this pull request as ready for review November 8, 2023 17:18
@alxiong alxiong requested review from sveitser and removed request for sveitser and ImJeremyHe November 8, 2023 17:19
@alxiong
Copy link
Contributor Author

alxiong commented Nov 8, 2023

I will deal with some minor TODOs and fix CI failure tmr, but I think it's good to start reviewing this PR now.

@sveitser @philippecamacho

the final test on batchVerify is currently blocked by #741

contract PlonkVerifier_preparePcsInfo_Test is PlonkVerifierCommonTest {
/// forge-config: default.fuzz.runs = 5
/// @dev Test `preparePcsInfo` matches that of Jellyfish
function testFuzz_preparePcsInfo_matches(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encountered 1 failing test in contracts/test/PlonkVerifier.t.sol:PlonkVerifier_preparePcsInfo_Test
[FAIL. Reason: InvalidPolyEvalArgs() Counterexample: calldata=0x0x99fdc07100000000000000000000000000000000000000000000000000000000000005fe000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000003b2, args=[1534, [], 0x00000000000000000000000000000000000000000000000000000000000003b2]] testFuzz_preparePcsInfo_matches(uint64,uint256[],bytes) (runs: 1, μ: 8001859, ~: 8001859)

Copy link
Contributor Author

@alxiong alxiong Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, I will add test logic for empty publicInput array.
(nothing wrong with code, just test is not careful)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 90bf8d1

foundry.toml Outdated
@@ -26,3 +27,6 @@ sepolia = { key = "${ETHERSCAN_API_KEY}" }
line_length=100
bracket_spacing=true
wrap_comments=true

[profile.ci]
fuzz = { run = 50 }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fuzz = { run = 50 }
fuzz = { runs = 50 }

Should we run a bit more?

I also noticed that the inline comments seems to take precedence over setting it via env var or in foundry.toml which seems weird. In that case should we not use the inline comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use inline ones previously because some tests run slower than others, but now the released built diff-test binary, all of these tests are fast, so I will remove any inline configs for fuzzer (just use 256 runs by default) and even remove this as well (256 for ci seems good enough)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we could add something like the following and run it once a day on the CI.

[profile.fuzz]
fuzz = { runs = 10000 }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use inline ones previously because some tests run slower than others, but now the released built diff-test binary, all of these tests are fast, so I will remove any inline configs for fuzzer (just use 256 runs by default) and even remove this as well (256 for ci seems good enough)?

Yeah if that's not too slow that is fine I think.

Since it's almost free and only costs CPU time I think it's not a bad idea to run more iterations on the CI occasionally, but we don't have to do it as part of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 90bf8d1

flake.nix Outdated Show resolved Hide resolved
// muteate the x coordinate
mstore(mload(add(proof, mul(0x20, nthPoint))), 0x1234)
}
// else, mutate y coordinate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The y coordinate is always mutated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in b914f77

Copy link
Contributor

@philippecamacho philippecamacho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Copy link
Collaborator

@sveitser sveitser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alxiong alxiong enabled auto-merge (squash) November 15, 2023 14:28
@alxiong alxiong disabled auto-merge November 15, 2023 14:28
@alxiong alxiong merged commit 54a22fc into main Nov 15, 2023
@alxiong alxiong deleted the plonk-verifier branch November 15, 2023 14:42
sveitser pushed a commit that referenced this pull request Feb 4, 2025
Replace explorer prefix search with exact match for block and transaction hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[contract] Move PlonkVerifier contract over
4 participants