-
Notifications
You must be signed in to change notification settings - Fork 2
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: zk shared key #586
Open
Mikelle
wants to merge
24
commits into
main
Choose a base branch
from
feat/zk-sharedkey
base: main
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.
Open
feat: zk shared key #586
+2,019
−876
Conversation
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
Mikelle
force-pushed
the
feat/zk-sharedkey
branch
from
January 28, 2025 21:06
b399491
to
016b17f
Compare
Mikelle
force-pushed
the
feat/zk-sharedkey
branch
from
January 29, 2025 00:41
89ef737
to
89789c4
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Describe your changes
Overview of the Changes in PR #586 - Zero-Knowledge Shared Key
Below is a high-level summary of what's going on in this pull request, focusing on the major changes and how they fit together. It’s grouped by core themes:
Doc for the reference: https://www.notion.so/primev/Preventing-Unopenable-Commitments-1606865efd6f8097927ed9c162ea7631
1. Zero-Knowledge (ZK) Context and Proof Flows
New
BN128.sol
Utilitycontracts/contracts/utils/BN128.sol
, which provides wrappers for two bn128 precompiles:ecAdd
(bn128 addition at0x06
)ecMul
(bn128 multiplication at0x07
)BN128AddFailed
orBN128MulFailed
.ZK Proof in
PreconfManager
PreconfManager.sol
now:zkContextHash
(like"mev-commit opening <chainID>"
)._zkProof
inopenCommitment(...)
._verifyZKProof(zkProof)
._verifyZKProof(zkProof)
:a = g^z * (providerPub)^c
a' = B^z * C^c
zkContextHash
→ a challenge_zkProof
’s challengeABI Changes
PreconfManager.abi
& generated Go bindings changed:sharedSecretKey
in function parameters/events replaced byuint256[] zkProof
.BN128AddFailed
,BN128MulFailed
,ProviderZKProofInvalid
.2. Struct / Signature Layout Changes
Commitment Data
sharedSecretKey
is removed; each side now supplies an 8-elementzkProof
array ([providerX, providerY, bidderX, bidderY, sharedX, sharedY, c, z]
).Bid Hash
EIP-712 struct for a bid now includes bidder’s BN254 public key:
Go code (e.g. encryptor/encryptor.go) updated to include (bidderPKx, bidderPKy) in ABI-encoded hashing.
Pre-Confirmation Hash
Similarly updated from:
to
3. Go Libraries and BN254 Key Handling
p2p/pkg/crypto/ecdh.go
andzkproof.go
GenerateKeyPairBN254()
→(sk, pk)
DeriveSharedKey(skA, pkB)
→ shared G1 pointC
.GenerateOptimizedProof(sk, A, B, C, context)
→(c, z)
VerifyOptimizedProof(proof, A, B, C, context)
→bool
BN254PublicKeyToBytes(...) / BN254PublicKeyFromBytes(...)
(96 bytes uncompressed).BN254PrivateKeyToBytes(...) / BN254PrivateKeyFromBytes(...)
(32 bytes forfr.Element
).keysstore.Store
:SetBN254PrivateKey(...)
,GetBN254PrivateKey(...)
SetBN254PublicKey(...)
,GetBN254PublicKey(...)
4. Effects on the P2P Side
p2p/pkg/p2p/libp2p/internal/handshake/
now exchanges BN254 public keys instead of ECDH P256.Keys
struct inp2p/pkg/p2p/p2p.go
changed:NIKEPublicKey
→*bn254.G1Affine
(was*ecdh.PublicKey
).5. Contract and Storage Adjustments
PreconfManager
:openCommitment(...)
→ final param_zkProof
.msg.sender == winner
, calls_verifyZKProof(_zkProof)
.ProviderZKProofInvalid
if verification fails.sharedSecretKey
in events.6. Typical Flow
(PKb)
in EIP-712 bid signature.(PKb)
, computes shared secretC = PKb^skProvider
, and generates a ZK proof(c,z)
for that ephemeral secret.openCommitment(…, _zkProof)
._verifyZKProof(...)
.7. Summary
sharedSecretKey bytes
approach with BN254 ECDH + zero-knowledge proof to ensure the ephemeral key is valid, without exposing it.Checklist before requesting a review