Skip to content

Commit

Permalink
fix: fix execute encoding for transactions (#3501)
Browse files Browse the repository at this point in the history
## What ❔

<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zkstack dev fmt` and `zkstack dev
lint`.
  • Loading branch information
StanislavBreadless authored Jan 17, 2025
1 parent 9b121c9 commit 4c381a8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
Binary file added core/genesis_export.bin
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use zksync_types::{
commitment::{L1BatchWithMetadata, PriorityOpsMerkleProof},
ethabi::{encode, Token},
ProtocolVersionId,
};

use crate::{
i_executor::structures::{StoredBatchInfo, SUPPORTED_ENCODING_VERSION},
Tokenizable, Tokenize,
Tokenizable,
};

/// Input required to encode `executeBatches` call.
Expand All @@ -15,11 +16,15 @@ pub struct ExecuteBatches {
pub priority_ops_proofs: Vec<PriorityOpsMerkleProof>,
}

impl Tokenize for &ExecuteBatches {
fn into_tokens(self) -> Vec<Token> {
let protocol_version = self.l1_batches[0].header.protocol_version.unwrap();
impl ExecuteBatches {
// The encodings of `ExecuteBatches` operations are different depending on the protocol version
// of the underlying chain.
// However, we can send batches with older protocol versions just by changing the encoding.
// This makes the migration simpler.
pub fn encode_for_eth_tx(&self, chain_protocol_version: ProtocolVersionId) -> Vec<Token> {
let internal_protocol_version = self.l1_batches[0].header.protocol_version.unwrap();

if protocol_version.is_pre_gateway() {
if internal_protocol_version.is_pre_gateway() && chain_protocol_version.is_pre_gateway() {
vec![Token::Array(
self.l1_batches
.iter()
Expand Down
16 changes: 12 additions & 4 deletions core/node/eth_sender/src/eth_tx_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ impl EthTxAggregator {
stm_protocol_version_id,
stm_validator_timelock_address,
),
chain_protocol_version_id,
is_gateway,
)
.await?;
Expand Down Expand Up @@ -642,7 +643,11 @@ impl EthTxAggregator {
.await;
}

fn encode_aggregated_op(&self, op: &AggregatedOperation) -> TxData {
fn encode_aggregated_op(
&self,
op: &AggregatedOperation,
chain_protocol_version_id: ProtocolVersionId,
) -> TxData {
let mut args = vec![Token::Uint(self.rollup_chain_id.as_u64().into())];
let is_op_pre_gateway = op.protocol_version().is_pre_gateway();

Expand Down Expand Up @@ -686,8 +691,9 @@ impl EthTxAggregator {
(calldata, None)
}
AggregatedOperation::Execute(op) => {
args.extend(op.into_tokens());
let encoding_fn = if is_op_pre_gateway {
args.extend(op.encode_for_eth_tx(chain_protocol_version_id));
let encoding_fn = if is_op_pre_gateway && chain_protocol_version_id.is_pre_gateway()
{
&self.functions.post_shared_bridge_execute
} else {
&self.functions.post_gateway_execute
Expand Down Expand Up @@ -743,6 +749,7 @@ impl EthTxAggregator {
storage: &mut Connection<'_, Core>,
aggregated_op: &AggregatedOperation,
timelock_contract_address: Address,
chain_protocol_version_id: ProtocolVersionId,
is_gateway: bool,
) -> Result<EthTx, EthSenderError> {
let mut transaction = storage.start_transaction().await.unwrap();
Expand All @@ -755,7 +762,8 @@ impl EthTxAggregator {
(_, _) => None,
};
let nonce = self.get_next_nonce(&mut transaction, sender_addr).await?;
let encoded_aggregated_op = self.encode_aggregated_op(aggregated_op);
let encoded_aggregated_op =
self.encode_aggregated_op(aggregated_op, chain_protocol_version_id);
let l1_batch_number_range = aggregated_op.l1_batch_range();

let eth_tx_predicted_gas = match (op_type, is_gateway, self.aggregator.mode()) {
Expand Down
3 changes: 2 additions & 1 deletion core/node/eth_sender/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use zksync_object_store::MockObjectStore;
use zksync_types::{
aggregated_operations::AggregatedActionType, block::L1BatchHeader,
commitment::L1BatchCommitmentMode, eth_sender::EthTx, pubdata_da::PubdataSendingMode,
settlement::SettlementMode, Address, L1BatchNumber, ProtocolVersion, H256,
settlement::SettlementMode, Address, L1BatchNumber, ProtocolVersion, ProtocolVersionId, H256,
};

use crate::{
Expand Down Expand Up @@ -525,6 +525,7 @@ impl EthSenderTester {
&mut self.conn.connection().await.unwrap(),
&aggregated_operation,
Address::random(),
ProtocolVersionId::latest(),
self.is_l2,
)
.await
Expand Down
1 change: 1 addition & 0 deletions core/node/eth_sender/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ async fn resend_each_block(commitment_mode: L1BatchCommitmentMode) -> anyhow::Re
&mut tester.conn.connection().await.unwrap(),
&get_dummy_operation(0),
Address::random(),
ProtocolVersionId::latest(),
false,
)
.await?;
Expand Down

0 comments on commit 4c381a8

Please sign in to comment.