Skip to content

Commit

Permalink
auto create deploy scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed Oct 16, 2024
1 parent f74b82c commit 70ab895
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
38 changes: 38 additions & 0 deletions contracts/script/deploy/v3.0.0-rc4/SP1VerifierGroth16.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {BaseScript} from "../../utils/Base.s.sol";
import {SP1Verifier} from "../../../src/v3.0.0-rc4/SP1VerifierGroth16.sol";
import {SP1VerifierGateway} from "../../../src/SP1VerifierGateway.sol";
import {ISP1VerifierWithHash} from "../../../src/ISP1Verifier.sol";

contract SP1VerifierScript is BaseScript {
string internal constant KEY = "V3_0_0_RC4_SP1_VERIFIER_GROTH16";

function run() external multichain(KEY) broadcaster {
// Read config
bytes32 CREATE2_SALT = readBytes32("CREATE2_SALT");
address SP1_VERIFIER_GATEWAY = readAddress("SP1_VERIFIER_GATEWAY");

// Deploy contract
address verifier = address(new SP1Verifier{salt: CREATE2_SALT}());

// Add the verifier to the gateway
SP1VerifierGateway gateway = SP1VerifierGateway(SP1_VERIFIER_GATEWAY);
gateway.addRoute(verifier);

// Write address
writeAddress(KEY, verifier);
}

function freeze() external multichain(KEY) broadcaster {
// Read config
address SP1_VERIFIER_GATEWAY = readAddress("SP1_VERIFIER_GATEWAY");
address SP1_VERIFIER = readAddress(KEY);

// Freeze the verifier on the gateway
SP1VerifierGateway gateway = SP1VerifierGateway(SP1_VERIFIER_GATEWAY);
bytes4 selector = bytes4(ISP1VerifierWithHash(SP1_VERIFIER).VERIFIER_HASH());
gateway.freezeRoute(selector);
}
}
38 changes: 38 additions & 0 deletions contracts/script/deploy/v3.0.0-rc4/SP1VerifierPlonk.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {BaseScript} from "../../utils/Base.s.sol";
import {SP1Verifier} from "../../../src/v3.0.0-rc4/SP1VerifierPlonk.sol";
import {SP1VerifierGateway} from "../../../src/SP1VerifierGateway.sol";
import {ISP1VerifierWithHash} from "../../../src/ISP1Verifier.sol";

contract SP1VerifierScript is BaseScript {
string internal constant KEY = "V3_0_0_RC4_SP1_VERIFIER_PLONK";

function run() external multichain(KEY) broadcaster {
// Read config
bytes32 CREATE2_SALT = readBytes32("CREATE2_SALT");
address SP1_VERIFIER_GATEWAY = readAddress("SP1_VERIFIER_GATEWAY");

// Deploy contract
address verifier = address(new SP1Verifier{salt: CREATE2_SALT}());

// Add the verifier to the gateway
SP1VerifierGateway gateway = SP1VerifierGateway(SP1_VERIFIER_GATEWAY);
gateway.addRoute(verifier);

// Write address
writeAddress(KEY, verifier);
}

function freeze() external multichain(KEY) broadcaster {
// Read config
address SP1_VERIFIER_GATEWAY = readAddress("SP1_VERIFIER_GATEWAY");
address SP1_VERIFIER = readAddress(KEY);

// Freeze the verifier on the gateway
SP1VerifierGateway gateway = SP1VerifierGateway(SP1_VERIFIER_GATEWAY);
bytes4 selector = bytes4(ISP1VerifierWithHash(SP1_VERIFIER).VERIFIER_HASH());
gateway.freezeRoute(selector);
}
}
48 changes: 48 additions & 0 deletions src/bin/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,53 @@ fn main() -> Result<()> {
contracts_src_dir.display()
);

// Copy deployment scripts from v2.0.0 to {SP1_CIRCUIT_VERSION}
let source_deploy_dir = PathBuf::from("contracts/script/deploy/v2.0.0");
let target_deploy_dir = PathBuf::from(format!("contracts/script/deploy/{}", SP1_CIRCUIT_VERSION));
create_dir_all(&target_deploy_dir)?;

for entry in read_dir(source_deploy_dir)? {
let entry = entry?;
let source_path = entry.path();
if source_path.is_file() {
let file_name = source_path.file_name().unwrap();
let target_path = target_deploy_dir.join(file_name);
std::fs::copy(&source_path, &target_path)?;

// Modify SP1VerifierGroth16.s.sol
if file_name == "SP1VerifierGroth16.s.sol" {
let mut content = String::from_utf8(read(&target_path)?)?;
content = content.replace(
"import {SP1Verifier} from \"../../../src/v2.0.0/SP1VerifierGroth16.sol\";",
&format!("import {{SP1Verifier}} from \"../../../src/{}/SP1VerifierGroth16.sol\";", SP1_CIRCUIT_VERSION)
);
content = content.replace(
"string internal constant KEY = \"V2_0_0_SP1_VERIFIER_GROTH16\";",
&format!("string internal constant KEY = \"{}_SP1_VERIFIER_GROTH16\";", SP1_CIRCUIT_VERSION.replace(".", "_").replace("-", "_").to_uppercase())
);
write(&target_path, content)?;
}

// Modify SP1VerifierPlonk.s.sol
if file_name == "SP1VerifierPlonk.s.sol" {
let mut content = String::from_utf8(read(&target_path)?)?;
content = content.replace(
"import {SP1Verifier} from \"../../../src/v2.0.0/SP1VerifierPlonk.sol\";",
&format!("import {{SP1Verifier}} from \"../../../src/{}/SP1VerifierPlonk.sol\";", SP1_CIRCUIT_VERSION)
);
content = content.replace(
"string internal constant KEY = \"V2_0_0_SP1_VERIFIER_PLONK\";",
&format!("string internal constant KEY = \"{}_SP1_VERIFIER_PLONK\";", SP1_CIRCUIT_VERSION.replace(".", "_").replace("-", "_").to_uppercase())
);
write(&target_path, content)?;
}
}
}

println!(
"Copied and updated deployment scripts to {}",
target_deploy_dir.display()
);

Ok(())
}

0 comments on commit 70ab895

Please sign in to comment.