ERC7786OpenBridgeLib
Title: ERC7786OpenBridgeLib
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Adapted for EIP-2535 from OpenZeppelin community-contracts ERC7786OpenBridge (https://github.com/OpenZeppelin/openzeppelin-community-contracts, commit f7e5f08).
N-of-M ERC-7786 aggregator: sendMessage fans a wrapped message out across M gateways;
receiveMessage counts independent gateway attestations and delivers to the recipient once N
agree (retry-on-failure, executed-flag reentrancy guard). Both a source gateway and a recipient.
Functions
erc7786OpenBridgeStorage
function erc7786OpenBridgeStorage() internal pure returns (ERC7786OpenBridgeStorage storage $);Returns
| Name | Type | Description |
|---|---|---|
| $ | ERC7786OpenBridgeStorage |
__ERC7786OpenBridge_init
Registers the shared IERC7786GatewaySource ERC-165 interface.
function __ERC7786OpenBridge_init() internal;registerInterface
Writes true to the SHARED IERC7786GatewaySource ERC-165 map slot (0x11967553 → ...).
function registerInterface() internal;getGateways
function getGateways() internal view returns (address[] memory);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address[] |
getThreshold
function getThreshold() internal view returns (uint8);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint8 |
getRemoteBridge
function getRemoteBridge(bytes memory chain) internal view returns (bytes memory);Parameters
| Name | Type | Description |
|---|---|---|
| chain | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes |
minDirectCoverage
function minDirectCoverage() internal view returns (uint8);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint8 |
supportsAttribute
function supportsAttribute(bytes4) internal pure returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| _ | bytes4 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
addGateway
function addGateway(address gateway) internal;Parameters
| Name | Type | Description |
|---|---|---|
| gateway | address |
removeGateway
function removeGateway(address gateway) internal;Parameters
| Name | Type | Description |
|---|---|---|
| gateway | address |
setThreshold
function setThreshold(uint8 threshold) internal;Parameters
| Name | Type | Description |
|---|---|---|
| threshold | uint8 |
setMinDirectCoverage
Sets the M-of-N coverage-awareness knob (issue #77 Q5): when non-zero, sendMessage refuses destinations whose DIRECT registry coverage is below it (set 2+ to hard-refuse M=1 routes; 0 — the default — disables the check entirely, so a diamond without a chain registry keeps working).
function setMinDirectCoverage(uint8 minDirectCoverage_) internal;Parameters
| Name | Type | Description |
|---|---|---|
| minDirectCoverage_ | uint8 |
registerRemoteBridge
Registers the matching remote bridge for its chain. Reverts with ThresholdViolation while the
threshold is still 0, forcing the safe configuration order: gateways, then threshold, then remotes.
function registerRemoteBridge(bytes calldata bridge) internal;Parameters
| Name | Type | Description |
|---|---|---|
| bridge | bytes |
sendMessage
ERC-7786 source: wraps the message and fans it out across all gateways to the matching
remote bridge. Rejects value + attributes. sendId = keccak of the per-gateway ids (or 0).
COVERAGE GATE (issue #77 Q5): when the admin has set _minDirectCoverage non-zero, the parsed
destination chain must have at least that many DIRECT (non-hub-routed) gateways recorded in the
chain registry — OpenBridgeInsufficientCoverage otherwise. The default 0 skips the registry
read entirely, so a diamond without a chain registry record (or facet) behaves exactly as before.
function sendMessage(bytes calldata recipient, bytes calldata payload, bytes[] calldata attributes)
internal
returns (bytes32 sendId);Parameters
| Name | Type | Description |
|---|---|---|
| recipient | bytes | |
| payload | bytes | |
| attributes | bytes[] |
Returns
| Name | Type | Description |
|---|---|---|
| sendId | bytes32 |
_resolveRemoteBridge
Parses the destination chain out of recipient ONCE, enforces the coverage gate on it, and
resolves the matching remote bridge (split into a helper to stay under the non-via-IR stack
limit — see sendMessage for the gate semantics).
function _resolveRemoteBridge(ERC7786OpenBridgeStorage storage $, bytes calldata recipient)
private
view
returns (bytes memory bridge);Parameters
| Name | Type | Description |
|---|---|---|
| $ | ERC7786OpenBridgeStorage | |
| recipient | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| bridge | bytes |
receiveMessage
ERC-7786 recipient: count an attesting gateway and, once the N threshold is met, deliver the unwrapped message to the final recipient. Idempotent per gateway; retryable on failure.
Never executes while the threshold is 0 (an unconfigured bridge): 0 >= 0 would otherwise let any
non-gateway caller deliver a forged payload. Gateway attestations are still recorded, so calling
again after setThreshold executes the message. Skips rather than reverts, so adapters that cannot
redeliver don't lose the attestation.
function receiveMessage(bytes32, bytes calldata sender, bytes calldata payload) internal returns (bytes4);Parameters
| Name | Type | Description |
|---|---|---|
| _ | bytes32 | |
| sender | bytes | |
| payload | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes4 |
_fanOut
Sends wrapped to every gateway addressed to bridge; returns keccak of the non-zero ids.
function _fanOut(
ERC7786OpenBridgeStorage storage $,
bytes memory bridge,
bytes memory wrapped,
bytes[] calldata attributes
) private returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| $ | ERC7786OpenBridgeStorage | |
| bridge | bytes | |
| wrapped | bytes | |
| attributes | bytes[] |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
_execute
Decodes the wrapped payload and delivers it. Sets executed BEFORE the call (reentrancy
guard); a failing recipient call rolls that back and leaves the message retryable.
function _execute(OpenBridgeTracker storage t, bytes32 id, bytes calldata payload) private;Parameters
| Name | Type | Description |
|---|---|---|
| t | OpenBridgeTracker | |
| id | bytes32 | |
| payload | bytes |