Skip to content

Commit a1ff8e9

Browse files
Amxxernestognw
andauthored
Rebranding ERC7786Aggregator as ERC7786OpenBridge (#180)
Co-authored-by: ernestognw <[email protected]>
1 parent f9fc20c commit a1ff8e9

File tree

4 files changed

+70
-76
lines changed

4 files changed

+70
-76
lines changed

contracts/crosschain/ERC7786Aggregator.sol renamed to contracts/crosschain/ERC7786OpenBridge.sol

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {InteroperableAddress} from "@openzeppelin/contracts/utils/draft-Interope
1111

1212
/**
1313
* @dev N of M gateway: Sends your message through M independent gateways. It will be delivered to the receiver by an
14-
* equivalent aggregator on the destination chain if N of the M gateways agree.
14+
* equivalent bridge on the destination chain if N of the M gateways agree.
1515
*/
16-
contract ERC7786Aggregator is IERC7786GatewaySource, IERC7786Receiver, Ownable, Pausable {
16+
contract ERC7786OpenBridge is IERC7786GatewaySource, IERC7786Receiver, Ownable, Pausable {
1717
using EnumerableSet for EnumerableSet.AddressSet;
1818
using InteroperableAddress for bytes;
1919

@@ -37,19 +37,19 @@ contract ERC7786Aggregator is IERC7786GatewaySource, IERC7786Receiver, Ownable,
3737
event ThresholdUpdated(uint8 threshold);
3838

3939
error UnsupportedNativeTransfer();
40-
error ERC7786AggregatorInvalidCrosschainSender();
41-
error ERC7786AggregatorAlreadyExecuted();
42-
error ERC7786AggregatorRemoteNotRegistered(bytes2 chainType, bytes chainReference);
43-
error ERC7786AggregatorGatewayAlreadyRegistered(address gateway);
44-
error ERC7786AggregatorGatewayNotRegistered(address gateway);
45-
error ERC7786AggregatorThresholdViolation();
46-
error ERC7786AggregatorInvalidExecutionReturnValue();
40+
error ERC7786OpenBridgeInvalidCrosschainSender();
41+
error ERC7786OpenBridgeAlreadyExecuted();
42+
error ERC7786OpenBridgeRemoteNotRegistered(bytes2 chainType, bytes chainReference);
43+
error ERC7786OpenBridgeGatewayAlreadyRegistered(address gateway);
44+
error ERC7786OpenBridgeGatewayNotRegistered(address gateway);
45+
error ERC7786OpenBridgeThresholdViolation();
46+
error ERC7786OpenBridgeInvalidExecutionReturnValue();
4747

4848
/****************************************************************************************************************
4949
* S T A T E V A R I A B L E S *
5050
****************************************************************************************************************/
5151

52-
/// @dev address of the matching aggregator for a given CAIP2 chain
52+
/// @dev address of the matching bridge for a given CAIP2 chain
5353
mapping(bytes2 chainType => mapping(bytes chainReference => bytes addr)) private _remotes;
5454

5555
/// @dev Tracking of the received message pending final delivery
@@ -99,8 +99,8 @@ contract ERC7786Aggregator is IERC7786GatewaySource, IERC7786Receiver, Ownable,
9999
if (attributes.length > 0)
100100
revert UnsupportedAttribute(attributes[0].length < 0x04 ? bytes4(0) : bytes4(attributes[0][0:4]));
101101

102-
// address of the remote aggregator, revert if not registered
103-
bytes memory aggregator = getRemoteAggregator(recipient);
102+
// address of the remote bridge, revert if not registered
103+
bytes memory bridge = getRemoteBridge(recipient);
104104
bytes memory sender = InteroperableAddress.formatEvmV1(block.chainid, msg.sender);
105105

106106
// wrapping the payload
@@ -112,7 +112,7 @@ contract ERC7786Aggregator is IERC7786GatewaySource, IERC7786Receiver, Ownable,
112112
for (uint256 i = 0; i < outbox.length; ++i) {
113113
address gateway = _gateways.at(i);
114114
// send message
115-
bytes32 id = IERC7786GatewaySource(gateway).sendMessage(aggregator, wrappedPayload, attributes);
115+
bytes32 id = IERC7786GatewaySource(gateway).sendMessage(bridge, wrappedPayload, attributes);
116116
// if ID, track it
117117
if (id != bytes32(0)) {
118118
outbox[i] = Outbox(gateway, id);
@@ -135,7 +135,7 @@ contract ERC7786Aggregator is IERC7786GatewaySource, IERC7786Receiver, Ownable,
135135
*
136136
* @dev This function serves a dual purpose:
137137
*
138-
* It will be called by ERC-7786 gateways with message coming from the the corresponding aggregator on the source
138+
* It will be called by ERC-7786 gateways with message coming from the the corresponding bridge on the source
139139
* chain. These "signals" are tracked until the threshold is reached. At that point the message is sent to the
140140
* destination.
141141
*
@@ -148,7 +148,7 @@ contract ERC7786Aggregator is IERC7786GatewaySource, IERC7786Receiver, Ownable,
148148
*
149149
* This function revert if:
150150
*
151-
* * the message is not properly formatted or does not originate from the registered aggregator on the source
151+
* * the message is not properly formatted or does not originate from the registered bridge on the source
152152
* chain.
153153
* * someone tries re-execute a message that was already successfully delivered. This includes gateways that call
154154
* this function a second time with a message that was already executed.
@@ -179,11 +179,8 @@ contract ERC7786Aggregator is IERC7786GatewaySource, IERC7786Receiver, Ownable,
179179
bytes calldata payload,
180180
bytes[] calldata attributes
181181
) public payable virtual whenNotPaused returns (bytes4) {
182-
// Check sender is a trusted aggregator
183-
require(
184-
keccak256(getRemoteAggregator(sender)) == keccak256(sender),
185-
ERC7786AggregatorInvalidCrosschainSender()
186-
);
182+
// Check sender is a trusted bridge
183+
require(keccak256(getRemoteBridge(sender)) == keccak256(sender), ERC7786OpenBridgeInvalidCrosschainSender());
187184

188185
// Message reception tracker
189186
bytes32 id = keccak256(abi.encode(sender, payload, attributes));
@@ -199,7 +196,7 @@ contract ERC7786Aggregator is IERC7786GatewaySource, IERC7786Receiver, Ownable,
199196
// if already executed, leave gracefully
200197
if (tracker.executed) return IERC7786Receiver.executeMessage.selector;
201198
} else if (tracker.executed) {
202-
revert ERC7786AggregatorAlreadyExecuted();
199+
revert ERC7786OpenBridgeAlreadyExecuted();
203200
}
204201

205202
// Parse payload
@@ -230,7 +227,7 @@ contract ERC7786Aggregator is IERC7786GatewaySource, IERC7786Receiver, Ownable,
230227
emit ExecutionSuccess(id);
231228
} else {
232229
// call successful but invalid value returned, we need to revert the subcall
233-
revert ERC7786AggregatorInvalidExecutionReturnValue();
230+
revert ERC7786OpenBridgeInvalidExecutionReturnValue();
234231
}
235232
}
236233

@@ -247,17 +244,14 @@ contract ERC7786Aggregator is IERC7786GatewaySource, IERC7786Receiver, Ownable,
247244
return _threshold;
248245
}
249246

250-
function getRemoteAggregator(bytes memory chain) public view virtual returns (bytes memory) {
247+
function getRemoteBridge(bytes memory chain) public view virtual returns (bytes memory) {
251248
(bytes2 chainType, bytes memory chainReference, ) = chain.parseV1();
252-
return getRemoteAggregator(chainType, chainReference);
249+
return getRemoteBridge(chainType, chainReference);
253250
}
254251

255-
function getRemoteAggregator(
256-
bytes2 chainType,
257-
bytes memory chainReference
258-
) public view virtual returns (bytes memory) {
252+
function getRemoteBridge(bytes2 chainType, bytes memory chainReference) public view virtual returns (bytes memory) {
259253
bytes memory addr = _remotes[chainType][chainReference];
260-
require(bytes(addr).length != 0, ERC7786AggregatorRemoteNotRegistered(chainType, chainReference));
254+
require(bytes(addr).length != 0, ERC7786OpenBridgeRemoteNotRegistered(chainType, chainReference));
261255
return InteroperableAddress.formatV1(chainType, chainReference, addr);
262256
}
263257

@@ -275,8 +269,8 @@ contract ERC7786Aggregator is IERC7786GatewaySource, IERC7786Receiver, Ownable,
275269
_setThreshold(newThreshold);
276270
}
277271

278-
function registerRemoteAggregator(bytes calldata aggregator) public virtual onlyOwner {
279-
_registerRemoteAggregator(aggregator);
272+
function registerRemoteBridge(bytes calldata bridge) public virtual onlyOwner {
273+
_registerRemoteBridge(bridge);
280274
}
281275

282276
function pause() public virtual onlyOwner {
@@ -295,25 +289,25 @@ contract ERC7786Aggregator is IERC7786GatewaySource, IERC7786Receiver, Ownable,
295289
// ================================================== Internal ===================================================
296290

297291
function _addGateway(address gateway) internal virtual {
298-
require(_gateways.add(gateway), ERC7786AggregatorGatewayAlreadyRegistered(gateway));
292+
require(_gateways.add(gateway), ERC7786OpenBridgeGatewayAlreadyRegistered(gateway));
299293
emit GatewayAdded(gateway);
300294
}
301295

302296
function _removeGateway(address gateway) internal virtual {
303-
require(_gateways.remove(gateway), ERC7786AggregatorGatewayNotRegistered(gateway));
304-
require(_threshold <= _gateways.length(), ERC7786AggregatorThresholdViolation());
297+
require(_gateways.remove(gateway), ERC7786OpenBridgeGatewayNotRegistered(gateway));
298+
require(_threshold <= _gateways.length(), ERC7786OpenBridgeThresholdViolation());
305299
emit GatewayRemoved(gateway);
306300
}
307301

308302
function _setThreshold(uint8 newThreshold) internal virtual {
309-
require(newThreshold > 0 && newThreshold <= _gateways.length(), ERC7786AggregatorThresholdViolation());
303+
require(newThreshold > 0 && newThreshold <= _gateways.length(), ERC7786OpenBridgeThresholdViolation());
310304
_threshold = newThreshold;
311305
emit ThresholdUpdated(newThreshold);
312306
}
313307

314-
function _registerRemoteAggregator(bytes calldata aggregator) internal virtual {
315-
(bytes2 chainType, bytes calldata chainReference, bytes calldata addr) = aggregator.parseV1Calldata();
308+
function _registerRemoteBridge(bytes calldata bridge) internal virtual {
309+
(bytes2 chainType, bytes calldata chainReference, bytes calldata addr) = bridge.parseV1Calldata();
316310
_remotes[chainType][chainReference] = addr;
317-
emit RemoteRegistered(aggregator);
311+
emit RemoteRegistered(bridge);
318312
}
319313
}

contracts/crosschain/README.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ NOTE: This document is better viewed at https://docs.openzeppelin.com/community-
66
Gateways are contracts that enable cross-chain communication. These can either be a message source or a destination according to ERC-7786.
77

88
* {ERC7786Receiver}: ERC-7786 cross-chain message receiver.
9-
* {ERC7786Aggregator}: ERC-7786 "N out of M" gateway. Sends a message through M gateways and executes on the destination if N received it.
9+
* {ERC7786OpenBridge}: ERC-7786 "N out of M" gateway. Sends a message through M gateways and executes on the destination if N received it.
1010

1111
Developers can access interoperability protocols through gateway adapters. The library includes the following gateway adapters:
1212

@@ -17,7 +17,7 @@ Developers can access interoperability protocols through gateway adapters. The l
1717

1818
== Gateways
1919

20-
{{ERC7786Aggregator}}
20+
{{ERC7786OpenBridge}}
2121

2222
== Clients
2323

docs/modules/ROOT/pages/crosschain.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ For a destination gateway, the library provides an adapter of the `AxelarExecuta
8484
include::api:example$crosschain/MyCustomAxelarGatewayDestination.sol[]
8585
----
8686

87-
=== Multi Bridge Aggregator
87+
=== Open Bridge
8888

89-
The xref:api:crosschain.adoc#ERC7786Aggregator[ERC7786Aggregator] is a special gateway that implements both xref:api:crosschain.adoc#IERC7786GatewaySource[IERC7786GatewaySource] and xref:api:crosschain.adoc#IERC7786Receiver[IERC7786Receiver] interfaces. It provides a way to send messages across multiple bridges simultaneously and ensures message delivery through a threshold-based confirmation system.
89+
The xref:api:crosschain.adoc#ERC7786OpenBridge[ERC7786OpenBridge] is a special gateway that implements both xref:api:crosschain.adoc#IERC7786GatewaySource[IERC7786GatewaySource] and xref:api:crosschain.adoc#IERC7786Receiver[IERC7786Receiver] interfaces. It provides a way to send messages across multiple bridges simultaneously and ensures message delivery through a threshold-based confirmation system.
9090

91-
The aggregator maintains a list of known gateways and a confirmation threshold. When sending a message, it broadcasts to all registered gateways, and when receiving, it requires a minimum number of confirmations before executing the message. This approach increases reliability by ensuring messages are properly delivered and validated across multiple bridges.
91+
The bridge maintains a list of known gateways and a confirmation threshold. When sending a message, it broadcasts to all registered gateways, and when receiving, it requires a minimum number of confirmations before executing the message. This approach increases reliability by ensuring messages are properly delivered and validated across multiple bridges.
9292

93-
When sending a message, the aggregator tracks the message IDs from each gateway to maintain a record of the message's journey across different bridges:
93+
When sending a message, the bridge tracks the message IDs from each gateway to maintain a record of the message's journey across different bridges:
9494

9595
```solidity
9696
function sendMessage(
@@ -110,7 +110,7 @@ function sendMessage(
110110
// send message
111111
bytes32 id = IERC7786GatewaySource(gateway).sendMessage(
112112
destinationChain,
113-
aggregator,
113+
bridge,
114114
wrappedPayload,
115115
attributes
116116
);
@@ -125,7 +125,7 @@ function sendMessage(
125125
}
126126
```
127127

128-
On the receiving end, the aggregator implements a threshold-based confirmation system. Messages are only executed after receiving enough confirmations from the gateways, ensuring message validity and preventing double execution. The xref:api:crosschain.adoc#ERC7786Aggregator-executeMessage-string-string-string-bytes-bytes---[`executeMessage`] function handles this process:
128+
On the receiving end, the bridge implements a threshold-based confirmation system. Messages are only executed after receiving enough confirmations from the gateways, ensuring message validity and preventing double execution. The xref:api:crosschain.adoc#ERC7786OpenBridge-executeMessage-string-string-string-bytes-bytes---[`executeMessage`] function handles this process:
129129

130130
```solidity
131131
function executeMessage(
@@ -148,7 +148,7 @@ function executeMessage(
148148
// if already executed, leave gracefully
149149
if (tracker.executed) return IERC7786Receiver.executeMessage.selector;
150150
} else if (tracker.executed) {
151-
revert ERC7786AggregatorAlreadyExecuted();
151+
revert ERC7786OpenBridgeAlreadyExecuted();
152152
}
153153

154154
// ... Validate sender and prepare payload for execution ...
@@ -173,4 +173,4 @@ function executeMessage(
173173
}
174174
```
175175

176-
The aggregator is designed to be configurable. As an `Ownable` contract, it allows the owner to manage the list of trusted gateways and adjust the confirmation threshold. The `_gateways` list and threshold are initially set during contract deployment using the xref:api:crosschain.adoc#ERC7786Aggregator-_addGateway-address-[`++_addGateway++`] and xref:api:crosschain.adoc#ERC7786Aggregator-_setThreshold-uint8-[`++_setThreshold++`] functions. The owner can update these settings as needed to adapt to changing requirements or add new gateways.
176+
The bridge is designed to be configurable. As an `Ownable` contract, it allows the owner to manage the list of trusted gateways and adjust the confirmation threshold. The `_gateways` list and threshold are initially set during contract deployment using the xref:api:crosschain.adoc#ERC7786OpenBridge-_addGateway-address-[`++_addGateway++`] and xref:api:crosschain.adoc#ERC7786OpenBridge-_setThreshold-uint8-[`++_setThreshold++`] functions. The owner can update these settings as needed to adapt to changing requirements or add new gateways.

0 commit comments

Comments
 (0)