From 66325e156e40a41d1346aef6439774d137c02923 Mon Sep 17 00:00:00 2001 From: danijelTxFusion Date: Mon, 4 Nov 2024 23:41:09 +0100 Subject: [PATCH 1/5] refactor: remove unused code --- clients/client.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/clients/client.go b/clients/client.go index c48b1d1..f3d5381 100644 --- a/clients/client.go +++ b/clients/client.go @@ -1195,10 +1195,6 @@ func (c *Client) getBlock(ctx context.Context, method string, args ...interface{ if block.TxHash == ethTypes.EmptyTxsHash && len(block.Transactions) > 0 { return nil, errors.New("server returned non-empty transaction list but block header indicates no transactions") } - // TODO use this validation when transaction root is fixed on zksync node - //if head.TxHash != ethTypes.EmptyTxsHash && len(body.Transactions) == 0 { - // return nil, errors.New("server returned empty transaction list but block header indicates transactions") - //} // Load uncles because they are not included in the block response. var uncles []*ethTypes.Header if len(block.Uncles) > 0 { From 9280b4f936258b91b8f1b94aa7b8f0d38e0bb20c Mon Sep 17 00:00:00 2001 From: danijelTxFusion Date: Tue, 5 Nov 2024 00:03:53 +0100 Subject: [PATCH 2/5] feat(clients): add `CustomSignature` and `GasPerPubdata` to `TransferCallMsq` --- clients/types.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/clients/types.go b/clients/types.go index ca02009..292a0bb 100644 --- a/clients/types.go +++ b/clients/types.go @@ -28,6 +28,12 @@ type TransferCallMsg struct { GasTipCap *big.Int // EIP-1559 tip per gas. PaymasterParams *types.PaymasterParams // The paymaster parameters. + // GasPerPubdata denotes the maximum amount of gas the user is willing + // to pay for a single byte of pubdata. + GasPerPubdata *big.Int + // CustomSignature is used for the cases in which the signer's account + // is not an EOA. + CustomSignature hexutil.Bytes } func (m *TransferCallMsg) ToCallMsg() (*ethereum.CallMsg, error) { @@ -68,9 +74,10 @@ func (m *TransferCallMsg) ToCallMsg() (*ethereum.CallMsg, error) { func (m *TransferCallMsg) ToZkCallMsg() (*types.CallMsg, error) { var ( - value *big.Int - data []byte - to *common.Address + value *big.Int + data []byte + to *common.Address + gasPerPubdata *big.Int ) if m.Token == utils.L2BaseTokenAddress { @@ -90,6 +97,10 @@ func (m *TransferCallMsg) ToZkCallMsg() (*types.CallMsg, error) { } } + if m.GasPerPubdata == nil { + gasPerPubdata = utils.DefaultGasPerPubdataLimit + } + return &types.CallMsg{ From: m.From, To: to, @@ -99,8 +110,9 @@ func (m *TransferCallMsg) ToZkCallMsg() (*types.CallMsg, error) { GasTipCap: m.GasTipCap, Value: value, Data: data, - GasPerPubdata: utils.DefaultGasPerPubdataLimit, + GasPerPubdata: gasPerPubdata, PaymasterParams: m.PaymasterParams, + CustomSignature: m.CustomSignature, }, nil } From 3324562244f4ad84c81225e06ffc84d152df73fa Mon Sep 17 00:00:00 2001 From: danijelTxFusion Date: Tue, 5 Nov 2024 00:04:28 +0100 Subject: [PATCH 3/5] feat(clients): add `CustomSignature` and `GasPerPubdata` to `WithdrawalCallMsq` --- clients/types.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/clients/types.go b/clients/types.go index 292a0bb..dd67694 100644 --- a/clients/types.go +++ b/clients/types.go @@ -130,6 +130,12 @@ type WithdrawalCallMsg struct { GasTipCap *big.Int // EIP-1559 tip per gas. PaymasterParams *types.PaymasterParams // The paymaster parameters. + // GasPerPubdata denotes the maximum amount of gas the user is willing + // to pay for a single byte of pubdata. + GasPerPubdata *big.Int + // CustomSignature is used for the cases in which the signer's account + // is not an EOA. + CustomSignature hexutil.Bytes } func (m *WithdrawalCallMsg) ToCallMsg(defaultL2Bridge *common.Address) (*ethereum.CallMsg, error) { @@ -186,6 +192,11 @@ func (m *WithdrawalCallMsg) ToZkCallMsg(defaultL2Bridge *common.Address) (*types return nil, err } + gasPerPubdata := m.GasPerPubdata + if gasPerPubdata == nil { + gasPerPubdata = utils.DefaultGasPerPubdataLimit + } + return &types.CallMsg{ From: msg.From, To: msg.To, @@ -195,8 +206,9 @@ func (m *WithdrawalCallMsg) ToZkCallMsg(defaultL2Bridge *common.Address) (*types GasTipCap: msg.GasTipCap, Value: msg.Value, Data: msg.Data, - GasPerPubdata: utils.DefaultGasPerPubdataLimit, + GasPerPubdata: gasPerPubdata, PaymasterParams: m.PaymasterParams, + CustomSignature: m.CustomSignature, }, nil } From 5da5e6875af2634e9b23d20f8a9694e5e3cfc37e Mon Sep 17 00:00:00 2001 From: danijelTxFusion Date: Tue, 5 Nov 2024 00:08:06 +0100 Subject: [PATCH 4/5] feat(clients): rename `TransferCallMsg` methods BREAKING CHANGE: Rename `TransferCallMsg.ToCallMsg` to `TransferCallMsg.ToL1CallMsg` and `TransferCallMsg.ToZkCallMsg` to `TransferCallMsg.ToCallMsg`. --- clients/client.go | 2 +- clients/types.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clients/client.go b/clients/client.go index f3d5381..96cd4a3 100644 --- a/clients/client.go +++ b/clients/client.go @@ -1039,7 +1039,7 @@ func (c *Client) EstimateGasL1(ctx context.Context, msg types.CallMsg) (uint64, // EstimateGasTransfer estimates the amount of gas required for a transfer transaction. func (c *Client) EstimateGasTransfer(ctx context.Context, msg TransferCallMsg) (uint64, error) { - callMsg, err := msg.ToZkCallMsg() + callMsg, err := msg.ToCallMsg() if err != nil { return 0, err } diff --git a/clients/types.go b/clients/types.go index dd67694..a530e14 100644 --- a/clients/types.go +++ b/clients/types.go @@ -36,7 +36,7 @@ type TransferCallMsg struct { CustomSignature hexutil.Bytes } -func (m *TransferCallMsg) ToCallMsg() (*ethereum.CallMsg, error) { +func (m *TransferCallMsg) ToL1CallMsg() (*ethereum.CallMsg, error) { var ( value *big.Int data []byte @@ -72,7 +72,7 @@ func (m *TransferCallMsg) ToCallMsg() (*ethereum.CallMsg, error) { }, nil } -func (m *TransferCallMsg) ToZkCallMsg() (*types.CallMsg, error) { +func (m *TransferCallMsg) ToCallMsg() (*types.CallMsg, error) { var ( value *big.Int data []byte From a71facc3bfbb4a660df04789ae33c3f42fd5d351 Mon Sep 17 00:00:00 2001 From: danijelTxFusion Date: Tue, 5 Nov 2024 00:13:31 +0100 Subject: [PATCH 5/5] feat(clients): rename `WithdrawalCallMsg` methods BREAKING CHANGE: Rename `WithdrawalCallMsg.ToCallMsg` to `WithdrawalCallMsg.ToL1CallMsg` and `WithdrawalCallMsg.ToZkCallMsg` to `WithdrawalCallMsg.ToCallMsg`. --- clients/client.go | 4 ++-- clients/types.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clients/client.go b/clients/client.go index 96cd4a3..4a0793f 100644 --- a/clients/client.go +++ b/clients/client.go @@ -1065,9 +1065,9 @@ func (c *Client) EstimateGasWithdraw(ctx context.Context, msg WithdrawalCallMsg) if errBridge != nil { return 0, fmt.Errorf("failed to getBridgeContracts: %w", errBridge) } - callMsg, err = msg.ToZkCallMsg(&contracts.L2SharedBridge) + callMsg, err = msg.ToCallMsg(&contracts.L2SharedBridge) } else { - callMsg, err = msg.ToZkCallMsg(nil) + callMsg, err = msg.ToCallMsg(nil) if err != nil { return 0, err } diff --git a/clients/types.go b/clients/types.go index a530e14..945a8fb 100644 --- a/clients/types.go +++ b/clients/types.go @@ -138,7 +138,7 @@ type WithdrawalCallMsg struct { CustomSignature hexutil.Bytes } -func (m *WithdrawalCallMsg) ToCallMsg(defaultL2Bridge *common.Address) (*ethereum.CallMsg, error) { +func (m *WithdrawalCallMsg) ToL1CallMsg(defaultL2Bridge *common.Address) (*ethereum.CallMsg, error) { if m.Token == utils.L2BaseTokenAddress { ethTokenAbi, err := ethtoken.IEthTokenMetaData.GetAbi() if err != nil { @@ -186,8 +186,8 @@ func (m *WithdrawalCallMsg) ToCallMsg(defaultL2Bridge *common.Address) (*ethereu } } -func (m *WithdrawalCallMsg) ToZkCallMsg(defaultL2Bridge *common.Address) (*types.CallMsg, error) { - msg, err := m.ToCallMsg(defaultL2Bridge) +func (m *WithdrawalCallMsg) ToCallMsg(defaultL2Bridge *common.Address) (*types.CallMsg, error) { + msg, err := m.ToL1CallMsg(defaultL2Bridge) if err != nil { return nil, err }