Skip to content

Commit ad1c85d

Browse files
committed
feat: deploy sp1 verifier in anvil
Co-authored-by: mechanix97
1 parent 18be091 commit ad1c85d

12 files changed

+2436
-2244
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ anvil_deploy_eigen_contracts:
7575
@echo "Deploying Eigen Contracts..."
7676
. contracts/scripts/anvil/deploy_eigen_contracts.sh
7777

78+
anvil_deploy_sp1_contracts:
79+
@echo "Deploying SP1 Contracts..."
80+
. contracts/scripts/anvil/deploy_sp1_contracts.sh
81+
7882
anvil_deploy_aligned_contracts:
7983
@echo "Deploying Aligned Contracts..."
8084
. contracts/scripts/anvil/deploy_aligned_contracts.sh

contracts/deployments/31337.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"CREATE2_SALT": "0x0000000000000000000000000000000000000000000000000000000000000009",
3+
"SP1_VERIFIER_GATEWAY_GROTH16": "0xbC42A182543d5AF01f51040955D149A74C015098",
4+
"V4_0_0_RC3_SP1_VERIFIER_GROTH16": "0x737A46c3A4579A452302130D762eFa66C6f81e28"
5+
}

contracts/foundry.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ out = "out"
44
libs = ["lib"]
55

66
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
7-
fs_permissions = [{ access = "read-write", path = "./script/output"}, {access = "read", path = "./script/deploy"}]
7+
fs_permissions = [
8+
{ access = "read-write", path = "./script/output" },
9+
{ access = "read", path = "./script/deploy" },
10+
{ access = "read-write", path = "./deployments" },
11+
]

contracts/lib/sp1-contracts

Submodule sp1-contracts added at 26651fd
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
import {BaseScript} from "../../lib/sp1-contracts/contracts/script/utils/Base.s.sol";
5+
import {SP1VerifierGateway} from "../../lib/sp1-contracts/contracts/src/SP1VerifierGateway.sol";
6+
7+
contract SP1VerifierGatewayScript is BaseScript {
8+
string internal constant KEY = "SP1_VERIFIER_GATEWAY_GROTH16";
9+
10+
function run() external multichain(KEY) broadcaster {
11+
// Read config
12+
bytes32 CREATE2_SALT = readBytes32("CREATE2_SALT");
13+
address OWNER = readAddress("OWNER");
14+
15+
// Deploy contract
16+
address gateway = address(new SP1VerifierGateway{salt: CREATE2_SALT}(OWNER));
17+
18+
// Write addresss
19+
writeAddress(KEY, gateway);
20+
}
21+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
import {BaseScript} from "../../lib/sp1-contracts/contracts/script/utils/Base.s.sol";
5+
import {SP1Verifier} from "../../lib/sp1-contracts/contracts/src/v4.0.0-rc.3/SP1VerifierGroth16.sol";
6+
import {SP1VerifierGateway} from "../../lib/sp1-contracts/contracts/src/SP1VerifierGateway.sol";
7+
import {ISP1VerifierWithHash} from "../../lib/sp1-contracts/contracts/src/ISP1Verifier.sol";
8+
9+
contract SP1VerifierScript is BaseScript {
10+
string internal constant KEY = "V4_0_0_RC3_SP1_VERIFIER_GROTH16";
11+
12+
function run() external multichain(KEY) broadcaster {
13+
// Read config
14+
bytes32 CREATE2_SALT = readBytes32("CREATE2_SALT");
15+
address SP1_VERIFIER_GATEWAY = readAddress("SP1_VERIFIER_GATEWAY_GROTH16");
16+
17+
// Deploy contract
18+
address verifier = address(new SP1Verifier{salt: CREATE2_SALT}());
19+
20+
// Add the verifier to the gateway
21+
SP1VerifierGateway gateway = SP1VerifierGateway(SP1_VERIFIER_GATEWAY);
22+
gateway.addRoute(verifier);
23+
24+
// Write address
25+
writeAddress(KEY, verifier);
26+
}
27+
28+
function freeze() external multichain(KEY) broadcaster {
29+
// Read config
30+
address SP1_VERIFIER_GATEWAY = readAddress("SP1_VERIFIER_GATEWAY_GROTH16");
31+
address SP1_VERIFIER = readAddress(KEY);
32+
33+
// Freeze the verifier on the gateway
34+
SP1VerifierGateway gateway = SP1VerifierGateway(SP1_VERIFIER_GATEWAY);
35+
bytes4 selector = bytes4(ISP1VerifierWithHash(SP1_VERIFIER).VERIFIER_HASH());
36+
gateway.freezeRoute(selector);
37+
}
38+
}

contracts/script/output/devnet/alignedlayer_deployment_output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"chainInfo": {
2121
"chainId": 31337,
22-
"deploymentBlock": 0
22+
"deploymentBlock": 3
2323
},
2424
"permissions": {
2525
"alignedLayerAggregator": "0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65",

contracts/scripts/anvil/deploy_aligned_contracts.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
55
# At this point we are in tests/integration
66
cd "$parent_path"
77

8-
# Start an empty anvil chain in the background and dump its state to a json file upon exit
9-
anvil --load-state state/eigenlayer-deployed-anvil-state.json --dump-state state/alignedlayer-deployed-anvil-state.json &
8+
# Start anvil chain in the background and dump its state to a json file upon exit
9+
anvil --load-state state/sp1-deployed-anvil-state.json --dump-state state/alignedlayer-deployed-anvil-state.json &
1010

1111
cd ../../
1212

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# cd to the directory of this script so that this can be run from anywhere
4+
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
5+
# At this point we are in tests/integration
6+
cd "$parent_path"
7+
8+
# Start an empty anvil chain in the background and dump its state to a json file upon exit
9+
anvil --load-state state/eigenlayer-deployed-anvil-state.json --dump-state state/sp1-deployed-anvil-state.json &
10+
11+
# cd to /contracts
12+
cd ../../
13+
14+
sleep 1
15+
16+
export CHAINS='DEVNET'
17+
export RPC_DEVNET='http://localhost:8545'
18+
19+
# Anvil account #2
20+
export OWNER='0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC'
21+
export VERIFIER_PRIVATE_KEY="0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a"
22+
23+
# Deploy Groth16 SP1 verifier gateway
24+
forge script script/deploy/SP1VerifierGatewayGroth16Deployer.s.sol:SP1VerifierGatewayScript \
25+
--rpc-url $RPC_DEVNET \
26+
--private-key $VERIFIER_PRIVATE_KEY \
27+
--broadcast
28+
29+
# Deploy Groth16 SP1 verifier
30+
forge script ./script/deploy/SP1VerifierGroth16Deployer.s.sol:SP1VerifierScript \
31+
--rpc-url $RPC_DEVNET \
32+
--private-key $VERIFIER_PRIVATE_KEY \
33+
--broadcast
34+
35+
36+
# Kill the anvil process to save state
37+
pkill anvil

contracts/scripts/anvil/state/alignedlayer-deployed-anvil-state.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)