Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 72 additions & 57 deletions MakefileEks.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,41 @@ start-bk-test-morph-test-qanet-to-morph-gas-price-oracle-qanet:
# mainnet
build-bk-prod-morph-prod-mainnet-to-morph-prover:
if [ ! -d dist ]; then mkdir -p dist; fi
cd $(PWD)/prover/bin/server && RUSTFLAGS="-C target-feature=+avx2,+avx512f" cargo build --release
cd $(PWD)/prover/bin/server && CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release
cp prover/target/release/prover-server dist/
cp -r prover/configs dist/
aws s3 cp s3://morph-0582-morph-technical-department-mainnet-data/morph-setup/secret-manager-wrapper.tar.gz ./
tar -xvzf secret-manager-wrapper.tar.gz

start-bk-prod-morph-prod-mainnet-to-morph-prover:
/data/secret-manager-wrapper ./prover-server

# testnet
build-bk-prod-morph-prod-testnet-to-morph-prover-hoodi:
if [ ! -d dist ]; then mkdir -p dist; fi
cd $(PWD)/prover/bin/server && CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release
cp prover/target/release/prover-server dist/
aws s3 cp s3://morph-0582-morph-technical-department-testnet-data/testnet/hoodi/morph-setup/secret-manager-wrapper.tar.gz ./
tar -xvzf secret-manager-wrapper.tar.gz

start-bk-prod-morph-prod-testnet-to-morph-prover-hoodi:
/data/secret-manager-wrapper ./prover-server

# qanet
build-bk-test-morph-test-qanet-to-morph-prover:
if [ ! -d dist ]; then mkdir -p dist; fi
cd $(PWD)/prover/bin/server && CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release
cp prover/target/release/prover-server dist/
aws s3 cp s3://morph-7637-morph-technical-department-qanet-data/morph-setup/secret-manager-wrapper.tar.gz ./
tar -xvzf secret-manager-wrapper.tar.gz

start-bk-test-morph-test-qanet-to-morph-prover:
/data/secret-manager-wrapper ./prover-server

# challenge-handler
# mainnet
build-bk-prod-morph-prod-mainnet-to-morph-challenge-handler:
if [ ! -d dist ]; then mkdir -p dist; fi
cd $(PWD)/prover/bin/challenge && cargo build --release
cd $(PWD)/prover/bin/challenge && CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release
cp prover/bin/challenge/target/release/challenge-handler dist/
aws s3 cp s3://morph-0582-morph-technical-department-mainnet-data/morph-setup/secret-manager-wrapper.tar.gz ./
tar -xvzf secret-manager-wrapper.tar.gz
Expand All @@ -58,18 +79,63 @@ build-bk-prod-morph-prod-mainnet-to-morph-challenge-handler:
start-bk-prod-morph-prod-mainnet-to-morph-challenge-handler:
/data/secret-manager-wrapper ./challenge-handler

# testnet
build-bk-prod-morph-prod-testnet-to-morph-challenge-handler-hoodi:
if [ ! -d dist ]; then mkdir -p dist; fi
cd $(PWD)/prover/bin/challenge && CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release
cp prover/bin/challenge/target/release/challenge-handler dist/
aws s3 cp s3://morph-0582-morph-technical-department-testnet-data/testnet/hoodi/morph-setup/secret-manager-wrapper.tar.gz ./
tar -xvzf secret-manager-wrapper.tar.gz

start-bk-prod-morph-prod-testnet-to-morph-challenge-handler-hoodi:
/data/secret-manager-wrapper ./challenge-handler

# qanet
build-bk-test-morph-test-qanet-to-morph-challenge-handler:
if [ ! -d dist ]; then mkdir -p dist; fi
cd $(PWD)/prover/bin/challenge && CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release
cp prover/bin/challenge/target/release/challenge-handler dist/
aws s3 cp s3://morph-7637-morph-technical-department-qanet-data/morph-setup/secret-manager-wrapper.tar.gz ./
tar -xvzf secret-manager-wrapper.tar.gz

