Skip to content

Commit 4e98d96

Browse files
committed
add 4844 tx wip
1 parent 596733d commit 4e98d96

File tree

9 files changed

+91
-61
lines changed

9 files changed

+91
-61
lines changed

lib/Cargo.toml

+27-13
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,34 @@ hex = { version = "0.4.3", optional = true}
2424
rlp = { version = "0.5.2", optional = true}
2525
tracing = { version = "0.1", optional = true}
2626

27-
[target.'cfg(not(target_os = "zkvm"))'.dependencies]
28-
thiserror = "1.0"
29-
anyhow = "1.0"
30-
chrono = { version = "0.4", default-features = false }
31-
ethers-providers = { version = "2.0", features = ["optimism"] }
32-
flate2 = "1.0.26"
33-
log = "0.4"
34-
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
35-
serde_with = "3.0"
36-
tokio = { version = "1.23", features = ["full"] }
37-
zeth-primitives = { path = "../primitives", features = ["revm", "ethers"] }
27+
# [target.'cfg(not(target_os = "zkvm"))'.dependencies]
28+
# thiserror = "1.0"
29+
# anyhow = "1.0"
30+
chrono = { version = "0.4", default-features = false, optional = true}
31+
ethers-providers = { version = "2.0", features = ["optimism"], optional = true}
32+
flate2 = { version = "1.0.26", optional = true}
33+
log = { version = "0.4", optional = true}
34+
serde_json = { version = "1.0", default-features = false, features = ["alloc"], optional = true}
35+
serde_with = {version = "3.0", optional = true}
36+
tokio = { version = "1.23", features = ["full"], optional = true}
37+
# zeth-primitives = { path = "../primitives", features = ["revm", "ethers"] }
3838

3939
[dev-dependencies]
4040
bincode = "1.3"
4141
serde_with = "3.1"
4242

