Downscope dependencies in serai-processor-ethereum-primitives, const-hex decode bytecode in ethereum-schnorr-contract

This commit is contained in:
Luke Parker 2025-01-19 00:16:50 -05:00
parent 642ba00952
commit 9d57c4eb4d
No known key found for this signature in database
7 changed files with 24 additions and 16 deletions
Cargo.lock
networks/ethereum/schnorr
processor/ethereum/primitives

3
Cargo.lock generated
View file

@ -2209,6 +2209,7 @@ dependencies = [
"alloy-simple-request-transport",
"alloy-sol-types",
"build-solidity-contracts",
"const-hex",
"group",
"k256",
"rand_core",
@ -6959,7 +6960,7 @@ name = "serai-processor-ethereum-primitives"
version = "0.1.0"
dependencies = [
"alloy-consensus",
"alloy-core",
"alloy-primitives",
"group",
"k256",
]

View file

@ -16,6 +16,8 @@ rustdoc-args = ["--cfg", "docsrs"]
workspace = true
[dependencies]
const-hex = { version = "1", default-features = false, features = ["std", "core-error"] }
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"] }

View file

@ -2,4 +2,5 @@
An Ethereum contract to verify Schnorr signatures.
This crate will fail to build if `solc` is not installed and available.
This crate will fail to build if the expected version of `solc` is not
installed and available.

View file

@ -4,8 +4,16 @@
#![allow(non_snake_case)]
/// The initialization bytecode of the Schnorr library.
pub const INIT_BYTECODE: &str =
include_str!(concat!(env!("OUT_DIR"), "/ethereum-schnorr-contract/Schnorr.bin"));
pub const BYTECODE: &[u8] = {
const BYTECODE_HEX: &[u8] =
include_bytes!(concat!(env!("OUT_DIR"), "/ethereum-schnorr-contract/Schnorr.bin"));
const BYTECODE: [u8; BYTECODE_HEX.len() / 2] =
match const_hex::const_decode_to_array::<{ BYTECODE_HEX.len() / 2 }>(BYTECODE_HEX) {
Ok(bytecode) => bytecode,
Err(_) => panic!("Schnorr.bin did not contain valid hex"),
};
&BYTECODE
};
mod public_key;
pub use public_key::PublicKey;

View file

@ -18,14 +18,10 @@ use crate::{Signature, tests::test_key};
fn ecrecover(message: Scalar, odd_y: bool, r: Scalar, s: Scalar) -> Option<[u8; 20]> {
let sig = ecdsa::Signature::from_scalars(r, s).ok()?;
let message: [u8; 32] = message.to_repr().into();
alloy_core::primitives::Signature::from_signature_and_parity(
sig,
alloy_core::primitives::Parity::Parity(odd_y),
)
.ok()?
.recover_address_from_prehash(&alloy_core::primitives::B256::from(message))
.ok()
.map(Into::into)
alloy_core::primitives::PrimitiveSignature::from_signature_and_parity(sig, odd_y)
.recover_address_from_prehash(&alloy_core::primitives::B256::from(message))
.ok()
.map(Into::into)
}
// Test ecrecover behaves as expected

View file

@ -20,5 +20,5 @@ workspace = true
group = { version = "0.13", default-features = false }
k256 = { version = "^0.13.1", default-features = false, features = ["std", "arithmetic"] }
alloy-core = { version = "0.8", default-features = false }
alloy-primitives = { version = "0.8", default-features = false }
alloy-consensus = { version = "0.9", default-features = false, features = ["k256"] }

View file

@ -5,12 +5,12 @@
use group::ff::PrimeField;
use k256::Scalar;
use alloy_core::primitives::PrimitiveSignature;
use alloy_primitives::PrimitiveSignature;
use alloy_consensus::{SignableTransaction, Signed, TxLegacy};
/// The Keccak256 hash function.
pub fn keccak256(data: impl AsRef<[u8]>) -> [u8; 32] {
alloy_core::primitives::keccak256(data.as_ref()).into()
alloy_primitives::keccak256(data.as_ref()).into()
}
/// Deterministically sign a transaction.
@ -67,7 +67,7 @@ fn test_deterministically_sign() {
let signed = deterministically_sign(tx.clone());
assert!(signed.recover_signer().is_ok());
let one = alloy_core::primitives::U256::from(1u64);
let one = alloy_primitives::U256::from(1u64);
assert_eq!(signed.signature().r(), one);
assert_eq!(signed.signature().s(), one);