Skip to content

Commit

Permalink
use calldata to save gas
Browse files Browse the repository at this point in the history
  • Loading branch information
zkbenny committed Mar 6, 2024
1 parent 67c504e commit c56b4fd
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 40 deletions.
12 changes: 6 additions & 6 deletions contracts/Arbitrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ contract Arbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Reentra
function setSecondaryChainGateway(
IL1Gateway _gateway,
bool _active,
bytes memory _adapterParams
bytes calldata _adapterParams
) external payable onlyOwner {
require(_gateway != primaryChainGateway, "Invalid gateway");
secondaryChainGateways[_gateway] = _active;
Expand All @@ -104,7 +104,7 @@ contract Arbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Reentra
IL1Gateway _gateway,
address _validator,
bool _active,
bytes memory _adapterParams
bytes calldata _adapterParams
) external payable onlyOwner {
require(_gateway == primaryChainGateway || secondaryChainGateways[_gateway], "Invalid gateway");
bytes memory callData = abi.encodeCall(IAdmin.setValidator, (_validator, _active));
Expand All @@ -117,7 +117,7 @@ contract Arbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Reentra
function changeFeeParams(
IL1Gateway _gateway,
FeeParams calldata _newFeeParams,
bytes memory _adapterParams
bytes calldata _adapterParams
) external payable onlyOwner {
require(_gateway == primaryChainGateway || secondaryChainGateways[_gateway], "Invalid gateway");
bytes memory callData = abi.encodeCall(IAdmin.changeFeeParams, (_newFeeParams));
Expand All @@ -126,7 +126,7 @@ contract Arbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Reentra
emit NewFeeParams(_gateway, _newFeeParams);
}

function receiveMessage(uint256 _value, bytes memory _callData) external payable {
function receiveMessage(uint256 _value, bytes calldata _callData) external payable {
require(msg.value == _value, "Invalid msg value");
// store message hash for forwarding
bytes32 finalizeMessageHash = keccak256(abi.encode(_value, _callData));
Expand All @@ -143,8 +143,8 @@ contract Arbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Reentra
function forwardMessage(
IL1Gateway _gateway,
uint256 _value,
bytes memory _callData,
bytes memory _adapterParams
bytes calldata _callData,
bytes calldata _adapterParams
) external payable nonReentrant onlyRelayer {
bytes32 finalizeMessageHash = keccak256(abi.encode(_value, _callData));
if (_gateway == primaryChainGateway) {
Expand Down
6 changes: 3 additions & 3 deletions contracts/dev-contracts/DummyArbitrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ contract DummyArbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Re

function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}

function receiveMessage(uint256 _value, bytes memory _callData) external payable {
function receiveMessage(uint256 _value, bytes calldata _callData) external payable {
require(msg.value == _value, "Invalid msg value");
emit ReceiveMessage(_value, _callData);
}

function forwardMessage(
IL1Gateway _gateway,
uint256 _value,
bytes memory _callData,
bytes memory _adapterParams
bytes calldata _callData,
bytes calldata _adapterParams
) external payable {
// Forward fee to send message
_gateway.sendMessage{value: msg.value + _value}(_value, _callData, _adapterParams);
Expand Down
6 changes: 3 additions & 3 deletions contracts/gateway/arbitrum/ArbitrumL1Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ contract ArbitrumL1Gateway is IMessageClaimer, L1BaseGateway, BaseGateway {

function sendMessage(
uint256 _value,
bytes memory _callData,
bytes memory _adapterParams
bytes calldata _callData,
bytes calldata _adapterParams
) external payable onlyArbitrator {
(uint256 maxSubmissionCost, uint256 gasLimit, uint256 maxFeePerGas) = abi.decode(
_adapterParams,
Expand All @@ -55,7 +55,7 @@ contract ArbitrumL1Gateway is IMessageClaimer, L1BaseGateway, BaseGateway {
);
}

function claimMessageCallback(uint256 _value, bytes memory _callData) external payable onlyRemoteGateway {
function claimMessageCallback(uint256 _value, bytes calldata _callData) external payable onlyRemoteGateway {
require(msg.value == _value, "Invalid value");
// Forward message to arbitrator
ARBITRATOR.receiveMessage{value: _value}(_value, _callData);
Expand Down
4 changes: 2 additions & 2 deletions contracts/gateway/arbitrum/ArbitrumL2Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract ArbitrumL2Gateway is IMessageClaimer, L2BaseGateway, BaseGateway {
__BaseGateway_init();
}

function sendMessage(uint256 _value, bytes memory _callData) external payable override onlyZkLink {
function sendMessage(uint256 _value, bytes calldata _callData) external payable override onlyZkLink {
// no fee
require(msg.value == _value, "Invalid value");

Expand All @@ -36,7 +36,7 @@ contract ArbitrumL2Gateway is IMessageClaimer, L2BaseGateway, BaseGateway {
emit L2GatewayMessageSent(_value, _callData);
}

function claimMessageCallback(uint256 _value, bytes memory _callData) external payable onlyRemoteGateway {
function claimMessageCallback(uint256 _value, bytes calldata _callData) external payable onlyRemoteGateway {
require(msg.value == _value, "Invalid value");

// solhint-disable-next-line avoid-low-level-calls
Expand Down
4 changes: 2 additions & 2 deletions contracts/gateway/ethereum/EthereumGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ contract EthereumGateway is
return address(this);
}

function sendMessage(uint256 _value, bytes memory _callData, bytes memory) external payable onlyArbitrator {
function sendMessage(uint256 _value, bytes calldata _callData, bytes calldata) external payable onlyArbitrator {
require(msg.value == _value, "Invalid value");

// solhint-disable-next-line avoid-low-level-calls
(bool success, ) = ZKLINK.call{value: _value}(_callData);
require(success, "Call zkLink failed");
}

function sendMessage(uint256 _value, bytes memory _callData) external payable override onlyZkLink {
function sendMessage(uint256 _value, bytes calldata _callData) external payable override onlyZkLink {
require(msg.value == _value, "Invalid value");
// Forward message to arbitrator
ARBITRATOR.receiveMessage{value: _value}(_value, _callData);
Expand Down
2 changes: 1 addition & 1 deletion contracts/gateway/linea/LineaL1Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract LineaL1Gateway is L1BaseGateway, LineaGateway {
__LineaGateway_init();
}

function sendMessage(uint256 _value, bytes memory _callData, bytes memory) external payable onlyArbitrator {
function sendMessage(uint256 _value, bytes calldata _callData, bytes calldata) external payable onlyArbitrator {
// transfer no fee to destination chain
require(msg.value == _value, "Invalid value");
bytes memory message = abi.encodeCall(IMessageClaimer.claimMessageCallback, (_value, _callData));
Expand Down
2 changes: 1 addition & 1 deletion contracts/gateway/linea/LineaL2Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract LineaL2Gateway is L2BaseGateway, LineaGateway {
__LineaGateway_init();
}

function sendMessage(uint256 _value, bytes memory _callData) external payable override onlyZkLink {
function sendMessage(uint256 _value, bytes calldata _callData) external payable override onlyZkLink {
// msg value should include fee
uint256 coinbaseFee = IL2MessageService(address(MESSAGE_SERVICE)).minimumFeeInWei();
require(msg.value == _value + coinbaseFee, "Invalid value");
Expand Down
4 changes: 2 additions & 2 deletions contracts/gateway/optimism/OptimismL1Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ contract OptimismL1Gateway is L1BaseGateway, OptimismGateway {

function sendMessage(
uint256 _value,
bytes memory _callData,
bytes memory _adapterParams
bytes calldata _callData,
bytes calldata _adapterParams
) external payable onlyArbitrator {
require(msg.value == _value, "Invalid value");
uint32 _minGasLimit = abi.decode(_adapterParams, (uint32));
Expand Down
2 changes: 1 addition & 1 deletion contracts/gateway/optimism/OptimismL2Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract OptimismL2Gateway is L2BaseGateway, OptimismGateway {
__OptimismGateway_init();
}

function sendMessage(uint256 _value, bytes memory _callData) external payable override onlyZkLink {
function sendMessage(uint256 _value, bytes calldata _callData) external payable override onlyZkLink {
require(msg.value == _value, "Invalid fee");

bytes memory message = abi.encodeCall(IMessageClaimer.claimMessageCallback, (_value, _callData));
Expand Down
6 changes: 3 additions & 3 deletions contracts/gateway/scroll/ScrollL1Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ contract ScrollL1Gateway is ScrollGateway, L1BaseGateway {

function sendMessage(
uint256 _value,
bytes memory _callData,
bytes memory _adapterParams
bytes calldata _callData,
bytes calldata _adapterParams
) external payable override onlyArbitrator {
uint256 _finalizeMessageGasLimit = abi.decode(_adapterParams, (uint256));

Expand All @@ -39,7 +39,7 @@ contract ScrollL1Gateway is ScrollGateway, L1BaseGateway {

function claimMessageCallback(
uint256 _value,
bytes memory _callData
bytes calldata _callData
) external payable override onlyMessageService onlyRemoteGateway {
// no fee
require(msg.value == _value, "Invalid value");
Expand Down
4 changes: 2 additions & 2 deletions contracts/gateway/scroll/ScrollL2Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract ScrollL2Gateway is L2BaseGateway, ScrollGateway {
__ScrollGateway_init();
}

function sendMessage(uint256 _value, bytes memory _callData) external payable override onlyZkLink {
function sendMessage(uint256 _value, bytes calldata _callData) external payable override onlyZkLink {
// no fee
require(msg.value == _value, "Invalid value");

Expand All @@ -35,7 +35,7 @@ contract ScrollL2Gateway is L2BaseGateway, ScrollGateway {

function claimMessageCallback(
uint256 _value,
bytes memory _callData
bytes calldata _callData
) external payable override onlyMessageService onlyRemoteGateway {
require(msg.value == _value, "Invalid value");

Expand Down
4 changes: 2 additions & 2 deletions contracts/gateway/zkpolygon/ZkPolygonL1Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract ZkPolygonL1Gateway is IBridgeMessageReceiver, L1BaseGateway, BaseGatewa
__BaseGateway_init();
}

function sendMessage(uint256 _value, bytes memory _callData, bytes memory) external payable onlyArbitrator {
function sendMessage(uint256 _value, bytes calldata _callData, bytes calldata) external payable onlyArbitrator {
require(msg.value == _value, "Invalid value");

bytes memory executeData = abi.encode(_value, _callData);
Expand All @@ -48,7 +48,7 @@ contract ZkPolygonL1Gateway is IBridgeMessageReceiver, L1BaseGateway, BaseGatewa
function onMessageReceived(
address originAddress,
uint32,
bytes memory data
bytes calldata data
) external payable override onlyMessageService {
require(originAddress == remoteGateway, "Invalid origin address");

Expand Down
4 changes: 2 additions & 2 deletions contracts/gateway/zkpolygon/ZkPolygonL2Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract ZkPolygonL2Gateway is IBridgeMessageReceiver, L2BaseGateway, BaseGatewa
__BaseGateway_init();
}

function sendMessage(uint256 _value, bytes memory _callData) external payable onlyZkLink {
function sendMessage(uint256 _value, bytes calldata _callData) external payable onlyZkLink {
// no fee
require(msg.value == _value, "Invalid value");

Expand All @@ -46,7 +46,7 @@ contract ZkPolygonL2Gateway is IBridgeMessageReceiver, L2BaseGateway, BaseGatewa
function onMessageReceived(
address originAddress,
uint32,
bytes memory data
bytes calldata data
) external payable override onlyMessageService {
require(originAddress == remoteGateway, "Invalid origin address");
(uint256 _value, bytes memory _callData) = abi.decode(data, (uint256, bytes));
Expand Down
4 changes: 2 additions & 2 deletions contracts/gateway/zksync/ZkSyncL1Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ contract ZkSyncL1Gateway is IZkSyncL1Gateway, L1BaseGateway, BaseGateway {

function sendMessage(
uint256 _value,
bytes memory _callData,
bytes memory _adapterParams
bytes calldata _callData,
bytes calldata _adapterParams
) external payable onlyArbitrator {
(uint256 _l2GasLimit, uint256 _l2GasPerPubdataByteLimit) = abi.decode(_adapterParams, (uint256, uint256));
bytes memory executeData = abi.encodeCall(IMessageClaimer.claimMessageCallback, (_value, _callData));
Expand Down
4 changes: 2 additions & 2 deletions contracts/gateway/zksync/ZkSyncL2Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract ZkSyncL2Gateway is IMessageClaimer, L2BaseGateway, BaseGateway {
__BaseGateway_init();
}

function sendMessage(uint256 _value, bytes memory _callData) external payable override onlyZkLink {
function sendMessage(uint256 _value, bytes calldata _callData) external payable override onlyZkLink {
// no fee
require(msg.value == _value, "Invalid value");

Expand All @@ -40,7 +40,7 @@ contract ZkSyncL2Gateway is IMessageClaimer, L2BaseGateway, BaseGateway {
emit L2GatewayMessageSent(_value, _callData);
}

function claimMessageCallback(uint256 _value, bytes memory _callData) external payable onlyRemoteGateway {
function claimMessageCallback(uint256 _value, bytes calldata _callData) external payable onlyRemoteGateway {
require(msg.value == _value, "Invalid value");

// solhint-disable-next-line avoid-low-level-calls
Expand Down
6 changes: 3 additions & 3 deletions contracts/interfaces/IArbitrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface IArbitrator {
/// @notice Receive message from one L1 gateway to another L1 gateway
/// @param _value The msg value
/// @param _callData The call data
function receiveMessage(uint256 _value, bytes memory _callData) external payable;
function receiveMessage(uint256 _value, bytes calldata _callData) external payable;

/// @notice Forward message from one L1 gateway to another L1 gateway
/// @param _gateway The message source gateway
Expand All @@ -17,7 +17,7 @@ interface IArbitrator {
function forwardMessage(
IL1Gateway _gateway,
uint256 _value,
bytes memory _callData,
bytes memory _adapterParams
bytes calldata _callData,
bytes calldata _adapterParams
) external payable;
}
2 changes: 1 addition & 1 deletion contracts/interfaces/IL1Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ interface IL1Gateway is IGateway {
/// @param _value The msg value
/// @param _callData The call data
/// @param _adapterParams Some params need to call canonical message service
function sendMessage(uint256 _value, bytes memory _callData, bytes memory _adapterParams) external payable;
function sendMessage(uint256 _value, bytes calldata _callData, bytes calldata _adapterParams) external payable;
}
2 changes: 1 addition & 1 deletion contracts/interfaces/IL2Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ interface IL2Gateway is IGateway {
/// @notice Send message to remote gateway
/// @param _value The msg value
/// @param _callData The call data
function sendMessage(uint256 _value, bytes memory _callData) external payable;
function sendMessage(uint256 _value, bytes calldata _callData) external payable;
}
2 changes: 1 addition & 1 deletion contracts/interfaces/IMessageClaimer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ interface IMessageClaimer {
/// @notice Receive callback called by message service
/// @param _value The message value
/// @param _callData The message data
function claimMessageCallback(uint256 _value, bytes memory _callData) external payable;
function claimMessageCallback(uint256 _value, bytes calldata _callData) external payable;
}

0 comments on commit c56b4fd

Please sign in to comment.