start-bk-test-morph-test-qanet-to-morph-challenge-handler:
/data/secret-manager-wrapper ./challenge-handler

# shadow-proving
# mainnet
build-bk-prod-morph-prod-mainnet-to-morph-shadow-proving:
if [ ! -d dist ]; then mkdir -p dist; fi
cd $(PWD)/prover/bin/shadow-prove && cargo build --release
cp prover/bin/shadow-prove/target/release/shadow-proving dist/
cd $(PWD)/prover/bin/shadow-prove && CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release
cp prover/target/release/shadow-proving dist/
aws s3 cp s3://morph-0582-morph-technical-department-mainnet-data/morph-setup/secret-manager-wrapper.tar.gz ./
tar -xvzf secret-manager-wrapper.tar.gz

start-bk-prod-morph-prod-mainnet-to-morph-shadow-proving:
/data/secret-manager-wrapper ./shadow-proving

# testnet
build-bk-prod-morph-prod-testnet-to-morph-shadow-proving-hoodi:
if [ ! -d dist ]; then mkdir -p dist; fi
cd $(PWD)/prover/bin/shadow-prove && CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release
cp prover/target/release/shadow-proving dist/
aws s3 cp s3://morph-0582-morph-technical-department-testnet-data/testnet/hoodi/morph-setup/secret-manager-wrapper.tar.gz ./
tar -xvzf secret-manager-wrapper.tar.gz

start-bk-prod-morph-prod-testnet-to-morph-shadow-proving-hoodi:
/data/secret-manager-wrapper ./shadow-proving

# qanet
build-bk-test-morph-test-qanet-to-morph-shadow-proving:
if [ ! -d dist ]; then mkdir -p dist; fi
cd $(PWD)/prover/bin/shadow-prove && CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release
cp prover/target/release/shadow-proving dist/
aws s3 cp s3://morph-7637-morph-technical-department-qanet-data/morph-setup/secret-manager-wrapper.tar.gz ./
tar -xvzf secret-manager-wrapper.tar.gz

start-bk-test-morph-test-qanet-to-morph-shadow-proving:
/data/secret-manager-wrapper ./shadow-proving


# staking-oracle
# mainnet
build-bk-prod-morph-prod-mainnet-to-morph-staking-oracle:
Expand Down Expand Up @@ -129,19 +195,6 @@ start-bk-prod-morph-prod-mainnet-to-morph-token-price-oracle:
/data/secret-manager-wrapper ./token-price-oracle


# gas-oracle
# testnet
build-bk-prod-morph-prod-testnet-to-morph-gas-price-oracle-holesky:
if [ ! -d dist ]; then mkdir -p dist; fi
cd $(PWD)/gas-oracle/app && cargo build --release
cp gas-oracle/app/target/release/app dist/
aws s3 cp s3://morph-0582-morph-technical-department-testnet-data/testnet/holesky/morph-setup/secret-manager-wrapper.tar.gz ./
tar -xvzf secret-manager-wrapper.tar.gz


start-bk-prod-morph-prod-testnet-to-morph-gas-price-oracle-holesky:
/data/secret-manager-wrapper ./app

# gas-oracle
# hoodi
build-bk-prod-morph-prod-testnet-to-morph-gas-price-oracle-hoodi:
Expand All @@ -156,44 +209,6 @@ start-bk-prod-morph-prod-testnet-to-morph-gas-price-oracle-hoodi:
/data/secret-manager-wrapper ./app


# prover
# testnet
build-bk-prod-morph-prod-testnet-to-morph-prover-holesky:
if [ ! -d dist ]; then mkdir -p dist; fi
cd $(PWD)/prover/bin/server && RUSTFLAGS="-C target-feature=+avx2,+avx512f" cargo build --release
cp prover/target/release/prover-server dist/
cp -r prover/configs dist/
aws s3 cp s3://morph-0582-morph-technical-department-testnet-data/testnet/holesky/morph-setup/secret-manager-wrapper.tar.gz ./
tar -xvzf secret-manager-wrapper.tar.gz