4343
[features]
4444
# default = ["taiko", "std"]
45-
std = []
45+
std = [
46+
"dep:chrono",
47+
"dep:ethers-providers",
48+
"dep:flate2",
49+
"dep:log",
50+
"dep:serde_json",
51+
"dep:serde_with",
52+
"dep:tokio",
53+
"zeth-primitives/ethers", "zeth-primitives/std"
54+
]
4655
taiko = [
4756
"zeth-primitives/taiko",
4857
"revm/taiko",
@@ -51,4 +60,9 @@ taiko = [
5160
"dep:rlp",
5261
"dep:tracing"
5362
]
54-
optimism = ["std", "revm/optimism", "dep:alloy-sol-types"]
63+
optimism = [
64+
"std",
65+
"zeth-primitives/optimism",
66+
"revm/optimism",
67+
"dep:alloy-sol-types"
68+
]

lib/src/builder/execute/ethereum.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use alloc::format;
1515
use core::{fmt::Debug, mem::take};
1616

1717
use anyhow::{anyhow, bail, Context};
18-
#[cfg(not(target_os = "zkvm"))]
18+
#[cfg(feature = "std")]
1919
use log::debug;
2020
use revm::{
2121
interpreter::Host,
@@ -59,7 +59,7 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
5959
bail!("Invalid protocol version: expected >= {MIN_SPEC_ID:?}, got {spec_id:?}");
6060
}
6161

62-
#[cfg(not(target_os = "zkvm"))]
62+
#[cfg(feature = "std")]
6363
{
6464
use chrono::{TimeZone, Utc};
6565
use log::info;
@@ -123,7 +123,7 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
123123
.recover_from()
124124
.with_context(|| format!("Error recovering address for transaction {tx_no}"))?;
125125

126-
#[cfg(not(target_os = "zkvm"))]
126+
#[cfg(feature = "std")]
127127
{
128128
let tx_hash = tx.hash();
129129
debug!("Tx no. {tx_no} (hash: {tx_hash})");
@@ -147,7 +147,7 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
147147
let gas_used = result.gas_used().try_into().unwrap();
148148
cumulative_gas_used = cumulative_gas_used.checked_add(gas_used).unwrap();
149149

150-
#[cfg(not(target_os = "zkvm"))]
150+
#[cfg(feature = "std")]
151151
debug!(" Ok: {result:?}");
152152

153153
// create the receipt from the EVM result
@@ -173,7 +173,7 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
173173
.context("failed to insert receipt")?;
174174

175175
// update account states
176-
#[cfg(not(target_os = "zkvm"))]
176+
#[cfg(feature = "std")]
177177
for (address, account) in &state {
178178
if account.is_touched() {
179179
// log account
@@ -215,7 +215,7 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
215215
.checked_mul(withdrawal.amount.try_into().unwrap())
216216
.unwrap();
217217

218-
#[cfg(not(target_os = "zkvm"))]
218+
#[cfg(feature = "std")]
219219
{
220220
debug!("Withdrawal no. {}", withdrawal.index);
221221
debug!(" Recipient: {:?}", withdrawal.address);
@@ -294,6 +294,22 @@ pub fn fill_eth_tx_env(tx_env: &mut TxEnv, essence: &EthereumTxEssence, caller:
294294
tx_env.nonce = Some(tx.nonce);
295295
tx_env.access_list = tx.access_list.clone().into();
296296
}
297+
EthereumTxEssence::Eip4844(tx) => {
298+
tx_env.caller = caller;
299+
tx_env.gas_limit = tx.gas_limit.try_into().unwrap();
300+
tx_env.gas_price = tx.max_fee_per_gas;
301+
tx_env.gas_priority_fee = Some(tx.max_priority_fee_per_gas);
302+
tx_env.transact_to = if let TransactionKind::Call(to_addr) = tx.to {
303+
TransactTo::Call(to_addr)
304+
} else {
305+
TransactTo::create()
306+
};
307+
tx_env.value = tx.value;
308+
tx_env.data = tx.data.clone();
309+
tx_env.chain_id = Some(tx.chain_id);
310+
tx_env.nonce = Some(tx.nonce);
311+
tx_env.access_list = tx.access_list.clone().into();
312+
}
297313
};
298314
}
299315

lib/src/builder/execute/optimism.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use alloc::{format, vec, vec::Vec};
1515
use core::{fmt::Debug, mem::take, str::FromStr};
1616

1717
use anyhow::{anyhow, bail, Context, Result};
18-
#[cfg(not(target_os = "zkvm"))]
18+
#[cfg(feature = "std")]
1919
use log::debug;
2020
use revm::{
2121
interpreter::Host,
@@ -62,7 +62,7 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
6262
}
6363
let chain_id = block_builder.chain_spec.chain_id();
6464

65-
#[cfg(not(target_os = "zkvm"))]
65+
#[cfg(feature = "std")]
6666
{
6767
use chrono::{TimeZone, Utc};
6868
use log::info;
@@ -125,7 +125,7 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
125125
.recover_from()
126126
.with_context(|| format!("Error recovering address for transaction {tx_no}"))?;
127127

128-
#[cfg(not(target_os = "zkvm"))]
128+
#[cfg(feature = "std")]
129129
{
130130
let tx_hash = tx.hash();
131131
debug!("Tx no. {tx_no} (hash: {tx_hash})");
@@ -142,7 +142,7 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
142142

143143
match &tx.essence {
144144
OptimismTxEssence::OptimismDeposited(deposit) => {
145-
#[cfg(not(target_os = "zkvm"))]
145+
#[cfg(feature = "std")]
146146
{
147147
debug!(" Source: {:?}", &deposit.source_hash);
148148
debug!(" Mint: {:?}", &deposit.mint);
@@ -165,7 +165,7 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
165165
let gas_used = result.gas_used().try_into().unwrap();
166166
cumulative_gas_used = cumulative_gas_used.checked_add(gas_used).unwrap();
167167

168-
#[cfg(not(target_os = "zkvm"))]
168+
#[cfg(feature = "std")]
169169
debug!(" Ok: {result:?}");
170170

171171
// create the receipt from the EVM result
@@ -177,7 +177,7 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
177177
);
178178

179179
// update account states
180-
#[cfg(not(target_os = "zkvm"))]
180+
#[cfg(feature = "std")]
181181
for (address, account) in &state {
182182
if account.is_touched() {
183183
// log account

lib/src/builder/execute/taiko.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use core::{fmt::Debug, mem::take, str::from_utf8};
1616

1717
use anyhow::{anyhow, bail, Context, Result};
18-
#[cfg(not(target_os = "zkvm"))]
18+
#[cfg(feature = "std")]
1919
use log::debug;
2020
use revm::{
2121
interpreter::Host,
@@ -61,7 +61,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
6161
}
6262
let chain_id = block_builder.chain_spec.chain_id();
6363

64-
#[cfg(not(target_os = "zkvm"))]
64+
#[cfg(feature = "std")]
6565
{
6666
use chrono::{TimeZone, Utc};
6767
use log::info;
@@ -129,7 +129,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
129129
.recover_from()
130130
.with_context(|| anyhow!("Error recovering address for transaction {tx_no}"))?;
131131

132-
#[cfg(not(target_os = "zkvm"))]
132+
#[cfg(feature = "std")]
133133
{
134134
let tx_hash = tx.hash();
135135
debug!("Tx no. {tx_no} (hash: {tx_hash})");
@@ -167,7 +167,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
167167
let gas_used = result.gas_used().try_into().unwrap();
168168
cumulative_gas_used = cumulative_gas_used.checked_add(gas_used).unwrap();
169169

170-
#[cfg(not(target_os = "zkvm"))]
170+
#[cfg(feature = "std")]
171171
debug!(" Ok: {result:?}");
172172

173173
// create the receipt from the EVM result
@@ -179,7 +179,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
179179
);
180180

181181
// update account states
182-
#[cfg(not(target_os = "zkvm"))]
182+
#[cfg(feature = "std")]
183183
for (address, account) in &state {
184184
if account.is_touched() {
185185
// log account

lib/src/host/preflight.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub trait Preflight<E: TxEssence> {
6161
) -> Result<Data<E>>;
6262
}
6363

64-
#[cfg(not(feature = "taiko"))]
64+
// #[cfg(not(feature = "taiko"))]
6565
/// Implements the [Preflight] trait for all compatible [BlockBuilderStrategy]s.
6666
impl<N: BlockBuilderStrategy> Preflight<N::TxEssence> for N
6767
where

lib/src/optimism/batcher.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl Batcher {
202202
// Read batches
203203
while let Some(batches) = self.batcher_channel.read_batches() {
204204
batches.into_iter().for_each(|batch| {
205-
#[cfg(not(target_os = "zkvm"))]
205+
#[cfg(feature = "std")]
206206
log::debug!(
207207
"received batch: timestamp={}, parent_hash={}, epoch={}",
208208
batch.essence.timestamp,
@@ -316,7 +316,7 @@ impl Batcher {
316316
// "batch.timestamp < next_timestamp -> drop"
317317
match batch.essence.timestamp.cmp(&next_timestamp) {
318318
Ordering::Greater => {
319-
#[cfg(not(target_os = "zkvm"))]
319+
#[cfg(feature = "std")]
320320
log::debug!(
321321
"Future batch: {} = batch.timestamp > next_timestamp = {}",
322322
&batch.essence.timestamp,
@@ -325,7 +325,7 @@ impl Batcher {
325325
return BatchStatus::Future;
326326
}
327327
Ordering::Less => {
328-
#[cfg(not(target_os = "zkvm"))]
328+
#[cfg(feature = "std")]
329329
log::debug!(
330330
"Batch too old: {} = batch.timestamp < next_timestamp = {}",
331331
&batch.essence.timestamp,
@@ -339,7 +339,7 @@ impl Batcher {
339339
// From the spec:
340340
// "batch.parent_hash != safe_l2_head.hash -> drop"
341341
if batch.essence.parent_hash != safe_l2_head.hash {
342-
#[cfg(not(target_os = "zkvm"))]
342+
#[cfg(feature = "std")]
343343
log::debug!(
344344
"Incorrect parent hash: {} != {}",
345345
batch.essence.parent_hash,
@@ -351,7 +351,7 @@ impl Batcher {
351351
// From the spec:
352352
// "batch.epoch_num + sequence_window_size < inclusion_block_number -> drop"
353353
if batch.essence.epoch_num + self.config.seq_window_size < batch.inclusion_block_number {
354-
#[cfg(not(target_os = "zkvm"))]
354+
#[cfg(feature = "std")]
355355
log::debug!(
356356
"Batch is not timely: {} + {} < {}",
357357
batch.essence.epoch_num,
@@ -364,7 +364,7 @@ impl Batcher {
364364
// From the spec:
365365
// "batch.epoch_num < epoch.number -> drop"
366366
if batch.essence.epoch_num < epoch.number {
367-
#[cfg(not(target_os = "zkvm"))]
367+
#[cfg(feature = "std")]
368368
log::debug!(
369369
"Batch epoch number is too low: {} < {}",
370370
batch.essence.epoch_num,
@@ -388,7 +388,7 @@ impl Batcher {
388388
// From the spec:
389389
// "batch.epoch_num > epoch.number+1 -> drop"
390390
_ => {
391-
#[cfg(not(target_os = "zkvm"))]
391+
#[cfg(feature = "std")]
392392
log::debug!(
393393
"Batch epoch number is too large: {} > {}",
394394
batch.essence.epoch_num,
@@ -401,7 +401,7 @@ impl Batcher {
401401
// From the spec:
402402
// "batch.epoch_hash != batch_origin.hash -> drop"
403403
if batch.essence.epoch_hash != batch_origin.hash {
404-
#[cfg(not(target_os = "zkvm"))]
404+
#[cfg(feature = "std")]
405405
log::debug!(
406406
"Epoch hash mismatch: {} != {}",
407407
batch.essence.epoch_hash,
@@ -413,7 +413,7 @@ impl Batcher {
413413
// From the spec:
414414
// "batch.timestamp < batch_origin.time -> drop"
415415
if batch.essence.timestamp < batch_origin.timestamp {
416-
#[cfg(not(target_os = "zkvm"))]
416+
#[cfg(feature = "std")]
417417
log::debug!(
418418
"Batch violates timestamp rule: {} < {}",
419419
batch.essence.timestamp,
@@ -426,7 +426,7 @@ impl Batcher {
426426
// "batch.timestamp > batch_origin.time + max_sequencer_drift: enforce the L2 timestamp
427427
// drift rule, but with exceptions to preserve above min L2 timestamp invariant:"
428428
if batch.essence.timestamp > batch_origin.timestamp + self.config.max_seq_drift {
429-
#[cfg(not(target_os = "zkvm"))]
429+
#[cfg(feature = "std")]
430430
log::debug!(
431431
"Sequencer drift detected: {} > {} + {}",
432432
batch.essence.timestamp,
@@ -437,7 +437,7 @@ impl Batcher {
437437
// From the spec:
438438
// "len(batch.transactions) > 0: -> drop"
439439
if !batch.essence.transactions.is_empty() {
440-
#[cfg(not(target_os = "zkvm"))]
440+
#[cfg(feature = "std")]
441441
log::debug!("Sequencer drift detected for non-empty batch; drop.");
442442
return BatchStatus::Drop;
443443
}
@@ -450,15 +450,15 @@ impl Batcher {
450450
let Some(next_epoch) = next_epoch else {
451451
// From the spec:
452452
// "If next_epoch is not known -> undecided"
453-
#[cfg(not(target_os = "zkvm"))]
453+
#[cfg(feature = "std")]
454454
log::debug!("Sequencer drift detected, but next epoch is not known; undecided");
455455
return BatchStatus::Undecided;
456456
};
457457

458458
// From the spec:
459459
// "If batch.timestamp >= next_epoch.time -> drop"
460460
if batch.essence.timestamp >= next_epoch.timestamp {
461-
#[cfg(not(target_os = "zkvm"))]
461+
#[cfg(feature = "std")]
462462
log::debug!("Sequencer drift detected; drop; batch timestamp is too far into the future. {} >= {}", batch.essence.timestamp, next_epoch.timestamp);
463463
return BatchStatus::Drop;
464464
}
@@ -472,7 +472,7 @@ impl Batcher {
472472
// any deposited transactions (identified by the transaction type prefix byte)"
473473
for tx in &batch.essence.transactions {
474474
if matches!(tx.first(), None | Some(&OPTIMISM_DEPOSITED_TX_TYPE)) {
475-
#[cfg(not(target_os = "zkvm"))]
475+
#[cfg(feature = "std")]
476476
log::debug!("Batch contains empty or invalid transaction");
477477
return BatchStatus::Drop;
478478
}

0 commit comments

Comments
 (0)