Skip to content

Commit 2033b01

Browse files
committed
op-checks
1 parent bd9e053 commit 2033b01

File tree

4 files changed

+37
-23
lines changed

4 files changed

+37
-23
lines changed

Cargo.lock

Lines changed: 15 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ bytes = { version = "1.8.0", features = ["serde"] }
6262

6363
# tips-ingress
6464
backon = "1.5.2"
65+
op-revm = { version = "10.1.0", default-features = false }

crates/ingress-rpc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ serde.workspace = true
3131
serde_json.workspace = true
3232
async-trait.workspace = true
3333
backon.workspace = true
34+
op-revm.workspace = true

crates/ingress-rpc/src/service.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
use alloy_consensus::Typed2718;
2-
use alloy_consensus::constants::KECCAK_EMPTY;
3-
use alloy_consensus::{Transaction, transaction::SignerRecoverable};
1+
use alloy_consensus::{
2+
Transaction, Typed2718, constants::KECCAK_EMPTY, transaction::SignerRecoverable,
3+
};
44
use alloy_primitives::{Address, B256, Bytes, U256, address};
5-
use alloy_provider::network::eip2718::Decodable2718;
6-
use alloy_provider::{Provider, RootProvider};
5+
use alloy_provider::{Provider, RootProvider, network::eip2718::Decodable2718};
76
use alloy_rpc_types_mev::{EthBundleHash, EthCancelBundle, EthSendBundle};
87
use anyhow::Result;
9-
use jsonrpsee::types::ErrorObject;
108
use jsonrpsee::{
119
core::{RpcResult, async_trait},
1210
proc_macros::rpc,
11+
types::ErrorObject,
1312
};
1413
use op_alloy_consensus::OpTxEnvelope;
15-
use op_alloy_network::Optimism;
14+
use op_alloy_network::{Optimism, eip2718::Encodable2718};
15+
use op_revm::{OpSpecId, l1block::L1BlockInfo};
1616
use reth_rpc_eth_types::EthApiError;
1717
use tracing::{info, warn};
1818

@@ -102,7 +102,8 @@ impl<Queue> IngressService<Queue> {
102102
}
103103

104104
// error if tx nonce is not the latest
105-
if envelope.nonce() != account.nonce - 1 {
105+
// https://github.com/paradigmxyz/reth/blob/a047a055ab996f85a399f5cfb2fe15e350356546/crates/transaction-pool/src/validate/eth.rs#L611
106+
if envelope.nonce() < account.nonce {
106107
return Err(anyhow::anyhow!("Nonce is not the latest"));
107108
}
108109

@@ -111,7 +112,17 @@ impl<Queue> IngressService<Queue> {
111112
return Err(anyhow::anyhow!("Insufficient funds"));
112113
}
113114

114-
// TODO: op-checks (l1 block info, l1 balance > execution + DA fee)
115+
// op-checks to see if sender can cover L1 gas cost
116+
// from: https://github.com/paradigmxyz/reth/blob/6aa73f14808491aae77fc7c6eb4f0aa63bef7e6e/crates/optimism/txpool/src/validator.rs#L219
117+
let mut l1_block_info = L1BlockInfo::default();
118+
let tx = envelope.clone().try_into_pooled()?;
119+
let encoded = tx.encoded_2718();
120+
121+
let cost_addition = l1_block_info.calculate_tx_l1_cost(&encoded, OpSpecId::ISTHMUS);
122+
let cost = tx.value().saturating_add(cost_addition);
123+
if cost > account.balance {
124+
return Err(anyhow::anyhow!("Insufficient funds to cover L1 gas cost"));
125+
}
115126
Ok(())
116127
}
117128
}

0 commit comments

Comments
 (0)