Skip to content

Commit d041d28

Browse files
committedNov 11, 2022
feat: notary for multiple native bridges
1 parent 7d12e34 commit d041d28

File tree

10 files changed

+389
-190
lines changed

10 files changed

+389
-190
lines changed
 

‎src/accumulators/ArbitrumL1Accum.sol

-125
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
// SPDX-License-Identifier: GPL-3.0-only
22
pragma solidity 0.8.7;
33

4-
import "./BaseAccum.sol";
5-
import "../interfaces/INotary.sol";
6-
import "../interfaces/native-bridge/IArbSys.sol";
4+
import "../BaseAccum.sol";
5+
import "../../interfaces/INotary.sol";
76

8-
contract ArbitrumL2Accum is BaseAccum {
7+
abstract contract NativeBridgeAccum is BaseAccum {
98
address public remoteNotary;
109
uint256 public immutable _chainSlug;
1110

12-
IArbSys constant arbsys = IArbSys(address(100));
13-
14-
event L2ToL1TxCreated(uint256 indexed withdrawalId);
1511
event UpdatedNotary(address notary_);
1612

1713
constructor(
@@ -23,12 +19,11 @@ contract ArbitrumL2Accum is BaseAccum {
2319
_chainSlug = chainSlug_;
2420
}
2521

26-
function setRemoteNotary(address notary_) external onlyOwner {
27-
remoteNotary = notary_;
28-
emit UpdatedNotary(notary_);
29-
}
22+
function sendL2Message(uint256[] calldata bridgeParams, bytes memory data)
23+
internal
24+
virtual;
3025

31-
function sealPacket(uint256[] calldata)
26+
function sealPacket(uint256[] calldata bridgeParams)
3227
external
3328
payable
3429
override
@@ -41,33 +36,21 @@ contract ArbitrumL2Accum is BaseAccum {
4136
{
4237
uint256 packetId = _sealedPackets++;
4338
bytes32 root = _roots[packetId];
44-
4539
if (root == bytes32(0)) revert NoPendingPacket();
40+
4641
bytes memory data = abi.encodeWithSelector(
4742
INotary.attest.selector,
4843
_getPacketId(packetId),
4944
root,
5045
bytes("")
5146
);
5247

53-
uint256 withdrawalId = arbsys.sendTxToL1(remoteNotary, data);
48+
sendL2Message(bridgeParams, data);
5449

55-
emit L2ToL1TxCreated(withdrawalId);
5650
emit PacketComplete(root, packetId);
5751
return (root, packetId, remoteChainSlug);
5852
}
5953

60-
function _getPacketId(uint256 packetCount_)
61-
internal
62-
view
63-
returns (uint256 packetId)
64-
{
65-
packetId =
66-
(_chainSlug << 224) |
67-
(uint256(uint160(address(this))) << 64) |
68-
packetCount_;
69-
}
70-
7154
function addPackedMessage(bytes32 packedMessage)
7255
external
7356
override
@@ -79,4 +62,20 @@ contract ArbitrumL2Accum is BaseAccum {
7962

8063
emit MessageAdded(packedMessage, packetId, packedMessage);
8164
}
65+
66+
function setRemoteNotary(address notary_) external onlyOwner {
67+
remoteNotary = notary_;
68+
emit UpdatedNotary(notary_);
69+
}
70+
71+
function _getPacketId(uint256 packetCount_)
72+
internal
73+
view
74+
returns (uint256 packetId)
75+
{
76+
packetId =
77+
(_chainSlug << 224) |
78+
(uint256(uint160(address(this))) << 64) |
79+
packetCount_;
80+
}
8281
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// SPDX-License-Identifier: GPL-3.0-only
2+
pragma solidity 0.8.7;
3+
4+
import "../NativeBridgeAccum.sol";
5+
import "../../../interfaces/native-bridge/IInbox.sol";
6+
7+
contract ArbitrumL1Accum is NativeBridgeAccum {
8+
address public remoteRefundAddress;
9+
address public callValueRefundAddress;
10+
IInbox public inbox;
11+
12+
event RetryableTicketCreated(uint256 indexed ticketId);
13+
event UpdatedInboxAddress(address inbox_);
14+
event UpdatedRefundAddresses(
15+
address remoteRefundAddress_,
16+
address callValueRefundAddress_
17+
);
18+
19+
constructor(
20+
address socket_,
21+
address notary_,
22+
address inbox_,
23+
uint32 remoteChainSlug_,
24+
uint32 chainSlug_
25+
) NativeBridgeAccum(socket_, notary_, remoteChainSlug_, chainSlug_) {
26+
inbox = IInbox(inbox_);
27+
remoteRefundAddress = msg.sender;
28+
callValueRefundAddress = msg.sender;
29+
}
30+
31+
function sendL2Message(uint256[] calldata bridgeParams, bytes memory data)
32+
internal
33+
override
34+
{
35+
// to avoid stack too deep
36+
address callValueRefund = callValueRefundAddress;
37+
address remoteRefund = remoteRefundAddress;
38+
39+
uint256 ticketID = inbox.createRetryableTicket{value: msg.value}(
40+
remoteNotary,
41+
0, // no value needed for attest
42+
bridgeParams[0], // maxSubmissionCost
43+
remoteRefund,
44+
callValueRefund,
45+
bridgeParams[1], // maxGas
46+
bridgeParams[2], // gasPriceBid
47+
data
48+
);
49+
emit RetryableTicketCreated(ticketID);
50+
}
51+
52+
function updateRefundAddresses(
53+
address remoteRefundAddress_,
54+
address callValueRefundAddress_
55+
) external onlyOwner {
56+
remoteRefundAddress = remoteRefundAddress_;
57+
callValueRefundAddress = callValueRefundAddress_;
58+
59+
emit UpdatedRefundAddresses(
60+
remoteRefundAddress_,
61+
callValueRefundAddress_
62+
);
63+
}
64+
65+
function updateInboxAddresses(address inbox_) external onlyOwner {
66+
inbox = IInbox(inbox_);
67+
68+
emit UpdatedInboxAddress(inbox_);
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// SPDX-License-Identifier: GPL-3.0-only
2+
pragma solidity 0.8.7;
3+
4+
import "../NativeBridgeAccum.sol";
5+
import "../../../interfaces/INotary.sol";
6+
import "../../../interfaces/native-bridge/IArbSys.sol";
7+
8+
contract ArbitrumL2Accum is NativeBridgeAccum {
9+
IArbSys constant arbsys = IArbSys(address(100));
10+
event L2ToL1TxCreated(uint256 indexed withdrawalId);
11+
12+
constructor(
13+
address socket_,
14+
address notary_,
15+
uint32 remoteChainSlug_,
16+
uint32 chainSlug_
17+
) NativeBridgeAccum(socket_, notary_, remoteChainSlug_, chainSlug_) {}
18+
19+
function sendL2Message(uint256[] calldata, bytes memory data)
20+
internal
21+
override
22+
{
23+
uint256 withdrawalId = arbsys.sendTxToL1(remoteNotary, data);
24+
emit L2ToL1TxCreated(withdrawalId);
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SPDX-License-Identifier: GPL-3.0-only
2+
pragma solidity 0.8.7;
3+
4+
/**
5+
* @title ICrossDomainMessenger
6+
*/
7+
interface ICrossDomainMessenger {
8+
/**********
9+
* Events *
10+
**********/
11+
12+
event SentMessage(
13+
address indexed target,
14+
address sender,
15+
bytes message,
16+
uint256 messageNonce,
17+
uint256 gasLimit
18+
);
19+
event RelayedMessage(bytes32 indexed msgHash);
20+
event FailedRelayedMessage(bytes32 indexed msgHash);
21+
22+
/*************
23+
* Variables *
24+
*************/
25+
26+
function xDomainMessageSender() external view returns (address);
27+
28+
/********************
29+
* Public Functions *
30+
********************/
31+
32+
/**
33+
* Sends a cross domain message to the target messenger.
34+
* @param _target Target contract address.
35+
* @param _message Message to send to the target.
36+
* @param _gasLimit Gas limit for the provided message.
37+
*/
38+
function sendMessage(
39+
address _target,
40+
bytes calldata _message,
41+
uint32 _gasLimit
42+
) external;
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: GPL-3.0-only
2+
pragma solidity 0.8.7;
3+
4+
/**
5+
* @title IFxMessageProcessor
6+
* @notice Defines the interface to process message
7+
*/
8+
interface IFxMessageProcessor {
9+
/**
10+
* @notice Process the cross-chain message from a FxChild contract through the Ethereum/Polygon StateSender
11+
* @param stateId The id of the cross-chain message created in the Ethereum/Polygon StateSender
12+
* @param rootMessageSender The address that initially sent this message on Ethereum
13+
* @param data The data from the abi-encoded cross-chain message
14+
**/
15+
function processMessageFromRoot(
16+
uint256 stateId,
17+
address rootMessageSender,
18+
bytes calldata data
19+
) external;
20+
}

0 commit comments

Comments
 (0)