Skip to content

Commit af6f11d

Browse files
committed
Refactor sidecars
Signed-off-by: Danil <[email protected]>
1 parent 55c722c commit af6f11d

File tree

9 files changed

+52
-88
lines changed

9 files changed

+52
-88
lines changed

core/Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/lib/eth_client/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ anyhow.workspace = true
3333
serde_json.workspace = true
3434
tokio.workspace = true
3535
c-kzg.workspace = true
36-
once_cell = "1.21.3"
3736

3837
[dev-dependencies]
3938
assert_matches.workspace = true

core/lib/eth_client/src/clients/http/signing.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,8 @@ impl<S: EthereumSigner, Net: Network> SigningClient<S, Net> {
264264
};
265265

266266
let mut signed_tx = self.inner.eth_signer.sign_transaction(tx).await?;
267-
if let Some(sidecar) = options.blob_tx_sidecar {
268-
signed_tx = encode_blob_tx_with_sidecar(
269-
&signed_tx,
270-
sidecar,
271-
options.support_eip7594.unwrap_or_default(),
272-
);
267+
if let Some(sidecar) = &options.blob_tx_sidecar {
268+
signed_tx = encode_blob_tx_with_sidecar(&signed_tx, sidecar);
273269
}
274270
let hash = web3::keccak256(&signed_tx).into();
275271
Ok((signed_tx, hash))

core/lib/eth_client/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ pub use zksync_web3_decl::{
1818
};
1919

2020
pub use crate::types::{
21-
encode_blob_tx_with_sidecar, CallFunctionArgs, ContractCall, ContractCallError,
22-
ExecutedTxStatus, FailureInfo, RawTransactionBytes, SignedCallResult, SigningError,
21+
convert_eip4844_sidecar_to_eip7594_sidecar, encode_blob_tx_with_sidecar, CallFunctionArgs,
22+
ContractCall, ContractCallError, ExecutedTxStatus, FailureInfo, RawTransactionBytes,
23+
SignedCallResult, SigningError,
2324
};
2425

2526
pub mod clients;
@@ -62,8 +63,6 @@ pub struct Options {
6263
pub factory_deps: Option<Vec<Vec<u8>>>,
6364
// Paymaster params
6465
pub paymaster_params: Option<PaymasterParams>,
65-
// support eip7594 upgrade
66-
pub support_eip7594: Option<bool>,
6766
}
6867

6968
impl Options {

core/lib/eth_client/src/types.rs

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rlp::RlpStream;
22
use zksync_types::{
3-
eth_sender::{EthTxBlobSidecar, EthTxBlobSidecarV2, SidecarBlobV1, SidecarBlobV2},
3+
eth_sender::{EthTxBlobSidecar, SidecarBlobV1, SidecarBlobV2},
44
ethabi, web3,
55
web3::{
66
contract::{Detokenize, Tokenize},
@@ -283,30 +283,8 @@ impl SignedCallResult {
283283

284284
// Encodes the blob transaction and the blob sidecar into the networking
285285
// format as defined in <https://eips.ethereum.org/EIPS/eip-4844#networking>
286-
pub fn encode_blob_tx_with_sidecar(
287-
raw_tx: &[u8],
288-
sidecar: EthTxBlobSidecar,
289-
eip7594_upgrade_support: bool,
290-
) -> Vec<u8> {
291-
let sidecar = match (&sidecar, eip7594_upgrade_support) {
292-
(EthTxBlobSidecar::EthTxBlobSidecarV2(_), true) => sidecar,
293-
(EthTxBlobSidecar::EthTxBlobSidecarV1(_), false) => sidecar,
294-
(EthTxBlobSidecar::EthTxBlobSidecarV1(data), true) => {
295-
let eip7594_blobs: Vec<SidecarBlobV2> = data
296-
.blobs
297-
.iter()
298-
.map(|blob| convert_eip4844_blobs_to_eip7594_blobs(blob.clone()))
299-
.collect();
300-
EthTxBlobSidecar::EthTxBlobSidecarV2(EthTxBlobSidecarV2 {
301-
blobs: eip7594_blobs,
302-
})
303-
}
304-
(EthTxBlobSidecar::EthTxBlobSidecarV2(_), false) => {
305-
panic!("EIP-7594 sidecars are not supported when eip7594 upgrade support is disabled");
306-
}
307-
};
308-
309-
let mut stream_outer = RlpStream::new();
286+
pub fn encode_blob_tx_with_sidecar(raw_tx: &[u8], sidecar: &EthTxBlobSidecar) -> Vec<u8> {
287+
let mut stream_outer = RlpStream::new();
310288

311289
match sidecar {
312290
EthTxBlobSidecar::EthTxBlobSidecarV1(sidecar) => {
@@ -381,37 +359,6 @@ pub fn encode_blob_tx_with_sidecar(
381359
}
382360
}
383361

384-
stream_outer
385-
} else {
386-
// rlp([tx_payload_body, wrapper_version, blobs, commitments, cell_proofs])
387-
let blobs_count = sidecar.blobs.len();
388-
389-
let mut stream_outer = RlpStream::new();
390-
stream_outer.begin_list(5);
391-
392-
stream_outer.append_raw(&raw_tx[1..], 1);
393-
let wrapper_version = 1u8;
394-
stream_outer.append_raw(&[wrapper_version], 1);
395-
396-
let mut blob_stream = RlpStream::new_list(blobs_count);
397-
let mut commitment_stream = RlpStream::new_list(blobs_count);
398-
let mut cell_proof_stream = RlpStream::new_list(128 * blobs_count);
399-
400-
for i in 0..blobs_count {
401-
blob_stream.append(&sidecar.blobs[i].blob);
402-
commitment_stream.append(&sidecar.blobs[i].commitment);
403-
for cell_proof in sidecar.blobs[i].cell_proofs.as_ref().unwrap() {
404-
cell_proof_stream.append(cell_proof);
405-
}
406-
}
407-
408-
stream_outer.append_raw(&blob_stream.out(), 1);
409-
stream_outer.append_raw(&commitment_stream.out(), 1);
410-
stream_outer.append_raw(&cell_proof_stream.out(), 1);
411-
412-
stream_outer
413-
};
414-
415362
let tx = [&[EIP_4844_TX_TYPE], stream_outer.as_raw()].concat();
416363

417364
tx
@@ -448,11 +395,13 @@ pub struct FailureInfo {
448395
pub gas_limit: U256,
449396
}
450397

451-
fn convert_eip4844_blobs_to_eip7594_blobs(sidecar: SidecarBlobV1) -> SidecarBlobV2 {
398+
/// Convert eip4844 proofs to cell proofs as required by eip7594
399+
pub fn convert_eip4844_sidecar_to_eip7594_sidecar(sidecar: SidecarBlobV1) -> SidecarBlobV2 {
452400
let mut cell_proofs = Vec::new();
453401

454402
let blob_kzg = c_kzg::Blob::from_bytes(&sidecar.blob).unwrap();
455403

404+
// KZG settings are cached, it's cheap to get them multiple times.
456405
let kzg_settings = c_kzg::ethereum_kzg_settings_arc(0);
457406
// Compute cells and their KZG proofs for this blob
458407
let (_cells, kzg_proofs) = kzg_settings
@@ -462,10 +411,10 @@ fn convert_eip4844_blobs_to_eip7594_blobs(sidecar: SidecarBlobV1) -> SidecarBlob
462411
for kzg_proof in kzg_proofs.iter() {
463412
cell_proofs.push(kzg_proof.to_bytes().into_inner().to_vec());
464413
}
414+
465415
SidecarBlobV2 {
466416
blob: sidecar.blob,
467417
commitment: sidecar.commitment,
468-
proof: sidecar.proof,
469418
versioned_hash: sidecar.versioned_hash,
470419
cell_proofs,
471420
}
@@ -546,7 +495,7 @@ mod tests {
546495
let expected_str = expected_str.trim();
547496
let raw_tx = encode_blob_tx_with_sidecar(
548497
&raw_tx,
549-
EthTxBlobSidecar::EthTxBlobSidecarV1(EthTxBlobSidecarV1 {
498+
&EthTxBlobSidecar::EthTxBlobSidecarV1(EthTxBlobSidecarV1 {
550499
blobs: vec![SidecarBlobV1 {
551500
blob,
552501
commitment,
@@ -555,7 +504,6 @@ mod tests {
555504
cell_proofs: None,
556505
}],
557506
}),
558-
true,
559507
);
560508

561509
let signed_call_result = SignedCallResult::new(
@@ -654,7 +602,7 @@ mod tests {
654602
let expected_str = expected_str.trim();
655603
let raw_tx = encode_blob_tx_with_sidecar(
656604
&raw_tx,
657-
EthTxBlobSidecar::EthTxBlobSidecarV1(EthTxBlobSidecarV1 {
605+
&EthTxBlobSidecar::EthTxBlobSidecarV1(EthTxBlobSidecarV1 {
658606
blobs: vec![
659607
SidecarBlobV1 {
660608
blob: blob_1,
@@ -672,7 +620,6 @@ mod tests {
672620
},
673621
],
674622
}),
675-
true,
676623
);
677624

678625
let signed_call_result = SignedCallResult::new(

core/lib/types/src/eth_sender.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ impl From<EthTxBlobSidecarV1> for EthTxBlobSidecar {
2222
}
2323
}
2424

25+
impl From<EthTxBlobSidecarV2> for EthTxBlobSidecar {
26+
fn from(value: EthTxBlobSidecarV2) -> Self {
27+
Self::EthTxBlobSidecarV2(value)
28+
}
29+
}
30+
2531
/// All sidecar data for a single blob for the EIP4844 transaction.
2632
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
2733
pub struct SidecarBlobV1 {
@@ -37,15 +43,13 @@ pub struct SidecarBlobV1 {
3743
pub versioned_hash: Vec<u8>,
3844
}
3945

40-
/// All sidecar data for a single blob for the EIP4844 transaction.
46+
/// All sidecar data for a single blob for the EIP7594 transaction.
4147
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
4248
pub struct SidecarBlobV2 {
4349
/// Blob itself
4450
pub blob: Vec<u8>,
4551
/// Blob commitment
4652
pub commitment: Vec<u8>,
47-
/// Blob proof
48-
pub proof: Vec<u8>,
4953
/// Blob commitment versioned hash
5054
pub versioned_hash: Vec<u8>,
5155
/// The KZG proofs for each of the cells in the blob.

core/node/eth_sender/src/eth_tx_aggregator.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use tokio::sync::watch;
44
use zksync_config::configs::eth_sender::{PrecommitParams, SenderConfig};
55
use zksync_contracts::BaseSystemContractsHashes;
66
use zksync_dal::{Connection, ConnectionPool, Core, CoreDal};
7-
use zksync_eth_client::{BoundEthInterface, CallFunctionArgs, ContractCallError, EthInterface};
7+
use zksync_eth_client::{
8+
convert_eip4844_sidecar_to_eip7594_sidecar, BoundEthInterface, CallFunctionArgs,
9+
ContractCallError, EthInterface,
10+
};
811
use zksync_health_check::{Health, HealthStatus, HealthUpdater, ReactiveHealthCheck};
912
use zksync_l1_contract_interface::{
1013
i_executor::{
@@ -20,7 +23,10 @@ use zksync_types::{
2023
AggregatedActionType, L1BatchAggregatedActionType, L2BlockAggregatedActionType,
2124
},
2225
commitment::{L1BatchWithMetadata, SerializeCommitment},
23-
eth_sender::{EthTx, EthTxBlobSidecar, EthTxBlobSidecarV1, EthTxFinalityStatus, SidecarBlobV1},
26+
eth_sender::{
27+
EthTx, EthTxBlobSidecar, EthTxBlobSidecarV1, EthTxBlobSidecarV2, EthTxFinalityStatus,
28+
SidecarBlobV1,
29+
},
2430
ethabi::{Function, Token},
2531
l2_to_l1_log::UserL2ToL1Log,
2632
protocol_version::{L1VerifierConfig, PACKED_SEMVER_MINOR_MASK},
@@ -983,7 +989,12 @@ impl EthTxAggregator {
983989
None
984990
};
985991

986-
Self::encode_commit_data(encoding_fn, &commit_data, l1_batch_for_sidecar)
992+
Self::encode_commit_data(
993+
encoding_fn,
994+
&commit_data,
995+
l1_batch_for_sidecar,
996+
self.config.use_fusaka_blob_format,
997+
)
987998
}
988999
L1BatchAggregatedOperation::PublishProofOnchain(op) => {
9891000
args.extend(op.conditional_into_tokens(self.config.is_verifier_pre_fflonk));
@@ -1054,6 +1065,7 @@ impl EthTxAggregator {
10541065
commit_fn: &Function,
10551066
commit_payload: &[Token],
10561067
l1_batch: Option<L1BatchWithMetadata>,
1068+
use_eip7594_blobs: bool,
10571069
) -> (Vec<u8>, Option<EthTxBlobSidecar>) {
10581070
let calldata = commit_fn
10591071
.encode_input(commit_payload)
@@ -1080,8 +1092,20 @@ impl EthTxAggregator {
10801092
})
10811093
.collect::<Vec<SidecarBlobV1>>();
10821094

1083-
let eth_tx_blob_sidecar = EthTxBlobSidecarV1 { blobs: sidecar };
1084-
Some(eth_tx_blob_sidecar.into())
1095+
let eth_tx_blob_sidecar = if use_eip7594_blobs {
1096+
EthTxBlobSidecarV2 {
1097+
blobs: sidecar
1098+
.into_iter()
1099+
.map(|sidecar_blob| {
1100+
convert_eip4844_sidecar_to_eip7594_sidecar(sidecar_blob).into()
1101+
})
1102+
.collect(),
1103+
}
1104+
.into()
1105+
} else {
1106+
EthTxBlobSidecarV1 { blobs: sidecar }.into()
1107+
};
1108+
Some(eth_tx_blob_sidecar)
10851109
}
10861110
};
10871111

core/node/eth_sender/src/eth_tx_manager.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use zksync_node_fee_model::l1_gas_price::TxParamsProvider;
1414
use zksync_shared_metrics::L1Stage;
1515
use zksync_types::{
1616
aggregated_operations::{AggregatedActionType, L1BatchAggregatedActionType},
17-
eth_sender::{EthTx, EthTxBlobSidecar, EthTxFinalityStatus, L1BlockNumbers},
17+
eth_sender::{EthTx, EthTxFinalityStatus, L1BlockNumbers},
1818
Address, L1BlockNumber, GATEWAY_CALLDATA_PROCESSING_ROLLUP_OVERHEAD_GAS, H256,
1919
L1_CALLDATA_PROCESSING_ROLLUP_OVERHEAD_GAS, L1_GAS_PER_PUBDATA_BYTE, U256,
2020
};
@@ -225,11 +225,10 @@ impl EthTxManager {
225225
)
226226
.await;
227227

228-
if let Some(blob_sidecar) = tx.blob_sidecar.clone() {
228+
if let Some(blob_sidecar) = &tx.blob_sidecar {
229229
signed_tx.raw_tx = RawTransactionBytes::new_unchecked(encode_blob_tx_with_sidecar(
230230
signed_tx.raw_tx.as_ref(),
231231
blob_sidecar,
232-
self.config.use_fusaka_blob_format,
233232
));
234233
}
235234

prover/Cargo.lock

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

0 commit comments

Comments
 (0)