start-bk-prod-morph-prod-testnet-to-morph-prover-holesky:
/data/secret-manager-wrapper ./prover-server

# challenge-handler
# testnet
build-bk-prod-morph-prod-testnet-to-morph-challenge-handler-holesky:
if [ ! -d dist ]; then mkdir -p dist; fi
cd $(PWD)/prover/bin/challenge && cargo build --release
cp prover/bin/challenge/target/release/challenge-handler dist/
aws s3 cp s3://morph-0582-morph-technical-department-testnet-data/testnet/holesky/morph-setup/secret-manager-wrapper.tar.gz ./
tar -xvzf secret-manager-wrapper.tar.gz


start-bk-prod-morph-prod-testnet-to-morph-challenge-handler-holesky:
/data/secret-manager-wrapper ./challenge-handler

# shadow-proving
# testnet
build-bk-prod-morph-prod-testnet-to-morph-shadow-proving-holesky:
if [ ! -d dist ]; then mkdir -p dist; fi
cd $(PWD)/prover/bin/shadow-prove && cargo build --release
cp prover/bin/shadow-prove/target/release/shadow-proving dist/
aws s3 cp s3://morph-0582-morph-technical-department-testnet-data/testnet/holesky/morph-setup/secret-manager-wrapper.tar.gz ./
tar -xvzf secret-manager-wrapper.tar.gz

start-bk-prod-morph-prod-testnet-to-morph-shadow-proving-holesky:
/data/secret-manager-wrapper ./shadow-proving

# staking-oracle
# testnet
build-bk-prod-morph-prod-testnet-to-morph-staking-oracle-holesky:
Expand All @@ -204,4 +219,4 @@ build-bk-prod-morph-prod-testnet-to-morph-staking-oracle-holesky:
tar -xvzf secret-manager-wrapper.tar.gz

