Skip to content

Commit

Permalink
feat(protocol): enhance nextTxId logics in DelegateOwner (#17718)
Browse files Browse the repository at this point in the history
Co-authored-by: D <[email protected]>
  • Loading branch information
dantaik and adaki2004 authored Jul 21, 2024
1 parent 185ef91 commit 85b2cad
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 140 deletions.
1 change: 1 addition & 0 deletions packages/protocol/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ artifacts
cache
coverage
lib
contracts/test/thirdparty/
contracts/automata-attestation/
1 change: 1 addition & 0 deletions packages/protocol/.solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ lib/
contracts/test/TestLibRLPReader.sol
**/contracts/thirdparty/**/*.sol
/contracts/automata-attestation/
test/thirdparty/
test/GasComparison.t.sol
test/TestLn.sol
14 changes: 10 additions & 4 deletions packages/protocol/contracts/L2/DelegateOwner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ contract DelegateOwner is EssentialContract, IMessageInvocable {
/// @param txId The transaction ID.
/// @param target The target address.
/// @param isDelegateCall True if the call is a `delegatecall`.
/// @param selector The function selector.
/// @param txdata The transaction data.
event MessageInvoked(
uint64 indexed txId, address indexed target, bool isDelegateCall, bytes4 indexed selector
uint64 indexed txId, address indexed target, bool isDelegateCall, bytes txdata
);

/// @notice Emitted when the admin has been changed.
Expand Down Expand Up @@ -123,7 +123,13 @@ contract DelegateOwner is EssentialContract, IMessageInvocable {
function _invokeCall(bytes calldata _data, bool _verifyTxId) private {
Call memory call = abi.decode(_data, (Call));

if (_verifyTxId && call.txId != nextTxId++) revert DO_INVALID_TX_ID();
if (call.txId == 0) {
call.txId = nextTxId;
} else if (_verifyTxId && call.txId != nextTxId) {
revert DO_INVALID_TX_ID();
}

nextTxId += 1;

// By design, the target must be a contract address if the txdata is not empty
if (call.txdata.length != 0 && !Address.isContract(call.target)) revert DO_INVALID_TARGET();
Expand All @@ -133,7 +139,7 @@ contract DelegateOwner is EssentialContract, IMessageInvocable {
: call.target.call{ value: msg.value }(call.txdata);

if (!success) LibBytes.revertWithExtractedError(result);
emit MessageInvoked(call.txId, call.target, call.isDelegateCall, bytes4(call.txdata));
emit MessageInvoked(call.txId, call.target, call.isDelegateCall, call.txdata);
}

function _isAdminOrRemoteOwner(address _sender) private view returns (bool) {
Expand Down
8 changes: 4 additions & 4 deletions packages/protocol/deployments/mainnet-contract-logs-L2.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@

#### delegate_owner

- proxy: `0x904aa0aC002532f1410457484893107757683F53`
- impl: `0x9F0C40A474E0FB6b27D71c43Aff840B9c42f0C44`
- admin: `0x8F13E3a9dFf52e282884aA70eAe93F57DD601298`
- remoteOwner: `0x8F13E3a9dFf52e282884aA70eAe93F57DD601298`
- proxy: `0x5995941Df88F30Ac140515AA39832db963E2f863`
- impl: `0x1f0511cDae2fbfD93563469dA02b82dEd320C8Bd`
- admin: `0x3c181965C5cFAE61a9010A283e5e0C1445649810` // owned by Daniel W
- remoteOwner: `0x3c181965C5cFAE61a9010A283e5e0C1445649810` // owned by Daniel W
- todo:
- test various use cases
- transfer remote owner to `admin.taiko.eth`
Expand Down
6 changes: 4 additions & 2 deletions packages/protocol/script/DeployL2DelegateOwner.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import "../contracts/L2/DelegateOwner.sol";
// forge script --rpc-url https://rpc.mainnet.taiko.xyz script/DeployL2DelegateOwner.s.sol
contract DeployL2DelegateOwner is DeployCapability {
address public l2Sam = 0x1670000000000000000000000000000000000006;
address public l1Owner = 0x8F13E3a9dFf52e282884aA70eAe93F57DD601298; // Daniel's EOA
address public l2Admin = 0x8F13E3a9dFf52e282884aA70eAe93F57DD601298; // same
address public testAccount2 = 0x3c181965C5cFAE61a9010A283e5e0C1445649810; // owned by Daniel W

address public l1Owner = testAccount2;
address public l2Admin = testAccount2;

modifier broadcast() {
vm.startBroadcast();
Expand Down
68 changes: 0 additions & 68 deletions packages/protocol/script/L1DelegateOwnerBatching.s.sol

This file was deleted.

57 changes: 57 additions & 0 deletions packages/protocol/script/SendMessageToDelegateOwner.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "forge-std/src/Script.sol";
import "../contracts/L2/DelegateOwner.sol";
import "../contracts/bridge/IBridge.sol";
import "../test/thirdparty/muticall3/Multicall3.sol";

contract SendMessageToDelegateOwner is Script {
address public delegateOwner = 0x5995941Df88F30Ac140515AA39832db963E2f863;
address public delegateOwnerImpl = 0x1f0511cDae2fbfD93563469dA02b82dEd320C8Bd;
address public multicall3 = 0xcA11bde05977b3631167028862bE2a173976CA11;
address public l1Bridge = 0xd60247c6848B7Ca29eDdF63AA924E53dB6Ddd8EC;
address public testAccount1 = 0x3c181965C5cFAE61a9010A283e5e0C1445649810; // owned by Daniel W

modifier broadcast() {
vm.startBroadcast();
_;
vm.stopBroadcast();
}

function run() external broadcast {
Multicall3.Call3[] memory calls = new Multicall3.Call3[](2);
calls[0].target = delegateOwner;
calls[0].allowFailure = false;
calls[0].callData =
abi.encodeCall(DelegateOwner.setAdmin, (0x4757D97449acA795510b9f3152C6a9019A3545c3));

calls[1].target = delegateOwner;
calls[1].allowFailure = false;
calls[1].callData = abi.encodeCall(UUPSUpgradeable.upgradeTo, (delegateOwnerImpl));

DelegateOwner.Call memory dcall = DelegateOwner.Call({
txId: 1, // Has to match with DelegateOwner's nextTxId or 0
target: multicall3,
isDelegateCall: true,
txdata: abi.encodeCall(Multicall3.aggregate3, (calls))
});

// Use https://bridge.taiko.xyz/relayer to manually trigger the message if necessary.
IBridge.Message memory message = IBridge.Message({
id: 0,
fee: 0,
gasLimit: 1_000_000, // cannot be zero
from: msg.sender,
srcChainId: 1,
srcOwner: msg.sender,
destChainId: 167_000,
destOwner: delegateOwner,
to: delegateOwner,
value: 0,
data: abi.encodeCall(DelegateOwner.onMessageInvocation, abi.encode(dcall))
});

IBridge(l1Bridge).sendMessage(message);
}
}
10 changes: 5 additions & 5 deletions packages/protocol/test/L2/DelegateOwner.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "../common/TestMulticall3.sol";
import "../thirdparty/muticall3/Multicall3.sol";
import "../TaikoTest.sol";

contract Target is EssentialContract {
Expand All @@ -17,7 +17,7 @@ contract TestDelegateOwner is TaikoTest {
SignalService public signalService;
AddressManager public addressManager;
DelegateOwner public delegateOwner;
TestMulticall3 public multicall;
Multicall3 public multicall;

uint64 remoteChainId = uint64(block.chainid + 1);
address remoteBridge = vm.addr(0x2000);
Expand All @@ -30,7 +30,7 @@ contract TestDelegateOwner is TaikoTest {

vm.startPrank(owner);

multicall = new TestMulticall3();
multicall = new Multicall3();

addressManager = AddressManager(
deployProxy({
Expand Down Expand Up @@ -169,7 +169,7 @@ contract TestDelegateOwner is TaikoTest {
})
);

TestMulticall3.Call3[] memory calls = new TestMulticall3.Call3[](4);
Multicall3.Call3[] memory calls = new Multicall3.Call3[](4);
calls[0].target = address(target1);
calls[0].allowFailure = false;
calls[0].callData = abi.encodeCall(EssentialContract.pause, ());
Expand All @@ -191,7 +191,7 @@ contract TestDelegateOwner is TaikoTest {
uint64(0),
address(multicall),
true, // DELEGATECALL
abi.encodeCall(TestMulticall3.aggregate3, (calls))
abi.encodeCall(Multicall3.aggregate3, (calls))
)
);

Expand Down
57 changes: 0 additions & 57 deletions packages/protocol/test/common/TestMulticall3.sol

This file was deleted.

Loading

0 comments on commit 85b2cad

Please sign in to comment.