From 239127aae54b16a19d7f556e3a2b57f4ab93f8da Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sat, 14 Sep 2024 22:12:32 -0400 Subject: [PATCH] Add crate for the Ethereum contracts --- .github/workflows/tests.yml | 2 +- Cargo.lock | 8 ++++ Cargo.toml | 1 + deny.toml | 1 + .../{ethereum-serai => contracts}/.gitignore | 0 processor/ethereum/contracts/Cargo.toml | 20 ++++++++ processor/ethereum/contracts/LICENSE | 15 ++++++ processor/ethereum/contracts/README.md | 7 +++ .../{ethereum-serai => contracts}/build.rs | 12 +++-- .../contracts/Deployer.sol | 0 .../contracts/IERC20.sol | 0 .../contracts/Router.sol | 0 .../contracts/Sandbox.sol | 0 .../contracts/Schnorr.sol | 0 .../contracts/tests}/ERC20.sol | 0 .../contracts/tests}/Schnorr.sol | 0 processor/ethereum/contracts/src/lib.rs | 48 +++++++++++++++++++ .../abi/mod.rs => contracts/src/tests.rs} | 4 +- processor/ethereum/ethereum-serai/Cargo.toml | 2 + .../ethereum/ethereum-serai/src/abi/mod.rs | 37 -------------- .../ethereum/ethereum-serai/src/deployer.rs | 2 +- processor/ethereum/ethereum-serai/src/lib.rs | 6 ++- .../ethereum/ethereum-serai/src/router.rs | 2 +- .../ethereum/ethereum-serai/src/tests/mod.rs | 2 +- 24 files changed, 121 insertions(+), 48 deletions(-) rename processor/ethereum/{ethereum-serai => contracts}/.gitignore (100%) create mode 100644 processor/ethereum/contracts/Cargo.toml create mode 100644 processor/ethereum/contracts/LICENSE create mode 100644 processor/ethereum/contracts/README.md rename processor/ethereum/{ethereum-serai => contracts}/build.rs (78%) rename processor/ethereum/{ethereum-serai => contracts}/contracts/Deployer.sol (100%) rename processor/ethereum/{ethereum-serai => contracts}/contracts/IERC20.sol (100%) rename processor/ethereum/{ethereum-serai => contracts}/contracts/Router.sol (100%) rename processor/ethereum/{ethereum-serai => contracts}/contracts/Sandbox.sol (100%) rename processor/ethereum/{ethereum-serai => contracts}/contracts/Schnorr.sol (100%) rename processor/ethereum/{ethereum-serai/src/tests/contracts => contracts/contracts/tests}/ERC20.sol (100%) rename processor/ethereum/{ethereum-serai/src/tests/contracts => contracts/contracts/tests}/Schnorr.sol (100%) create mode 100644 processor/ethereum/contracts/src/lib.rs rename processor/ethereum/{ethereum-serai/src/tests/abi/mod.rs => contracts/src/tests.rs} (71%) delete mode 100644 processor/ethereum/ethereum-serai/src/abi/mod.rs diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4e1c167a..9b90ee91 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -52,7 +52,7 @@ jobs: -p serai-processor-signers \ -p serai-processor-bin \ -p serai-bitcoin-processor \ - -p ethereum-serai \ + -p serai-processor-ethereum-contracts \ -p serai-ethereum-processor \ -p serai-monero-processor \ -p tendermint-machine \ diff --git a/Cargo.lock b/Cargo.lock index e98a8f34..55108241 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2497,6 +2497,7 @@ dependencies = [ "k256", "modular-frost", "rand_core", + "serai-processor-ethereum-contracts", "thiserror", "tokio", ] @@ -8671,6 +8672,13 @@ dependencies = [ "zeroize", ] +[[package]] +name = "serai-processor-ethereum-contracts" +version = "0.1.0" +dependencies = [ + "alloy-sol-types", +] + [[package]] name = "serai-processor-frost-attempt-manager" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 09e51255..f06d76ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,6 +85,7 @@ members = [ "processor/bin", "processor/bitcoin", + "processor/ethereum/contracts", "processor/ethereum/ethereum-serai", "processor/ethereum", "processor/monero", diff --git a/deny.toml b/deny.toml index 183122e8..cef3a683 100644 --- a/deny.toml +++ b/deny.toml @@ -59,6 +59,7 @@ exceptions = [ { allow = ["AGPL-3.0"], name = "serai-bitcoin-processor" }, { allow = ["AGPL-3.0"], name = "ethereum-serai" }, + { allow = ["AGPL-3.0"], name = "serai-processor-ethereum-contracts" }, { allow = ["AGPL-3.0"], name = "serai-ethereum-processor" }, { allow = ["AGPL-3.0"], name = "serai-monero-processor" }, diff --git a/processor/ethereum/ethereum-serai/.gitignore b/processor/ethereum/contracts/.gitignore similarity index 100% rename from processor/ethereum/ethereum-serai/.gitignore rename to processor/ethereum/contracts/.gitignore diff --git a/processor/ethereum/contracts/Cargo.toml b/processor/ethereum/contracts/Cargo.toml new file mode 100644 index 00000000..87beba08 --- /dev/null +++ b/processor/ethereum/contracts/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "serai-processor-ethereum-contracts" +version = "0.1.0" +description = "Ethereum contracts for the Serai processor" +license = "AGPL-3.0-only" +repository = "https://github.com/serai-dex/serai/tree/develop/processor/ethereum/contracts" +authors = ["Luke Parker ", "Elizabeth Binks "] +edition = "2021" +publish = false +rust-version = "1.79" + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] + +[lints] +workspace = true + +[dependencies] +alloy-sol-types = { version = "0.8", default-features = false } diff --git a/processor/ethereum/contracts/LICENSE b/processor/ethereum/contracts/LICENSE new file mode 100644 index 00000000..41d5a261 --- /dev/null +++ b/processor/ethereum/contracts/LICENSE @@ -0,0 +1,15 @@ +AGPL-3.0-only license + +Copyright (c) 2022-2024 Luke Parker + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License Version 3 as +published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . diff --git a/processor/ethereum/contracts/README.md b/processor/ethereum/contracts/README.md new file mode 100644 index 00000000..fcd8f3c7 --- /dev/null +++ b/processor/ethereum/contracts/README.md @@ -0,0 +1,7 @@ +# Serai Processor Ethereum Contracts + +The Ethereum contracts used for (and for testing) the Serai processor. This is +its own crate for organizational and build-time reasons. It is not intended to +be publicly used. + +This crate will fail to build if `solc` is not installed and available. diff --git a/processor/ethereum/ethereum-serai/build.rs b/processor/ethereum/contracts/build.rs similarity index 78% rename from processor/ethereum/ethereum-serai/build.rs rename to processor/ethereum/contracts/build.rs index 38fcfe00..fe79fcc1 100644 --- a/processor/ethereum/ethereum-serai/build.rs +++ b/processor/ethereum/contracts/build.rs @@ -28,14 +28,18 @@ fn main() { "./contracts/Sandbox.sol", "./contracts/Router.sol", - "./src/tests/contracts/Schnorr.sol", - "./src/tests/contracts/ERC20.sol", + "./contracts/tests/Schnorr.sol", + "./contracts/tests/ERC20.sol", "--no-color", ]; let solc = Command::new("solc").args(args).output().unwrap(); assert!(solc.status.success()); - for line in String::from_utf8(solc.stderr).unwrap().lines() { - assert!(!line.starts_with("Error:")); + let stderr = String::from_utf8(solc.stderr).unwrap(); + for line in stderr.lines() { + if line.contains("Error:") { + println!("{stderr}"); + panic!() + } } } diff --git a/processor/ethereum/ethereum-serai/contracts/Deployer.sol b/processor/ethereum/contracts/contracts/Deployer.sol similarity index 100% rename from processor/ethereum/ethereum-serai/contracts/Deployer.sol rename to processor/ethereum/contracts/contracts/Deployer.sol diff --git a/processor/ethereum/ethereum-serai/contracts/IERC20.sol b/processor/ethereum/contracts/contracts/IERC20.sol similarity index 100% rename from processor/ethereum/ethereum-serai/contracts/IERC20.sol rename to processor/ethereum/contracts/contracts/IERC20.sol diff --git a/processor/ethereum/ethereum-serai/contracts/Router.sol b/processor/ethereum/contracts/contracts/Router.sol similarity index 100% rename from processor/ethereum/ethereum-serai/contracts/Router.sol rename to processor/ethereum/contracts/contracts/Router.sol diff --git a/processor/ethereum/ethereum-serai/contracts/Sandbox.sol b/processor/ethereum/contracts/contracts/Sandbox.sol similarity index 100% rename from processor/ethereum/ethereum-serai/contracts/Sandbox.sol rename to processor/ethereum/contracts/contracts/Sandbox.sol diff --git a/processor/ethereum/ethereum-serai/contracts/Schnorr.sol b/processor/ethereum/contracts/contracts/Schnorr.sol similarity index 100% rename from processor/ethereum/ethereum-serai/contracts/Schnorr.sol rename to processor/ethereum/contracts/contracts/Schnorr.sol diff --git a/processor/ethereum/ethereum-serai/src/tests/contracts/ERC20.sol b/processor/ethereum/contracts/contracts/tests/ERC20.sol similarity index 100% rename from processor/ethereum/ethereum-serai/src/tests/contracts/ERC20.sol rename to processor/ethereum/contracts/contracts/tests/ERC20.sol diff --git a/processor/ethereum/ethereum-serai/src/tests/contracts/Schnorr.sol b/processor/ethereum/contracts/contracts/tests/Schnorr.sol similarity index 100% rename from processor/ethereum/ethereum-serai/src/tests/contracts/Schnorr.sol rename to processor/ethereum/contracts/contracts/tests/Schnorr.sol diff --git a/processor/ethereum/contracts/src/lib.rs b/processor/ethereum/contracts/src/lib.rs new file mode 100644 index 00000000..fef10288 --- /dev/null +++ b/processor/ethereum/contracts/src/lib.rs @@ -0,0 +1,48 @@ +use alloy_sol_types::sol; + +#[rustfmt::skip] +#[expect(warnings)] +#[expect(needless_pass_by_value)] +#[expect(clippy::all)] +#[expect(clippy::ignored_unit_patterns)] +#[expect(clippy::redundant_closure_for_method_calls)] +mod erc20_container { + use super::*; + sol!("contracts/IERC20.sol"); +} +pub mod erc20 { + pub const BYTECODE: &str = include_str!("../artifacts/Deployer.bin"); + pub use super::erc20_container::IERC20::*; +} + +#[rustfmt::skip] +#[expect(warnings)] +#[expect(needless_pass_by_value)] +#[expect(clippy::all)] +#[expect(clippy::ignored_unit_patterns)] +#[expect(clippy::redundant_closure_for_method_calls)] +mod deployer_container { + use super::*; + sol!("contracts/Deployer.sol"); +} +pub mod deployer { + pub const BYTECODE: &str = include_str!("../artifacts/Deployer.bin"); + pub use super::deployer_container::Deployer::*; +} + +#[rustfmt::skip] +#[expect(warnings)] +#[expect(needless_pass_by_value)] +#[expect(clippy::all)] +#[expect(clippy::ignored_unit_patterns)] +#[expect(clippy::redundant_closure_for_method_calls)] +mod router_container { + use super::*; + sol!(Router, "artifacts/Router.abi"); +} +pub mod router { + pub const BYTECODE: &str = include_str!("../artifacts/Router.bin"); + pub use super::router_container::Router::*; +} + +pub mod tests; diff --git a/processor/ethereum/ethereum-serai/src/tests/abi/mod.rs b/processor/ethereum/contracts/src/tests.rs similarity index 71% rename from processor/ethereum/ethereum-serai/src/tests/abi/mod.rs rename to processor/ethereum/contracts/src/tests.rs index 57ea8811..9f141c29 100644 --- a/processor/ethereum/ethereum-serai/src/tests/abi/mod.rs +++ b/processor/ethereum/contracts/src/tests.rs @@ -8,6 +8,6 @@ use alloy_sol_types::sol; #[allow(clippy::redundant_closure_for_method_calls)] mod schnorr_container { use super::*; - sol!("src/tests/contracts/Schnorr.sol"); + sol!("contracts/tests/Schnorr.sol"); } -pub(crate) use schnorr_container::TestSchnorr as schnorr; +pub use schnorr_container::TestSchnorr as schnorr; diff --git a/processor/ethereum/ethereum-serai/Cargo.toml b/processor/ethereum/ethereum-serai/Cargo.toml index ed4520d1..f0ea323f 100644 --- a/processor/ethereum/ethereum-serai/Cargo.toml +++ b/processor/ethereum/ethereum-serai/Cargo.toml @@ -38,6 +38,8 @@ alloy-provider = { version = "0.3", default-features = false } alloy-node-bindings = { version = "0.3", default-features = false, optional = true } +contracts = { package = "serai-processor-ethereum-contracts", path = "../contracts" } + [dev-dependencies] frost = { package = "modular-frost", path = "../../../crypto/frost", default-features = false, features = ["tests"] } diff --git a/processor/ethereum/ethereum-serai/src/abi/mod.rs b/processor/ethereum/ethereum-serai/src/abi/mod.rs deleted file mode 100644 index 1ae23374..00000000 --- a/processor/ethereum/ethereum-serai/src/abi/mod.rs +++ /dev/null @@ -1,37 +0,0 @@ -use alloy_sol_types::sol; - -#[rustfmt::skip] -#[allow(warnings)] -#[allow(needless_pass_by_value)] -#[allow(clippy::all)] -#[allow(clippy::ignored_unit_patterns)] -#[allow(clippy::redundant_closure_for_method_calls)] -mod erc20_container { - use super::*; - sol!("contracts/IERC20.sol"); -} -pub use erc20_container::IERC20 as erc20; - -#[rustfmt::skip] -#[allow(warnings)] -#[allow(needless_pass_by_value)] -#[allow(clippy::all)] -#[allow(clippy::ignored_unit_patterns)] -#[allow(clippy::redundant_closure_for_method_calls)] -mod deployer_container { - use super::*; - sol!("contracts/Deployer.sol"); -} -pub use deployer_container::Deployer as deployer; - -#[rustfmt::skip] -#[allow(warnings)] -#[allow(needless_pass_by_value)] -#[allow(clippy::all)] -#[allow(clippy::ignored_unit_patterns)] -#[allow(clippy::redundant_closure_for_method_calls)] -mod router_container { - use super::*; - sol!(Router, "artifacts/Router.abi"); -} -pub use router_container::Router as router; diff --git a/processor/ethereum/ethereum-serai/src/deployer.rs b/processor/ethereum/ethereum-serai/src/deployer.rs index 19aa328d..88f4a5fb 100644 --- a/processor/ethereum/ethereum-serai/src/deployer.rs +++ b/processor/ethereum/ethereum-serai/src/deployer.rs @@ -30,7 +30,7 @@ impl Deployer { /// funded for this transaction to be submitted. This account has no known private key to anyone, /// so ETH sent can be neither misappropriated nor returned. pub fn deployment_tx() -> Signed { - let bytecode = include_str!("../artifacts/Deployer.bin"); + let bytecode = contracts::deployer::BYTECODE; let bytecode = Bytes::from_hex(bytecode).expect("compiled-in Deployer bytecode wasn't valid hex"); diff --git a/processor/ethereum/ethereum-serai/src/lib.rs b/processor/ethereum/ethereum-serai/src/lib.rs index 38bd79e7..76121401 100644 --- a/processor/ethereum/ethereum-serai/src/lib.rs +++ b/processor/ethereum/ethereum-serai/src/lib.rs @@ -15,7 +15,11 @@ pub mod alloy { pub mod crypto; -pub(crate) mod abi; +pub(crate) mod abi { + pub use contracts::erc20; + pub use contracts::deployer; + pub use contracts::router; +} pub mod erc20; pub mod deployer; diff --git a/processor/ethereum/ethereum-serai/src/router.rs b/processor/ethereum/ethereum-serai/src/router.rs index c569d409..95866e67 100644 --- a/processor/ethereum/ethereum-serai/src/router.rs +++ b/processor/ethereum/ethereum-serai/src/router.rs @@ -135,7 +135,7 @@ pub struct Executed { pub struct Router(Arc>, Address); impl Router { pub(crate) fn code() -> Vec { - let bytecode = include_str!("../artifacts/Router.bin"); + let bytecode = contracts::router::BYTECODE; Bytes::from_hex(bytecode).expect("compiled-in Router bytecode wasn't valid hex").to_vec() } diff --git a/processor/ethereum/ethereum-serai/src/tests/mod.rs b/processor/ethereum/ethereum-serai/src/tests/mod.rs index dcdbedce..bdfa8414 100644 --- a/processor/ethereum/ethereum-serai/src/tests/mod.rs +++ b/processor/ethereum/ethereum-serai/src/tests/mod.rs @@ -21,7 +21,7 @@ use crate::crypto::{address, deterministically_sign, PublicKey}; mod crypto; #[cfg(test)] -mod abi; +use contracts::tests as abi; #[cfg(test)] mod schnorr; #[cfg(test)]