From 3cdc1536c5e6ea205c3586414ba69c91e256a97b Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Thu, 13 Nov 2025 05:44:52 -0500 Subject: [PATCH] Make `ethereum-schnorr-contract` no-`std` and no-`alloc` eligible --- networks/ethereum/schnorr/Cargo.toml | 15 +++++++++++---- networks/ethereum/schnorr/src/lib.rs | 1 + networks/ethereum/schnorr/src/signature.rs | 3 ++- processor/ethereum/router/Cargo.toml | 2 +- tests/no-std/Cargo.toml | 4 ++++ tests/no-std/src/lib.rs | 2 ++ 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/networks/ethereum/schnorr/Cargo.toml b/networks/ethereum/schnorr/Cargo.toml index bfe88776..f927557d 100644 --- a/networks/ethereum/schnorr/Cargo.toml +++ b/networks/ethereum/schnorr/Cargo.toml @@ -16,10 +16,12 @@ rustdoc-args = ["--cfg", "docsrs"] workspace = true [dependencies] -subtle = { version = "2", default-features = false, features = ["std"] } -sha3 = { version = "0.10", default-features = false, features = ["std"] } -group = { version = "0.13", default-features = false, features = ["alloc"] } -k256 = { version = "^0.13.1", default-features = false, features = ["std", "arithmetic"] } +std-shims = { path = "../../../common/std-shims", version = "0.1", default-features = false } + +subtle = { version = "2", default-features = false } +sha3 = { version = "0.10", default-features = false } +group = { version = "0.13", default-features = false } +k256 = { version = "^0.13.1", default-features = false, features = ["arithmetic"] } [build-dependencies] build-solidity-contracts = { path = "../build-contracts", version = "0.1" } @@ -40,3 +42,8 @@ alloy-provider = { version = "1", default-features = false } alloy-node-bindings = { version = "1", default-features = false } tokio = { version = "1", default-features = false, features = ["macros"] } + +[features] +alloc = ["std-shims/alloc", "group/alloc"] +std = ["alloc", "std-shims/std", "subtle/std", "sha3/std", "k256/std"] +default = ["std"] diff --git a/networks/ethereum/schnorr/src/lib.rs b/networks/ethereum/schnorr/src/lib.rs index bcef5fd9..a0cc6e07 100644 --- a/networks/ethereum/schnorr/src/lib.rs +++ b/networks/ethereum/schnorr/src/lib.rs @@ -2,6 +2,7 @@ #![doc = include_str!("../README.md")] #![deny(missing_docs)] #![allow(non_snake_case)] +#![cfg_attr(not(feature = "std"), no_std)] mod public_key; pub use public_key::PublicKey; diff --git a/networks/ethereum/schnorr/src/signature.rs b/networks/ethereum/schnorr/src/signature.rs index 105e6d4d..a3766a85 100644 --- a/networks/ethereum/schnorr/src/signature.rs +++ b/networks/ethereum/schnorr/src/signature.rs @@ -1,4 +1,4 @@ -use std::io; +use std_shims::io; use sha3::{Digest, Keccak256}; @@ -77,6 +77,7 @@ impl Signature { } /// Write the signature. + #[cfg(feature = "alloc")] pub fn write(&self, writer: &mut impl io::Write) -> io::Result<()> { writer.write_all(&self.to_bytes()) } diff --git a/processor/ethereum/router/Cargo.toml b/processor/ethereum/router/Cargo.toml index 133f7610..404f4aa1 100644 --- a/processor/ethereum/router/Cargo.toml +++ b/processor/ethereum/router/Cargo.toml @@ -35,7 +35,7 @@ alloy-provider = { version = "1", default-features = false } revm = { version = "33", default-features = false } -ethereum-schnorr = { package = "ethereum-schnorr-contract", path = "../../../networks/ethereum/schnorr", default-features = false } +ethereum-schnorr = { package = "ethereum-schnorr-contract", path = "../../../networks/ethereum/schnorr", default-features = false, features = ["std"] } ethereum-primitives = { package = "serai-processor-ethereum-primitives", path = "../primitives", default-features = false } ethereum-deployer = { package = "serai-processor-ethereum-deployer", path = "../deployer", default-features = false } diff --git a/tests/no-std/Cargo.toml b/tests/no-std/Cargo.toml index 2552d7aa..f0c35b1b 100644 --- a/tests/no-std/Cargo.toml +++ b/tests/no-std/Cargo.toml @@ -46,6 +46,8 @@ frost-schnorrkel = { path = "../../crypto/schnorrkel", default-features = false, bitcoin-serai = { path = "../../networks/bitcoin", default-features = false, features = ["hazmat"], optional = true } +ethereum-schnorr-contract = { path = "../../networks/ethereum/schnorr", default-features = false } + [features] alloc = [ "std-shims/alloc", @@ -75,4 +77,6 @@ alloc = [ "frost-schnorrkel", "bitcoin-serai", + + "ethereum-schnorr-contract/alloc", ] diff --git a/tests/no-std/src/lib.rs b/tests/no-std/src/lib.rs index 320a3c87..334196fa 100644 --- a/tests/no-std/src/lib.rs +++ b/tests/no-std/src/lib.rs @@ -16,6 +16,8 @@ pub use embedwards25519; pub use schnorr_signatures; +pub use ethereum_schnorr_contract; + #[cfg(feature = "alloc")] pub mod alloc { pub use multiexp;