From bf16c88883596344ccb0dfc7fa4d63449bf42a7b Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Wed, 8 May 2024 15:43:26 +0800 Subject: [PATCH] processMessage returns status --- packages/protocol/contracts/L1/TaikoData.sol | 2 +- packages/protocol/contracts/bridge/Bridge.sol | 12 ++++++++++-- packages/protocol/contracts/bridge/IBridge.sol | 8 +++++++- packages/protocol/script/DeployERC20Airdrop.s.sol | 2 +- packages/protocol/script/DeployOnL1.s.sol | 6 +++--- packages/protocol/test/L2/TaikoL2.t.sol | 2 +- packages/protocol/test/L2/TaikoL2NoFeeCheck.t.sol | 2 +- .../common/AttestationBase.t.sol | 2 +- packages/protocol/test/bridge/Bridge.t.sol | 2 +- .../protocol/test/team/airdrop/ERC20Airdrop.t.sol | 4 ++-- packages/protocol/test/tokenvault/BridgedERC20.t.sol | 2 +- packages/protocol/test/tokenvault/ERC20Vault.t.sol | 6 +++--- .../protocol/test/verifiers/RiscZeroVerifier.t.sol | 2 +- 13 files changed, 33 insertions(+), 19 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoData.sol b/packages/protocol/contracts/L1/TaikoData.sol index 2c816af177..a9b0adc6ed 100644 --- a/packages/protocol/contracts/L1/TaikoData.sol +++ b/packages/protocol/contracts/L1/TaikoData.sol @@ -163,7 +163,7 @@ library TaikoData { mapping( uint64 blockId_mod_blockRingBufferSize => mapping(uint32 transitionId => TransitionState ts) - ) transitions; + ) transitions; // Ring buffer for Ether deposits bytes32 __reserve1; SlotA slotA; // slot 5 diff --git a/packages/protocol/contracts/bridge/Bridge.sol b/packages/protocol/contracts/bridge/Bridge.sol index b27816526e..a4122e2b87 100644 --- a/packages/protocol/contracts/bridge/Bridge.sol +++ b/packages/protocol/contracts/bridge/Bridge.sol @@ -216,13 +216,20 @@ contract Bridge is EssentialContract, IBridge { bytes calldata _proof ) external - sameChain(_message.destChainId) - diffChain(_message.srcChainId) whenNotPaused nonReentrant + returns (IBridge.Status) { uint256 gasStart = gasleft(); + // same as `sameChain(_message.destChainId)` but without stack-too-deep + if (_message.destChainId != block.chainid) revert B_INVALID_CHAINID(); + + // same as `diffChain(_message.srcChainId)` but without stack-too-deep + if (_message.srcChainId == 0 || _message.srcChainId == block.chainid) { + revert B_INVALID_CHAINID(); + } + // If the gas limit is set to zero, only the owner can process the message. if (_message.gasLimit == 0 && msg.sender != _message.destOwner) { revert B_PERMISSION_DENIED(); @@ -281,6 +288,7 @@ contract Bridge is EssentialContract, IBridge { _updateMessageStatus(msgHash, stats.status); emit MessageProcessed(msgHash, _message, stats); + return stats.status; } /// @inheritdoc IBridge diff --git a/packages/protocol/contracts/bridge/IBridge.sol b/packages/protocol/contracts/bridge/IBridge.sol index 0e2ad57bfd..2ab3830833 100644 --- a/packages/protocol/contracts/bridge/IBridge.sol +++ b/packages/protocol/contracts/bridge/IBridge.sol @@ -90,7 +90,13 @@ interface IBridge { /// needed. /// @param _message The message to be processed. /// @param _proof The merkle inclusion proof. - function processMessage(Message calldata _message, bytes calldata _proof) external; + /// @return The messsage's status after processing. + function processMessage( + Message calldata _message, + bytes calldata _proof + ) + external + returns (Status); /// @notice Retries to invoke the messageCall after releasing associated /// Ether and tokens. diff --git a/packages/protocol/script/DeployERC20Airdrop.s.sol b/packages/protocol/script/DeployERC20Airdrop.s.sol index 70d0f7f3d4..cd640a0239 100644 --- a/packages/protocol/script/DeployERC20Airdrop.s.sol +++ b/packages/protocol/script/DeployERC20Airdrop.s.sol @@ -37,7 +37,7 @@ contract DeployERC20Airdrop is DeployCapability { impl: address(new ERC20Airdrop()), data: abi.encodeCall( ERC20Airdrop.init, (address(0), 0, 0, bytes32(0), bridgedTko, vaultAddress) - ) + ) }) ); diff --git a/packages/protocol/script/DeployOnL1.s.sol b/packages/protocol/script/DeployOnL1.s.sol index 751379e463..fe0577c4d5 100644 --- a/packages/protocol/script/DeployOnL1.s.sol +++ b/packages/protocol/script/DeployOnL1.s.sol @@ -152,7 +152,7 @@ contract DeployOnL1 is DeployCapability { impl: address(new TaikoToken()), data: abi.encodeCall( TaikoToken.init, (owner, vm.envAddress("TAIKO_TOKEN_PREMINT_RECIPIENT")) - ), + ), registerTo: sharedAddressManager }); } @@ -263,7 +263,7 @@ contract DeployOnL1 is DeployCapability { vm.envBytes32("L2_GENESIS_HASH"), vm.envBool("PAUSE_TAIKO_L1") ) - ), + ), registerTo: rollupAddressManager }); @@ -330,7 +330,7 @@ contract DeployOnL1 is DeployCapability { impl: automateDcapV3AttestationImpl, data: abi.encodeCall( AutomataDcapV3Attestation.init, (owner, address(sigVerifyLib), address(pemCertChainLib)) - ), + ), registerTo: rollupAddressManager }); diff --git a/packages/protocol/test/L2/TaikoL2.t.sol b/packages/protocol/test/L2/TaikoL2.t.sol index 3665c3cf43..eadb14a6f3 100644 --- a/packages/protocol/test/L2/TaikoL2.t.sol +++ b/packages/protocol/test/L2/TaikoL2.t.sol @@ -49,7 +49,7 @@ contract TestTaikoL2 is TaikoTest { impl: address(new TaikoL2EIP1559Configurable()), data: abi.encodeCall( TaikoL2.init, (address(0), addressManager, l1ChainId, gasExcess) - ), + ), registerTo: addressManager }) ) diff --git a/packages/protocol/test/L2/TaikoL2NoFeeCheck.t.sol b/packages/protocol/test/L2/TaikoL2NoFeeCheck.t.sol index 6a10e25d6c..8b21fbaf56 100644 --- a/packages/protocol/test/L2/TaikoL2NoFeeCheck.t.sol +++ b/packages/protocol/test/L2/TaikoL2NoFeeCheck.t.sol @@ -49,7 +49,7 @@ contract TestTaikoL2NoFeeCheck is TaikoTest { impl: address(new SkipBasefeeCheckL2()), data: abi.encodeCall( TaikoL2.init, (address(0), addressManager, l1ChainId, gasExcess) - ), + ), registerTo: addressManager }) ) diff --git a/packages/protocol/test/automata-attestation/common/AttestationBase.t.sol b/packages/protocol/test/automata-attestation/common/AttestationBase.t.sol index 453d7d6647..4133197796 100644 --- a/packages/protocol/test/automata-attestation/common/AttestationBase.t.sol +++ b/packages/protocol/test/automata-attestation/common/AttestationBase.t.sol @@ -61,7 +61,7 @@ contract AttestationBase is Test, DcapTestUtils, V3QuoteParseUtils { data: abi.encodeCall( AutomataDcapV3Attestation.init, (admin, address(sigVerifyLib), address(pemCertChainLib)) - ) + ) }) ); diff --git a/packages/protocol/test/bridge/Bridge.t.sol b/packages/protocol/test/bridge/Bridge.t.sol index 0cf597e457..33caf89b67 100644 --- a/packages/protocol/test/bridge/Bridge.t.sol +++ b/packages/protocol/test/bridge/Bridge.t.sol @@ -93,7 +93,7 @@ contract BridgeTest is TaikoTest { impl: address(new DelegateOwner()), data: abi.encodeCall( DelegateOwner.init, (mockDAO, address(addressManager), l1ChainId) - ) + ) }) ) ); diff --git a/packages/protocol/test/team/airdrop/ERC20Airdrop.t.sol b/packages/protocol/test/team/airdrop/ERC20Airdrop.t.sol index ac33e31935..1222a7cf9e 100644 --- a/packages/protocol/test/team/airdrop/ERC20Airdrop.t.sol +++ b/packages/protocol/test/team/airdrop/ERC20Airdrop.t.sol @@ -102,7 +102,7 @@ contract TestERC20Airdrop is TaikoTest { data: abi.encodeCall( BridgedERC20.init, (address(0), address(addressManager), randAddress(), 100, 18, "TKO", "Taiko Token") - ) + ) }) ); @@ -129,7 +129,7 @@ contract TestERC20Airdrop is TaikoTest { data: abi.encodeCall( ERC20Airdrop.init, (address(0), claimStart, claimEnd, merkleRoot, address(token), address(vault)) - ) + ) }) ); diff --git a/packages/protocol/test/tokenvault/BridgedERC20.t.sol b/packages/protocol/test/tokenvault/BridgedERC20.t.sol index 80470c7064..6c92727d8c 100644 --- a/packages/protocol/test/tokenvault/BridgedERC20.t.sol +++ b/packages/protocol/test/tokenvault/BridgedERC20.t.sol @@ -131,7 +131,7 @@ contract TestBridgedERC20 is TaikoTest { data: abi.encodeCall( BridgedERC20.init, (owner, address(manager), srcToken, srcChainId, srcDecimals, name, name) - ), + ), registerTo: manager }) ); diff --git a/packages/protocol/test/tokenvault/ERC20Vault.t.sol b/packages/protocol/test/tokenvault/ERC20Vault.t.sol index 1f0fb5908f..e6e0749af6 100644 --- a/packages/protocol/test/tokenvault/ERC20Vault.t.sol +++ b/packages/protocol/test/tokenvault/ERC20Vault.t.sol @@ -177,7 +177,7 @@ contract TestERC20Vault is TaikoTest { data: abi.encodeCall( BridgedERC20.init, (address(0), address(addressManager), randAddress(), 100, 18, "USDC", "USDC coin") - ) + ) }) ); @@ -188,7 +188,7 @@ contract TestERC20Vault is TaikoTest { data: abi.encodeCall( BridgedERC20.init, (address(0), address(addressManager), randAddress(), 100, 18, "USDT", "USDT coin") - ) + ) }) ); @@ -207,7 +207,7 @@ contract TestERC20Vault is TaikoTest { "stETH", "Lido Staked ETH" ) - ) + ) }) ); vm.stopPrank(); diff --git a/packages/protocol/test/verifiers/RiscZeroVerifier.t.sol b/packages/protocol/test/verifiers/RiscZeroVerifier.t.sol index 75eb16dd2d..77c719d8a2 100644 --- a/packages/protocol/test/verifiers/RiscZeroVerifier.t.sol +++ b/packages/protocol/test/verifiers/RiscZeroVerifier.t.sol @@ -48,7 +48,7 @@ contract TestRiscZeroVerifier is TaikoL1TestBase { data: abi.encodeCall( RiscZeroVerifier.init, (address(0), address(addressManager), address(riscZeroRemoteVerifier)) - ) + ) }) );