Files
serai/processor/ethereum/router/build.rs
Luke Parker ea00ba9ff8 Clarified usage of CREATE
CREATE was originally intended for gas savings. While one sketch did move to
CREATE2, the security concerns around address collisions (requiring all init
codes not be malleable to achieve security) continue to justify this.

To resolve the gas estimation concerns raised in the prior commit, the
createAddress function has been made constant-gas.
2025-01-27 07:36:13 -05:00

71 lines
2.0 KiB
Rust

use std::{env, fs};
use alloy_sol_macro_input::SolInputKind;
fn write(sol: syn_solidity::File, file: &str) {
let sol = alloy_sol_macro_expander::expand::expand(sol).unwrap();
fs::write(file, sol.to_string()).unwrap();
}
fn sol(sol_files: &[&str], file: &str) {
let mut sol = String::new();
for sol_file in sol_files {
sol += &fs::read_to_string(sol_file).unwrap();
}
let SolInputKind::Sol(sol) = syn::parse_str(&sol).unwrap() else {
panic!("parsed .sols file wasn't SolInputKind::Sol");
};
write(sol, file);
}
fn main() {
let artifacts_path =
env::var("OUT_DIR").unwrap().to_string() + "/serai-processor-ethereum-router";
if !fs::exists(&artifacts_path).unwrap() {
fs::create_dir(&artifacts_path).unwrap();
}
build_solidity_contracts::build(
&["../../../networks/ethereum/schnorr/contracts", "../erc20/contracts", "contracts"],
"contracts",
&artifacts_path,
)
.unwrap();
// These are detected multiple times and distinguished, hence their renaming to canonical forms
fs::rename(
artifacts_path.clone() + "/Router_sol_Router.bin",
artifacts_path.clone() + "/Router.bin",
)
.unwrap();
fs::rename(
artifacts_path.clone() + "/Router_sol_Router.bin-runtime",
artifacts_path.clone() + "/Router.bin-runtime",
)
.unwrap();
// This cannot be handled with the sol! macro. The Router requires an import
// https://github.com/alloy-rs/core/issues/602
sol(
&[
"../../../networks/ethereum/schnorr/contracts/Schnorr.sol",
"contracts/IRouter.sol",
"contracts/Router.sol",
],
&(artifacts_path.clone() + "/router.rs"),
);
let test_artifacts_path = artifacts_path + "/tests";
if !fs::exists(&test_artifacts_path).unwrap() {
fs::create_dir(&test_artifacts_path).unwrap();
}
// Build the test contracts
build_solidity_contracts::build(
&["../../../networks/ethereum/schnorr/contracts", "../erc20/contracts", "contracts"],
"contracts/tests",
&test_artifacts_path,
)
.unwrap();
}