alloy-core 1.0, alloy 0.14, revm 0.22 (001)

This moves to Rust 1.86 as were prior on Rust 1.81, and the new alloy
dependencies require 1.82.

The revm API changes were notable for us. Instead of relying on a modified call
instruction (with deep introspection into the EVM design), we now use the more
recent and now more prominent Inspector API. This:

1) Lets us perform far less introspection
2) Forces us to rewrite the gas estimation code we just had audited

Thankfully, it itself should be much easier to read/review, and our existing
test suite has extensively validated it.

This resolves 001 which was a concern for if/when this upgrade occurs. By doing
it now, with a dedicated test case ensuring the issue we would have had with
alloy-core 0.8 and `validate=false` isn't actively an issue, we resolve it.
This commit is contained in:
Luke Parker
2025-04-12 08:09:09 -04:00
parent 5a7b815e2e
commit 184c02714a
25 changed files with 1483 additions and 625 deletions

View File

@@ -17,17 +17,16 @@ rustdoc-args = ["--cfg", "docsrs"]
workspace = true
[dependencies]
alloy-core = { version = "0.8", default-features = false }
alloy-core = { version = "1", default-features = false }
alloy-sol-types = { version = "0.8", default-features = false }
alloy-sol-macro = { version = "0.8", default-features = false }
alloy-sol-types = { version = "1", default-features = false }
alloy-sol-macro = { version = "1", default-features = false }
alloy-consensus = { version = "0.9", default-features = false }
alloy-consensus = { version = "0.14", default-features = false }
alloy-rpc-types-eth = { version = "0.9", default-features = false }
alloy-transport = { version = "0.9", default-features = false }
alloy-simple-request-transport = { path = "../../../networks/ethereum/alloy-simple-request-transport", default-features = false }
alloy-provider = { version = "0.9", default-features = false }
alloy-rpc-types-eth = { version = "0.14", default-features = false }
alloy-transport = { version = "0.14", default-features = false }
alloy-provider = { version = "0.14", default-features = false }
ethereum-primitives = { package = "serai-processor-ethereum-primitives", path = "../primitives", default-features = false }
@@ -35,8 +34,9 @@ ethereum-primitives = { package = "serai-processor-ethereum-primitives", path =
build-solidity-contracts = { path = "../../../networks/ethereum/build-contracts", default-features = false }
[dev-dependencies]
alloy-rpc-client = { version = "0.9", default-features = false }
alloy-node-bindings = { version = "0.9", default-features = false }
alloy-simple-request-transport = { path = "../../../networks/ethereum/alloy-simple-request-transport", default-features = false }
alloy-rpc-client = { version = "0.14", default-features = false }
alloy-node-bindings = { version = "0.14", default-features = false }
tokio = { version = "1.0", default-features = false, features = ["rt-multi-thread", "macros"] }

View File

@@ -11,7 +11,6 @@ use alloy_sol_types::SolCall;
use alloy_rpc_types_eth::{TransactionInput, TransactionRequest};
use alloy_transport::{TransportErrorKind, RpcError};
use alloy_simple_request_transport::SimpleRequest;
use alloy_provider::{Provider, RootProvider};
#[cfg(test)]
@@ -44,7 +43,7 @@ const INITCODE: &[u8] = {
/// of the EVM. It then supports retrieving the deployed contracts addresses (which aren't
/// deterministic) using a single call.
#[derive(Clone, Debug)]
pub struct Deployer(Arc<RootProvider<SimpleRequest>>);
pub struct Deployer(Arc<RootProvider>);
impl Deployer {
/// Obtain the transaction to deploy this contract, already signed.
///
@@ -119,7 +118,7 @@ impl Deployer {
///
/// This will return `None` if the Deployer has yet to be deployed on-chain.
pub async fn new(
provider: Arc<RootProvider<SimpleRequest>>,
provider: Arc<RootProvider>,
) -> Result<Option<Self>, RpcError<TransportErrorKind>> {
let address = Self::address();
let code = provider.get_code_at(address).await?;
@@ -138,16 +137,14 @@ impl Deployer {
let call = TransactionRequest::default().to(Self::address()).input(TransactionInput::new(
abi::Deployer::deploymentsCall::new((init_code_hash.into(),)).abi_encode().into(),
));
let bytes = self.0.call(&call).await?;
let deployment = abi::Deployer::deploymentsCall::abi_decode_returns(&bytes, true)
.map_err(|e| {
TransportErrorKind::Custom(
format!("node returned a non-address for function returning address: {e:?}").into(),
)
})?
._0;
let bytes = self.0.call(call).await?;
let deployment = abi::Deployer::deploymentsCall::abi_decode_returns(&bytes).map_err(|e| {
TransportErrorKind::Custom(
format!("node returned a non-address for function returning address: {e:?}").into(),
)
})?;
if **deployment == [0; 20] {
if deployment == Address::ZERO {
return Ok(None);
}
Ok(Some(deployment))

View File

@@ -76,9 +76,9 @@ async fn test_deployer() {
let call = TransactionRequest::default()
.to(Deployer::address())
.input(TransactionInput::new(deploy_tx.tx().input.clone()));
let call_err = provider.call(&call).await.unwrap_err();
let call_err = provider.call(call).await.unwrap_err();
assert!(matches!(
call_err.as_error_resp().unwrap().as_decoded_error::<DeployerErrors>(true).unwrap(),
call_err.as_error_resp().unwrap().as_decoded_interface_error::<DeployerErrors>().unwrap(),
DeployerErrors::PriorDeployed(PriorDeployed {}),
));
}
@@ -97,9 +97,9 @@ async fn test_deployer() {
let call = TransactionRequest::default()
.to(Deployer::address())
.input(TransactionInput::new(deploy_tx.tx().input.clone()));
let call_err = provider.call(&call).await.unwrap_err();
let call_err = provider.call(call).await.unwrap_err();
assert!(matches!(
call_err.as_error_resp().unwrap().as_decoded_error::<DeployerErrors>(true).unwrap(),
call_err.as_error_resp().unwrap().as_decoded_interface_error::<DeployerErrors>().unwrap(),
DeployerErrors::DeploymentFailed(DeploymentFailed {}),
));
}