Skip to content

Commit

Permalink
can not use transient storage cross call
Browse files Browse the repository at this point in the history
  • Loading branch information
zkbenny committed Apr 5, 2024
1 parent 9bb3212 commit d151d29
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 39 deletions.
23 changes: 12 additions & 11 deletions contracts/Arbitrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,7 @@ contract Arbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Reentra
require(msg.value == _value, "Invalid msg value");
IL1Gateway sourceGateway = IL1Gateway(msg.sender);
// `forwardParams` is set in `claimMessage`
bytes memory _forwardParams;
assembly {
_forwardParams := tload(forwardParams.slot)
}
bytes memory _forwardParams = forwardParams;
// Ensure the caller is L1 gateway
if (sourceGateway == primaryChainGateway) {
// Unpack destination chain and final callData
Expand Down Expand Up @@ -216,31 +213,35 @@ contract Arbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Reentra
require(secondaryChainGateways[secondaryChainGateway], "Invalid secondary chain gateway");
// Forward fee to send message
secondaryChainGateway.sendMessage{value: msg.value + _value}(_value, finalCallData, _adapterParams);
emit MessageForwarded(secondaryChainGateway, _value, finalCallData);
} else {
require(secondaryChainGateways[_gateway], "Not secondary chain gateway");
require(
finalizeMessageHash == secondaryChainMessageHashQueues[_gateway].popFront(),
"Invalid finalize message hash"
);
// Forward fee to send message
primaryChainGateway.sendMessage{value: msg.value + _value}(_value, _callData, _adapterParams);
IL1Gateway targetGateway = primaryChainGateway;
targetGateway.sendMessage{value: msg.value + _value}(_value, _callData, _adapterParams);
emit MessageForwarded(targetGateway, _value, _callData);
}
emit MessageForwarded(_gateway, _value, _callData);
}

function claimMessage(
address _sourceChainCanonicalMessageService,
bytes calldata _sourceChainClaimCallData,
bytes memory _forwardParams
bytes calldata _forwardParams
) external payable nonReentrant onlyRelayer {
// The `forwardParams` will be cleared after tx executed
assembly {
tstore(forwardParams.slot, _forwardParams)
}
// The `forwardParams` and msg value will be used in `receiveMessage`
// The msg value is equal to the combined cost of all messages delivered from l1 to l2
// The excess fees will be refunded to the relayer by rollup canonical message service
forwardParams = _forwardParams;
// Call the claim interface of source chain message service
// And it will inner call the `claimMessageCallback` interface of source chain L1Gateway
// In the `claimMessageCallback` of L1Gateway, it will inner call `receiveMessage` of Arbitrator
// No use of return value
Address.functionCall(_sourceChainCanonicalMessageService, _sourceChainClaimCallData);
// Cleared after `receiveMessage`
forwardParams = new bytes(0);
}
}
2 changes: 1 addition & 1 deletion contracts/dev-contracts/DummyArbitrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract DummyArbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Re
_gateway.sendMessage{value: msg.value + _value}(_value, _callData, _adapterParams);
}

function claimMessage(address, bytes calldata, bytes memory) external payable {
function claimMessage(address, bytes calldata, bytes calldata) external payable {
// do nothing
}
}
2 changes: 1 addition & 1 deletion contracts/interfaces/IArbitrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ interface IArbitrator {
function claimMessage(
address _sourceChainCanonicalMessageService,
bytes calldata _sourceChainClaimCallData,
bytes memory _forwardParams
bytes calldata _forwardParams
) external payable;
}
15 changes: 1 addition & 14 deletions hardhat.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,7 @@ const hardhatUserConfig = {
},
},
},
],
overrides: {
'contracts/Arbitrator.sol': {
version: '0.8.25',
settings: {
viaIR: true,
optimizer: {
enabled: true,
runs: 200,
},
evmVersion: 'cancun',
},
},
},
]
},
networks: {
hardhat: {
Expand Down
12 changes: 0 additions & 12 deletions zksync/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ require('@matterlabs/hardhat-zksync-deploy');
require('@matterlabs/hardhat-zksync-solc');
require('@matterlabs/hardhat-zksync-verify');
require('@matterlabs/hardhat-zksync-upgradable');
const { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } = require('hardhat/builtin-tasks/task-names');
const path = require('path');

const fs = require('fs');

Expand All @@ -25,16 +23,6 @@ require('./script/deploy_l2_gateway');
require('./script/deploy_erc20_bridge');

const BaseConfig = require('../hardhat.base.config');
const { subtask } = require('hardhat/config');
subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS, async (_, { config }, runSuper) => {
const paths = await runSuper();

return paths.filter(solidityFilePath => {
const relativePath = path.relative(config.paths.sources, solidityFilePath);

return relativePath !== 'Arbitrator.sol';
});
});

module.exports = Object.assign({}, BaseConfig, {
zksolc: {
Expand Down

0 comments on commit d151d29

Please sign in to comment.