mirror of
https://github.com/th30d4y/OpenLearnX.git
synced 2026-05-26 19:26:33 +00:00
Fix .gitignore: stop tracking ignored files
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.6.0) (crosschain/CrossChainEnabled.sol)
|
||||
|
||||
pragma solidity ^0.8.4;
|
||||
|
||||
import "./errors.sol";
|
||||
|
||||
/**
|
||||
* @dev Provides information for building cross-chain aware contracts. This
|
||||
* abstract contract provides accessors and modifiers to control the execution
|
||||
* flow when receiving cross-chain messages.
|
||||
*
|
||||
* Actual implementations of cross-chain aware contracts, which are based on
|
||||
* this abstraction, will have to inherit from a bridge-specific
|
||||
* specialization. Such specializations are provided under
|
||||
* `crosschain/<chain>/CrossChainEnabled<chain>.sol`.
|
||||
*
|
||||
* _Available since v4.6._
|
||||
*/
|
||||
abstract contract CrossChainEnabled {
|
||||
/**
|
||||
* @dev Throws if the current function call is not the result of a
|
||||
* cross-chain execution.
|
||||
*/
|
||||
modifier onlyCrossChain() {
|
||||
if (!_isCrossChain()) revert NotCrossChainCall();
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Throws if the current function call is not the result of a
|
||||
* cross-chain execution initiated by `account`.
|
||||
*/
|
||||
modifier onlyCrossChainSender(address expected) {
|
||||
address actual = _crossChainSender();
|
||||
if (expected != actual) revert InvalidCrossChainSender(actual, expected);
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns whether the current function call is the result of a
|
||||
* cross-chain message.
|
||||
*/
|
||||
function _isCrossChain() internal view virtual returns (bool);
|
||||
|
||||
/**
|
||||
* @dev Returns the address of the sender of the cross-chain message that
|
||||
* triggered the current function call.
|
||||
*
|
||||
* IMPORTANT: Should revert with `NotCrossChainCall` if the current function
|
||||
* call is not the result of a cross-chain message.
|
||||
*/
|
||||
function _crossChainSender() internal view virtual returns (address);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
= Cross Chain Awareness
|
||||
|
||||
[.readme-notice]
|
||||
NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/crosschain
|
||||
|
||||
This directory provides building blocks to improve cross-chain awareness of smart contracts.
|
||||
|
||||
- {CrossChainEnabled} is an abstraction that contains accessors and modifiers to control the execution flow when receiving cross-chain messages.
|
||||
|
||||
== CrossChainEnabled specializations
|
||||
|
||||
The following specializations of {CrossChainEnabled} provide implementations of the {CrossChainEnabled} abstraction for specific bridges. This can be used to complex cross-chain aware components such as {AccessControlCrossChain}.
|
||||
|
||||
{{CrossChainEnabledAMB}}
|
||||
|
||||
{{CrossChainEnabledArbitrumL1}}
|
||||
|
||||
{{CrossChainEnabledArbitrumL2}}
|
||||
|
||||
{{CrossChainEnabledOptimism}}
|
||||
|
||||
{{CrossChainEnabledPolygonChild}}
|
||||
|
||||
== Libraries for cross-chain
|
||||
|
||||
In addition to the {CrossChainEnabled} abstraction, cross-chain awareness is also available through libraries. These libraries can be used to build complex designs such as contracts with the ability to interact with multiple bridges.
|
||||
|
||||
{{LibAMB}}
|
||||
|
||||
{{LibArbitrumL1}}
|
||||
|
||||
{{LibArbitrumL2}}
|
||||
|
||||
{{LibOptimism}}
|
||||
@@ -0,0 +1,49 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.7.0) (crosschain/amb/CrossChainEnabledAMB.sol)
|
||||
|
||||
pragma solidity ^0.8.4;
|
||||
|
||||
import "../CrossChainEnabled.sol";
|
||||
import "./LibAMB.sol";
|
||||
|
||||
/**
|
||||
* @dev https://docs.tokenbridge.net/amb-bridge/about-amb-bridge[AMB]
|
||||
* specialization or the {CrossChainEnabled} abstraction.
|
||||
*
|
||||
* As of february 2020, AMB bridges are available between the following chains:
|
||||
*
|
||||
* - https://docs.tokenbridge.net/eth-xdai-amb-bridge/about-the-eth-xdai-amb[ETH ⇌ xDai]
|
||||
* - https://docs.tokenbridge.net/eth-qdai-bridge/about-the-eth-qdai-amb[ETH ⇌ qDai]
|
||||
* - https://docs.tokenbridge.net/eth-etc-amb-bridge/about-the-eth-etc-amb[ETH ⇌ ETC]
|
||||
* - https://docs.tokenbridge.net/eth-bsc-amb/about-the-eth-bsc-amb[ETH ⇌ BSC]
|
||||
* - https://docs.tokenbridge.net/eth-poa-amb-bridge/about-the-eth-poa-amb[ETH ⇌ POA]
|
||||
* - https://docs.tokenbridge.net/bsc-xdai-amb/about-the-bsc-xdai-amb[BSC ⇌ xDai]
|
||||
* - https://docs.tokenbridge.net/poa-xdai-amb/about-the-poa-xdai-amb[POA ⇌ xDai]
|
||||
* - https://docs.tokenbridge.net/rinkeby-xdai-amb-bridge/about-the-rinkeby-xdai-amb[Rinkeby ⇌ xDai]
|
||||
* - https://docs.tokenbridge.net/kovan-sokol-amb-bridge/about-the-kovan-sokol-amb[Kovan ⇌ Sokol]
|
||||
*
|
||||
* _Available since v4.6._
|
||||
*/
|
||||
contract CrossChainEnabledAMB is CrossChainEnabled {
|
||||
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
||||
address private immutable _bridge;
|
||||
|
||||
/// @custom:oz-upgrades-unsafe-allow constructor
|
||||
constructor(address bridge) {
|
||||
_bridge = bridge;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev see {CrossChainEnabled-_isCrossChain}
|
||||
*/
|
||||
function _isCrossChain() internal view virtual override returns (bool) {
|
||||
return LibAMB.isCrossChain(_bridge);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev see {CrossChainEnabled-_crossChainSender}
|
||||
*/
|
||||
function _crossChainSender() internal view virtual override onlyCrossChain returns (address) {
|
||||
return LibAMB.crossChainSender(_bridge);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.7.0) (crosschain/amb/LibAMB.sol)
|
||||
|
||||
pragma solidity ^0.8.4;
|
||||
|
||||
import {IAMB as AMB_Bridge} from "../../vendor/amb/IAMB.sol";
|
||||
import "../errors.sol";
|
||||
|
||||
/**
|
||||
* @dev Primitives for cross-chain aware contracts using the
|
||||
* https://docs.tokenbridge.net/amb-bridge/about-amb-bridge[AMB]
|
||||
* family of bridges.
|
||||
*/
|
||||
library LibAMB {
|
||||
/**
|
||||
* @dev Returns whether the current function call is the result of a
|
||||
* cross-chain message relayed by `bridge`.
|
||||
*/
|
||||
function isCrossChain(address bridge) internal view returns (bool) {
|
||||
return msg.sender == bridge;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the address of the sender that triggered the current
|
||||
* cross-chain message through `bridge`.
|
||||
*
|
||||
* NOTE: {isCrossChain} should be checked before trying to recover the
|
||||
* sender, as it will revert with `NotCrossChainCall` if the current
|
||||
* function call is not the result of a cross-chain message.
|
||||
*/
|
||||
function crossChainSender(address bridge) internal view returns (address) {
|
||||
if (!isCrossChain(bridge)) revert NotCrossChainCall();
|
||||
return AMB_Bridge(bridge).messageSender();
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.7.0) (crosschain/arbitrum/CrossChainEnabledArbitrumL1.sol)
|
||||
|
||||
pragma solidity ^0.8.4;
|
||||
|
||||
import "../CrossChainEnabled.sol";
|
||||
import "./LibArbitrumL1.sol";
|
||||
|
||||
/**
|
||||
* @dev https://arbitrum.io/[Arbitrum] specialization or the
|
||||
* {CrossChainEnabled} abstraction the L1 side (mainnet).
|
||||
*
|
||||
* This version should only be deployed on L1 to process cross-chain messages
|
||||
* originating from L2. For the other side, use {CrossChainEnabledArbitrumL2}.
|
||||
*
|
||||
* The bridge contract is provided and maintained by the arbitrum team. You can
|
||||
* find the address of this contract on the rinkeby testnet in
|
||||
* https://developer.offchainlabs.com/docs/useful_addresses[Arbitrum's developer documentation].
|
||||
*
|
||||
* _Available since v4.6._
|
||||
*/
|
||||
abstract contract CrossChainEnabledArbitrumL1 is CrossChainEnabled {
|
||||
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
||||
address private immutable _bridge;
|
||||
|
||||
/// @custom:oz-upgrades-unsafe-allow constructor
|
||||
constructor(address bridge) {
|
||||
_bridge = bridge;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev see {CrossChainEnabled-_isCrossChain}
|
||||
*/
|
||||
function _isCrossChain() internal view virtual override returns (bool) {
|
||||
return LibArbitrumL1.isCrossChain(_bridge);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev see {CrossChainEnabled-_crossChainSender}
|
||||
*/
|
||||
function _crossChainSender() internal view virtual override onlyCrossChain returns (address) {
|
||||
return LibArbitrumL1.crossChainSender(_bridge);
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.8.0) (crosschain/arbitrum/CrossChainEnabledArbitrumL2.sol)
|
||||
|
||||
pragma solidity ^0.8.4;
|
||||
|
||||
import "../CrossChainEnabled.sol";
|
||||
import "./LibArbitrumL2.sol";
|
||||
|
||||
/**
|
||||
* @dev https://arbitrum.io/[Arbitrum] specialization or the
|
||||
* {CrossChainEnabled} abstraction the L2 side (arbitrum).
|
||||
*
|
||||
* This version should only be deployed on L2 to process cross-chain messages
|
||||
* originating from L1. For the other side, use {CrossChainEnabledArbitrumL1}.
|
||||
*
|
||||
* Arbitrum L2 includes the `ArbSys` contract at a fixed address. Therefore,
|
||||
* this specialization of {CrossChainEnabled} does not include a constructor.
|
||||
*
|
||||
* _Available since v4.6._
|
||||
*
|
||||
* WARNING: There is currently a bug in Arbitrum that causes this contract to
|
||||
* fail to detect cross-chain calls when deployed behind a proxy. This will be
|
||||
* fixed when the network is upgraded to Arbitrum Nitro, currently scheduled for
|
||||
* August 31st 2022.
|
||||
*/
|
||||
abstract contract CrossChainEnabledArbitrumL2 is CrossChainEnabled {
|
||||
/**
|
||||
* @dev see {CrossChainEnabled-_isCrossChain}
|
||||
*/
|
||||
function _isCrossChain() internal view virtual override returns (bool) {
|
||||
return LibArbitrumL2.isCrossChain(LibArbitrumL2.ARBSYS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev see {CrossChainEnabled-_crossChainSender}
|
||||
*/
|
||||
function _crossChainSender() internal view virtual override onlyCrossChain returns (address) {
|
||||
return LibArbitrumL2.crossChainSender(LibArbitrumL2.ARBSYS);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.8.0) (crosschain/arbitrum/LibArbitrumL1.sol)
|
||||
|
||||
pragma solidity ^0.8.4;
|
||||
|
||||
import {IBridge as ArbitrumL1_Bridge} from "../../vendor/arbitrum/IBridge.sol";
|
||||
import {IOutbox as ArbitrumL1_Outbox} from "../../vendor/arbitrum/IOutbox.sol";
|
||||
import "../errors.sol";
|
||||
|
||||
/**
|
||||
* @dev Primitives for cross-chain aware contracts for
|
||||
* https://arbitrum.io/[Arbitrum].
|
||||
*
|
||||
* This version should only be used on L1 to process cross-chain messages
|
||||
* originating from L2. For the other side, use {LibArbitrumL2}.
|
||||
*/
|
||||
library LibArbitrumL1 {
|
||||
/**
|
||||
* @dev Returns whether the current function call is the result of a
|
||||
* cross-chain message relayed by the `bridge`.
|
||||
*/
|
||||
function isCrossChain(address bridge) internal view returns (bool) {
|
||||
return msg.sender == bridge;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the address of the sender that triggered the current
|
||||
* cross-chain message through the `bridge`.
|
||||
*
|
||||
* NOTE: {isCrossChain} should be checked before trying to recover the
|
||||
* sender, as it will revert with `NotCrossChainCall` if the current
|
||||
* function call is not the result of a cross-chain message.
|
||||
*/
|
||||
function crossChainSender(address bridge) internal view returns (address) {
|
||||
if (!isCrossChain(bridge)) revert NotCrossChainCall();
|
||||
|
||||
address sender = ArbitrumL1_Outbox(ArbitrumL1_Bridge(bridge).activeOutbox()).l2ToL1Sender();
|
||||
require(sender != address(0), "LibArbitrumL1: system messages without sender");
|
||||
|
||||
return sender;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.8.0) (crosschain/arbitrum/LibArbitrumL2.sol)
|
||||
|
||||
pragma solidity ^0.8.4;
|
||||
|
||||
import {IArbSys as ArbitrumL2_Bridge} from "../../vendor/arbitrum/IArbSys.sol";
|
||||
import "../errors.sol";
|
||||
|
||||
/**
|
||||
* @dev Primitives for cross-chain aware contracts for
|
||||
* https://arbitrum.io/[Arbitrum].
|
||||
*
|
||||
* This version should only be used on L2 to process cross-chain messages
|
||||
* originating from L1. For the other side, use {LibArbitrumL1}.
|
||||
*
|
||||
* WARNING: There is currently a bug in Arbitrum that causes this contract to
|
||||
* fail to detect cross-chain calls when deployed behind a proxy. This will be
|
||||
* fixed when the network is upgraded to Arbitrum Nitro, currently scheduled for
|
||||
* August 31st 2022.
|
||||
*/
|
||||
library LibArbitrumL2 {
|
||||
/**
|
||||
* @dev Returns whether the current function call is the result of a
|
||||
* cross-chain message relayed by `arbsys`.
|
||||
*/
|
||||
address public constant ARBSYS = 0x0000000000000000000000000000000000000064;
|
||||
|
||||
function isCrossChain(address arbsys) internal view returns (bool) {
|
||||
return ArbitrumL2_Bridge(arbsys).wasMyCallersAddressAliased();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the address of the sender that triggered the current
|
||||
* cross-chain message through `arbsys`.
|
||||
*
|
||||
* NOTE: {isCrossChain} should be checked before trying to recover the
|
||||
* sender, as it will revert with `NotCrossChainCall` if the current
|
||||
* function call is not the result of a cross-chain message.
|
||||
*/
|
||||
function crossChainSender(address arbsys) internal view returns (address) {
|
||||
if (!isCrossChain(arbsys)) revert NotCrossChainCall();
|
||||
|
||||
return ArbitrumL2_Bridge(arbsys).myCallersAddressWithoutAliasing();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.6.0) (crosschain/errors.sol)
|
||||
|
||||
pragma solidity ^0.8.4;
|
||||
|
||||
error NotCrossChainCall();
|
||||
error InvalidCrossChainSender(address actual, address expected);
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.7.0) (crosschain/optimism/CrossChainEnabledOptimism.sol)
|
||||
|
||||
pragma solidity ^0.8.4;
|
||||
|
||||
import "../CrossChainEnabled.sol";
|
||||
import "./LibOptimism.sol";
|
||||
|
||||
/**
|
||||
* @dev https://www.optimism.io/[Optimism] specialization or the
|
||||
* {CrossChainEnabled} abstraction.
|
||||
*
|
||||
* The messenger (`CrossDomainMessenger`) contract is provided and maintained by
|
||||
* the optimism team. You can find the address of this contract on mainnet and
|
||||
* kovan in the https://github.com/ethereum-optimism/optimism/tree/develop/packages/contracts/deployments[deployments section of Optimism monorepo].
|
||||
*
|
||||
* _Available since v4.6._
|
||||
*/
|
||||
abstract contract CrossChainEnabledOptimism is CrossChainEnabled {
|
||||
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
||||
address private immutable _messenger;
|
||||
|
||||
/// @custom:oz-upgrades-unsafe-allow constructor
|
||||
constructor(address messenger) {
|
||||
_messenger = messenger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev see {CrossChainEnabled-_isCrossChain}
|
||||
*/
|
||||
function _isCrossChain() internal view virtual override returns (bool) {
|
||||
return LibOptimism.isCrossChain(_messenger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev see {CrossChainEnabled-_crossChainSender}
|
||||
*/
|
||||
function _crossChainSender() internal view virtual override onlyCrossChain returns (address) {
|
||||
return LibOptimism.crossChainSender(_messenger);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.7.0) (crosschain/optimism/LibOptimism.sol)
|
||||
|
||||
pragma solidity ^0.8.4;
|
||||
|
||||
import {ICrossDomainMessenger as Optimism_Bridge} from "../../vendor/optimism/ICrossDomainMessenger.sol";
|
||||
import "../errors.sol";
|
||||
|
||||
/**
|
||||
* @dev Primitives for cross-chain aware contracts for https://www.optimism.io/[Optimism].
|
||||
* See the https://community.optimism.io/docs/developers/bridge/messaging/#accessing-msg-sender[documentation]
|
||||
* for the functionality used here.
|
||||
*/
|
||||
library LibOptimism {
|
||||
/**
|
||||
* @dev Returns whether the current function call is the result of a
|
||||
* cross-chain message relayed by `messenger`.
|
||||
*/
|
||||
function isCrossChain(address messenger) internal view returns (bool) {
|
||||
return msg.sender == messenger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the address of the sender that triggered the current
|
||||
* cross-chain message through `messenger`.
|
||||
*
|
||||
* NOTE: {isCrossChain} should be checked before trying to recover the
|
||||
* sender, as it will revert with `NotCrossChainCall` if the current
|
||||
* function call is not the result of a cross-chain message.
|
||||
*/
|
||||
function crossChainSender(address messenger) internal view returns (address) {
|
||||
if (!isCrossChain(messenger)) revert NotCrossChainCall();
|
||||
|
||||
return Optimism_Bridge(messenger).xDomainMessageSender();
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.9.0) (crosschain/polygon/CrossChainEnabledPolygonChild.sol)
|
||||
|
||||
pragma solidity ^0.8.4;
|
||||
|
||||
import "../CrossChainEnabled.sol";
|
||||
import "../../security/ReentrancyGuard.sol";
|
||||
import "../../utils/Address.sol";
|
||||
import "../../vendor/polygon/IFxMessageProcessor.sol";
|
||||
|
||||
address constant DEFAULT_SENDER = 0x000000000000000000000000000000000000dEaD;
|
||||
|
||||
/**
|
||||
* @dev https://polygon.technology/[Polygon] specialization or the
|
||||
* {CrossChainEnabled} abstraction the child side (polygon/mumbai).
|
||||
*
|
||||
* This version should only be deployed on child chain to process cross-chain
|
||||
* messages originating from the parent chain.
|
||||
*
|
||||
* The fxChild contract is provided and maintained by the polygon team. You can
|
||||
* find the address of this contract polygon and mumbai in
|
||||
* https://docs.polygon.technology/docs/develop/l1-l2-communication/fx-portal/#contract-addresses[Polygon's Fx-Portal documentation].
|
||||
*
|
||||
* _Available since v4.6._
|
||||
*/
|
||||
abstract contract CrossChainEnabledPolygonChild is IFxMessageProcessor, CrossChainEnabled, ReentrancyGuard {
|
||||
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
||||
address private immutable _fxChild;
|
||||
address private _sender = DEFAULT_SENDER;
|
||||
|
||||
/// @custom:oz-upgrades-unsafe-allow constructor
|
||||
constructor(address fxChild) {
|
||||
_fxChild = fxChild;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev see {CrossChainEnabled-_isCrossChain}
|
||||
*/
|
||||
function _isCrossChain() internal view virtual override returns (bool) {
|
||||
return msg.sender == _fxChild;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev see {CrossChainEnabled-_crossChainSender}
|
||||
*/
|
||||
function _crossChainSender() internal view virtual override onlyCrossChain returns (address) {
|
||||
return _sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev External entry point to receive and relay messages originating
|
||||
* from the fxChild.
|
||||
*
|
||||
* Non-reentrancy is crucial to avoid a cross-chain call being able
|
||||
* to impersonate anyone by just looping through this with user-defined
|
||||
* arguments.
|
||||
*
|
||||
* Note: if _fxChild calls any other function that does a delegate-call,
|
||||
* then security could be compromised.
|
||||
*/
|
||||
function processMessageFromRoot(
|
||||
uint256 /* stateId */,
|
||||
address rootMessageSender,
|
||||
bytes calldata data
|
||||
) external override nonReentrant {
|
||||
if (!_isCrossChain()) revert NotCrossChainCall();
|
||||
|
||||
_sender = rootMessageSender;
|
||||
Address.functionDelegateCall(address(this), data, "cross-chain execution failed");
|
||||
_sender = DEFAULT_SENDER;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user