Add crate for the Ethereum contracts

This commit is contained in:
Luke Parker 2024-09-14 22:12:32 -04:00
parent d9543bee40
commit 239127aae5
24 changed files with 121 additions and 48 deletions

View file

@ -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 \

8
Cargo.lock generated
View file

@ -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"

View file

@ -85,6 +85,7 @@ members = [
"processor/bin",
"processor/bitcoin",
"processor/ethereum/contracts",
"processor/ethereum/ethereum-serai",
"processor/ethereum",
"processor/monero",

View file

@ -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" },

View file

@ -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 <lukeparker5132@gmail.com>", "Elizabeth Binks <elizabethjbinks@gmail.com>"]
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 }

View file

@ -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 <http://www.gnu.org/licenses/>.

View file

@ -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.

View file

@ -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!()
}
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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"] }

View file

@ -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;

View file

@ -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<TxLegacy> {
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");

View file

@ -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;

View file

@ -135,7 +135,7 @@ pub struct Executed {
pub struct Router(Arc<RootProvider<SimpleRequest>>, Address);
impl Router {
pub(crate) fn code() -> Vec<u8> {
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()
}

View file

@ -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)]