start-bk-prod-morph-prod-testnet-to-morph-staking-oracle-holesky:
/data/secret-manager-wrapper ./staking-oracle
/data/secret-manager-wrapper ./staking-oracle
46 changes: 23 additions & 23 deletions contracts/contracts/libraries/verifier/PlonkVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,38 @@ contract PlonkVerifier {
uint256 private constant G1_SRS_Y = 11763105256161367503191792604679297387056316997144156930871823008787082098465;

// ----------------------- vk ---------------------
uint256 private constant VK_NB_PUBLIC_INPUTS = 2;
uint256 private constant VK_DOMAIN_SIZE = 16777216;
uint256 private constant VK_INV_DOMAIN_SIZE = 21888241567198334088790460357988866238279339518792980768180410072331574733841;
uint256 private constant VK_OMEGA = 5709868443893258075976348696661355716898495876243883251619397131511003808859;
uint256 private constant VK_QL_COM_X = 2714773032566361735398260413518107570706289019141573602093747023461681138141;
uint256 private constant VK_QL_COM_Y = 10207220609888567477852282724812707756861966294950666667119692155077205992894;
uint256 private constant VK_QR_COM_X = 17919274808167168584263187859012763816365260341587621260815379357637476029962;
uint256 private constant VK_QR_COM_Y = 14558165337321799812085033100515533981610351056305142204990949940017867076397;
uint256 private constant VK_QM_COM_X = 1814703450159964740292891910795980721108620081843240976053374083376051887455;
uint256 private constant VK_QM_COM_Y = 11252528960397523304289223453506717847025678682133692300385063157160041127070;
uint256 private constant VK_QO_COM_X = 20843277058771674275997213106654908867381045039357421108797602213552545033079;
uint256 private constant VK_QO_COM_Y = 9646775541123942436366130063934415659078920798926708026864638413383214238671;
uint256 private constant VK_QK_COM_X = 5484717465597821820411103650564499774744032473047103693751158150047197753654;
uint256 private constant VK_QK_COM_Y = 5561799343038529497262757012400750786503050088440144551259537360162821571059;
uint256 private constant VK_NB_PUBLIC_INPUTS = 5;
uint256 private constant VK_DOMAIN_SIZE = 33554432;
uint256 private constant VK_INV_DOMAIN_SIZE = 21888242219518804655518433051623070663413851959604507555939307129453691614729;
uint256 private constant VK_OMEGA = 19200870435978225707111062059747084165650991997241425080699860725083300967194;
uint256 private constant VK_QL_COM_X = 9496857109770518741292064488682135861248962674494967861604446614769298140801;
uint256 private constant VK_QL_COM_Y = 13306697158707148893187289359474517489309092662132847111865615083807847780686;
uint256 private constant VK_QR_COM_X = 15168106396031721196861946917417531048941395918951726120971774887904231224033;
uint256 private constant VK_QR_COM_Y = 17067422783799132011484353829344785446718705273302151466551760455276544179973;
uint256 private constant VK_QM_COM_X = 2062503189072358517228813627364112801206468481541880929627061212524046867500;
uint256 private constant VK_QM_COM_Y = 16383264006058748048241814683452691377147195760917894158624764699848260181996;
uint256 private constant VK_QO_COM_X = 11276993554321744761007348475396375004546042576992247443165667159541648019615;
uint256 private constant VK_QO_COM_Y = 1336009123797329867458955655460754684518485281155722686318249389277951918969;
uint256 private constant VK_QK_COM_X = 3509076513963323471275614870100244642947645425705684850560588726111445186717;
uint256 private constant VK_QK_COM_Y = 15082251669986564403690950092410766520944967428195940447691297074393449013243;

uint256 private constant VK_S1_COM_X = 16111562061301112215931665617877464360548491176332584512747295033804502769274;
uint256 private constant VK_S1_COM_Y = 15035232142063390140879951391784254536324051421746307325879221184372296043705;
uint256 private constant VK_S1_COM_X = 20702610951114261233096944021168607816381642857429919420395478944329365232425;
uint256 private constant VK_S1_COM_Y = 6287924284852772991087729385363871923831267251255140888671281832443192104403;

uint256 private constant VK_S2_COM_X = 899944321381010541211546037826620464002745326050515852312919625047231523882;
uint256 private constant VK_S2_COM_Y = 61717668739330555376092528203839789132705738484346798874082062974863965392;
uint256 private constant VK_S2_COM_X = 645470009383750670501092774958765334436477314405650592677994973080307449345;
uint256 private constant VK_S2_COM_Y = 4256397297118091181646823265799511434474377494065149067487129126410465669924;

uint256 private constant VK_S3_COM_X = 9316901462569250008665217603385561854185385862824092362271612343176126127375;
uint256 private constant VK_S3_COM_Y = 13799900238612879579721466063922041459340434537392216736920805107993374657577;
uint256 private constant VK_S3_COM_X = 7492538199234778964992190797161279888333633666731339557560747528992222778140;
uint256 private constant VK_S3_COM_Y = 19883641962643068517995924785061749749272042967551599977561118882192215161378;

uint256 private constant VK_COSET_SHIFT = 5;


uint256 private constant VK_QCP_0_X = 21578473557091588309361521643625606794648013014197133181947992670819103775934;
uint256 private constant VK_QCP_0_Y = 18236588362476326695195531997097392315059481348147701548685746610417604595065;
uint256 private constant VK_QCP_0_X = 21276573233863489069809736193483015861331560639958294945226697354328765942402;
uint256 private constant VK_QCP_0_Y = 21667749868347388386642256911557299806363086510301513644953688310359382808300;


uint256 private constant VK_INDEX_COMMIT_API_0 = 10900304;
uint256 private constant VK_INDEX_COMMIT_API_0 = 25304569;
uint256 private constant VK_NB_CUSTOM_GATES = 1;

// ------------------------------------------------
Expand Down
41 changes: 33 additions & 8 deletions contracts/contracts/libraries/verifier/SP1VerifierPlonk.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,33 @@ contract SP1Verifier is PlonkVerifier, ISP1VerifierWithHash {
/// @param expected The verifier selector from the first 4 bytes of the VERIFIER_HASH().
error WrongVerifierSelector(bytes4 received, bytes4 expected);

/// @notice Thrown when the exit code is invalid.
error InvalidExitCode();

/// @notice Thrown when the proof is invalid.
error InvalidProof();

/// @notice Thrown when the vkRoot is invalid.
error InvalidVkRoot();

/// @notice The version of the circuit.
function VERSION() external pure returns (string memory) {
return "v5.0.0";
return "v6.1.0";
}

/// @inheritdoc ISP1VerifierWithHash
function VERIFIER_HASH() public pure returns (bytes32) {
return 0xd4e8ecd2357dd882209800acd6abb443d231cf287d77ba62b732ce937c8b56e7;
return 0x5a093a2fcb46394f5cadfe55c44d4d572fad9cec7aeb38026b0278322ef07fac;
}

/// @notice The recursion vk root.
function VK_ROOT() public pure returns (bytes32) {
return 0x002f850ee998974d6cc00e50cd0814b098c05bfade466d28573240d057f25352;
}

/// @notice Hashes the public values to a field elements inside Bn254.
/// @param publicValues The public values.
function hashPublicValues(
bytes calldata publicValues
) public pure returns (bytes32) {
function hashPublicValues(bytes calldata publicValues) public pure returns (bytes32) {
return sha256(publicValues) & bytes32(uint256((1 << 253) - 1));
}

Expand All @@ -49,13 +59,28 @@ contract SP1Verifier is PlonkVerifier, ISP1VerifierWithHash {
revert WrongVerifierSelector(receivedSelector, expectedSelector);
}

uint256 expectedVkRoot = uint256(VK_ROOT());

bytes32 publicValuesDigest = hashPublicValues(publicValues);
uint256[] memory inputs = new uint256[](2);
uint256 exitCode = uint256(bytes32(proofBytes[4:36]));
uint256 vkRoot = uint256(bytes32(proofBytes[36:68]));
uint256 nonce = uint256(bytes32(proofBytes[68:100]));

uint256[] memory inputs = new uint256[](5);
inputs[0] = uint256(programVKey);
inputs[1] = uint256(publicValuesDigest);
bool success = this.Verify(proofBytes[4:], inputs);
inputs[2] = exitCode;
inputs[3] = vkRoot;
inputs[4] = nonce;
if (exitCode != 0) {
revert InvalidExitCode();
}
if (vkRoot != expectedVkRoot) {
revert InvalidVkRoot();
}
bool success = this.Verify(proofBytes[100:], inputs);
if (!success) {
revert InvalidProof();
}
}
}
}
12 changes: 7 additions & 5 deletions contracts/contracts/test/ZkEvmVerifierV1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ZkEvmVerifierV1} from "../libraries/verifier/ZkEvmVerifierV1.sol";

struct ProofFixture {
bytes proof;
bytes32 publicValues;
bytes publicValues;
bytes32 vkey;
}

Expand Down Expand Up @@ -35,15 +35,17 @@ contract EvmTest is Test {
// Prove state success.
function test_ValidProof() public {
ProofFixture memory fixture = loadFixture();
evm.verifyPlonk(fixture.proof, abi.encodePacked(fixture.publicValues));
evm.verifyPlonk(fixture.proof, fixture.publicValues);
}

// Prove state fail.
function testRevert_InValidProof() public {
vm.expectRevert();
ProofFixture memory fixture = loadFixture();
// Create a fake proof.
fixture.proof[31] = 0x00;
evm.verifyPlonk(fixture.proof, abi.encodePacked(fixture.publicValues));
// Corrupt a byte inside the gnark proof body (proofBytes layout in
// SP1 v6: [0..4]=selector, [4..36]=exit_code, [36..68]=vk_root,
// [68..100]=nonce, [100..]=gnark proof).
fixture.proof[200] = ~fixture.proof[200];
evm.verifyPlonk(fixture.proof, fixture.publicValues);
}
}
Loading
Loading