-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add canonical address registry contract + fixed circuit (#437)
* have circuit take msg directly to avoid replays, leave digest calculation for luke * fix typo in comment * changeset * fix bitmath * fix posec comment * add draft contracts * add script to gen test case to core * add eip712 test case for canon addr registry entry * fix nits * add canonical address registry contract * remove abicoder v2, tob rec * add unit test with mock verifier for canon addr registry * make all license comments in sol files mit or apache 2 * update deploy script and e2e tests to include canon addr registry * rename deposit request hash file in core to deposit request * prog: e2e test submits canon addr set tx success * finish success test case for registry * add rest of e2e tests for registry * save snap progress before fixing op digest calc to include canon addr * snap builds with method to sign registry entry * expose fe sdk method for proving and registering addr * add compressedCanonAddr to digest, contract unit tests pass, need to fix fe-sdk and snap * fix: fe sdk passes canon addr as part of canon addr entry * fix e2e tests and add canon addr to entry * cleanup * changesets * save progress, bad digest and msg.sender e2e test calls should fail but are not * fix: require verifyProof in addr registry, e2e tests use chai as promised * post rebase yarn i * use mask instead of mod 2^252 * rebase --------- Co-authored-by: Luke Tchang <[email protected]>
- Loading branch information
1 parent
d38c29e
commit 77c4063
Showing
130 changed files
with
1,183 additions
and
273 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@nocturne-xyz/frontend-sdk": minor | ||
"@nocturne-xyz/core": minor | ||
"@nocturne-xyz/snap": minor | ||
--- | ||
|
||
Add functionality to snap/fe-sdk that supports signing a canon addr registry entry and returning necessary inputs for sig check proof gen |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@nocturne-xyz/contracts": minor | ||
--- | ||
|
||
Add CanonicalAddressRegistry contract which integrates canon addr sig check verifier, add unit tests as well for EIP712 hashing and registry state changes |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@nocturne-xyz/e2e-tests": minor | ||
--- | ||
|
||
Add e2e tests for canon addr registry |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@nocturne-xyz/config": minor | ||
"@nocturne-xyz/deploy": minor | ||
--- | ||
|
||
Add CanonicalAddressRegistry and sig check verifier to deploy and config packages |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@nocturne-xyz/local-prover": minor | ||
"@nocturne-xyz/circuits": minor | ||
"@nocturne-xyz/core": minor | ||
--- | ||
|
||
`CanonAddrSigCheck` circuit takes msg directly as PI instead of computing it from nonce |
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
Binary file modified
BIN
+41.4 KB
(100%)
circuit-artifacts/canonAddrSigCheck/canonAddrSigCheck_cpp/canonAddrSigCheck.zkey
Binary file not shown.
Binary file modified
BIN
+41.4 KB
(100%)
circuit-artifacts/canonAddrSigCheck/canonAddrSigCheck_cpp/canonAddrSigCheck_0.zkey
Binary file not shown.
Binary file modified
BIN
+41.4 KB
(100%)
circuit-artifacts/canonAddrSigCheck/canonAddrSigCheck_cpp/canonAddrSigCheck_1.zkey
Binary file not shown.
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
Binary file modified
BIN
-329 KB
(88%)
circuit-artifacts/canonAddrSigCheck/canonAddrSigCheck_js/canonAddrSigCheck.wasm
Binary file not shown.
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"proof":{"pi_a":["4707566568477662226701048704629002296898023495689302474085085543854193803155","3644575967738185505850689153930594197798302000091737453074352963009621583047","1"],"pi_b":[["13069141789356215556738799393349390032904395438451693951284966024185000982701","16413079359372682889686551964213736164909267325081402914478067411060909601738"],["10662132772867170602735388807233470982369982452803154206295065507017214400127","4210609573482297197474333202124807106129386536279608053368214238189911285716"],["1","0"]],"pi_c":["4336617563514886771836809062099125132568962461354180077456839313813411275943","6202904228419388614700373200548865108297023268079905783649845080424671268049","1"],"protocol":"groth16","curve":"bn128"},"publicSignals":["6590372629931178525044320278222256515723582191188933114746797360106155515468n","1453n"]} | ||
{"proof":{"pi_a":["5630047084404145852196878404202071164693044570330721321676781341333588762104","5255535139083995876723395176671055509390864255299011749228285185193695228901","1"],"pi_b":[["12283154930299705562303463526757988689290201186127646279800710714166407338636","6516582753066308242934026658946013128564007414906215796376877261005233776079"],["1034684672340757360878561019818456289937999191141133820206372131499300689111","12008549011081544495151508087453846999773609320011469369232264723680826797336"],["1","0"]],"pi_c":["1365930388966472203706781819223319674052243487788680138590293792437643151816","21289716135235906338137180885035493028168989099470691987747086359134740017437","1"],"protocol":"groth16","curve":"bn128"},"publicSignals":["6590372629931178525044320278222256515723582191188933114746797360106155515468n","1453n"]} |
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
73 changes: 73 additions & 0 deletions
73
packages/contracts/contracts/CanonAddrRegistryEntryEIP712.sol
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity ^0.8.17; | ||
|
||
// External | ||
import {ECDSAUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol"; | ||
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
import {EIP712Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol"; | ||
// Internal | ||
import {Utils} from "./libs/Utils.sol"; | ||
import "./libs/Types.sol"; | ||
|
||
/// @title CanonAddrRegistryEntryEIP712 | ||
/// @author Nocturne Labs | ||
/// @notice Base contract for CanonicalAddressRegistry containing EIP712 signing logic for canon | ||
/// addr registry entries | ||
contract CanonAddrRegistryEntryEIP712 is EIP712Upgradeable { | ||
uint256 constant BOTTOM_252_MASK = (1 << 252) - 1; | ||
|
||
bytes32 public constant CANON_ADDR_REGISTRY_ENTRY_TYPEHASH = | ||
keccak256( | ||
bytes( | ||
"CanonAddrRegistryEntry(address ethAddress,uint256 compressedCanonAddr,uint256 perCanonAddrNonce)" | ||
) | ||
); | ||
|
||
uint256 constant MODULUS_252 = 2 ** 252; | ||
|
||
/// @notice Internal initializer | ||
/// @param contractName Name of the contract | ||
/// @param contractVersion Version of the contract | ||
function __CanonAddrRegistryEntryEIP712_init( | ||
string memory contractName, | ||
string memory contractVersion | ||
) internal onlyInitializing { | ||
__EIP712_init(contractName, contractVersion); | ||
} | ||
|
||
/// @notice Computes EIP712 digest of canon addr registry entry | ||
/// @param entry Canon addr registry entry | ||
/// @dev The returned uint256 is masked to zero out the top 4 MSBs. The top 3 MSBs | ||
/// are 0 because the circuit verifier must take elems <= 253 bits. The 4th MSB is 0 to | ||
/// leave space for the sign bit of the compressed canon addr. | ||
function _computeDigest( | ||
CanonAddrRegistryEntry memory entry | ||
) public view returns (uint256) { | ||
bytes32 domainSeparator = _domainSeparatorV4(); | ||
bytes32 structHash = _hashCanonAddrRegistryEntry(entry); | ||
|
||
bytes32 digest = ECDSAUpgradeable.toTypedDataHash( | ||
domainSeparator, | ||
structHash | ||
); | ||
|
||
// Only take bottom 252 bits to fit compressed addr sign bit in 253rd PI bit | ||
return uint256(digest) & BOTTOM_252_MASK; | ||
} | ||
|
||
/// @notice Hashes canon addr registry entry | ||
/// @param entry Canon addr registry entry | ||
function _hashCanonAddrRegistryEntry( | ||
CanonAddrRegistryEntry memory entry | ||
) internal pure returns (bytes32) { | ||
return | ||
keccak256( | ||
abi.encode( | ||
CANON_ADDR_REGISTRY_ENTRY_TYPEHASH, | ||
entry.ethAddress, | ||
entry.compressedCanonAddr, | ||
entry.perCanonAddrNonce | ||
) | ||
); | ||
} | ||
} |
Oops, something went wrong.