Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utilities for CrossChain messaging #3183

Merged
merged 42 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
07aa7b9
move ICompoundTimelock to a vendor/compound
Amxx Feb 10, 2022
f6e286b
add CrossChainEnabled and support for some chains
Amxx Feb 10, 2022
36d479a
add missing dependencies
Amxx Feb 10, 2022
23b82b7
web3js and ethers testing + lint
Amxx Feb 10, 2022
b98fae5
testing AccessControlCrossChain
Amxx Feb 14, 2022
3ee00b6
fix lint
Amxx Feb 14, 2022
670f597
don't run slither on the mocks
Amxx Feb 14, 2022
5ed8f33
refactor testing
Amxx Feb 14, 2022
5eaab89
add CrossChainEnabledPolygonChild
Amxx Feb 16, 2022
03294aa
add polygon child testing
Amxx Feb 16, 2022
80ec9e2
rename params for clarity
Amxx Feb 22, 2022
9faf612
add CrossChain documentation
Amxx Feb 24, 2022
0f6e613
Merge branch 'master' into feature/crosschain
Amxx Feb 24, 2022
4928727
fix spelling
Amxx Feb 24, 2022
27c18a5
remove ethers.js version of crosschain testing
Amxx Feb 24, 2022
be3543a
remove ethers/waffle dependencies
Amxx Feb 24, 2022
3b3cd58
add link to optimism bridges deployments
Amxx Feb 25, 2022
2313a06
Merge branch 'master' into feature/crosschain
frangio Mar 22, 2022
d9f6513
reset lockfile
frangio Mar 22, 2022
147528b
Apply suggestions from code review
Amxx Mar 23, 2022
4ebb13d
wording
Amxx Mar 23, 2022
2260e5a
Merge remote-tracking branch 'Amxx/feature/crosschain' into feature/c…
Amxx Mar 23, 2022
e73d815
fix lint
Amxx Mar 23, 2022
b300b6b
check custom error
Amxx Mar 23, 2022
5e1dfa2
add reverts to crossChainSender if call is not crosschain
Amxx Mar 24, 2022
ab77189
add custom error check
Amxx Mar 24, 2022
b2a4418
bump required solidity version
Amxx Mar 24, 2022
afb52f1
fix inconsistency in tests
Amxx Mar 25, 2022
6ac95cd
improve custom error detection
Amxx Mar 25, 2022
345a9b0
expect rewrite
Amxx Mar 25, 2022
bc2b083
sometimes the linter is not really smart
Amxx Mar 25, 2022
69cdf15
revert to simpler error detection
Amxx Mar 25, 2022
41cd634
add changelog entry
frangio Mar 28, 2022
1d4c86d
add customError helper
Amxx Mar 29, 2022
19752c8
Merge branch 'master' into feature/crosschain
Amxx Mar 29, 2022
1252614
add PR link in changelog entry
Amxx Mar 29, 2022
10acf59
print full revert string if customError detection fails
Amxx Mar 29, 2022
c1f0793
use bridge address instead of inbox for arbitrumL1
Amxx Mar 29, 2022
5ea8297
remove console.error
frangio Mar 29, 2022
04f4629
avoid mutating a dependency
frangio Mar 29, 2022
b0e9cdb
refactor crosschain helper to avoid global state
frangio Mar 29, 2022
cc2dd04
fix custom error tests when optimizations are on
frangio Mar 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use bridge address instead of inbox for arbitrumL1
  • Loading branch information
Amxx committed Mar 29, 2022
commit c1f0793c1d0169cf4b239dc1b045b01af0367a47
14 changes: 7 additions & 7 deletions contracts/crosschain/arbitrum/CrossChainEnabledArbitrumL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@ import "./LibArbitrumL1.sol";
* This version should only be deployed on L1 to process cross-chain messages
* originating from L2. For the other side, use {CrossChainEnabledArbitrumL2}.
*
* The inbox contract is provided and maintained by the arbitrum team. You can
* The bridge contract is provided and maintained by the arbitrum team. You can
* find the address of this contract on the rinkeby testnet in
* [Arbitrum's developer documentation](https://developer.offchainlabs.com/docs/public_testnet#l1).
* [Arbitrum's developer documentation](https://developer.offchainlabs.com/docs/useful_addresses).
*
* _Available since v4.6._
*/
abstract contract CrossChainEnabledArbitrumL1 is CrossChainEnabled {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address private immutable _inbox;
address private immutable _bridge;

/// @custom:oz-upgrades-unsafe-allow constructor
constructor(address inbox) {
_inbox = inbox;
constructor(address bridge) {
_bridge = bridge;
}

/**
* @dev see {CrossChainEnabled-_isCrossChain}
*/
function _isCrossChain() internal view virtual override returns (bool) {
return LibArbitrumL1.isCrossChain(_inbox);
return LibArbitrumL1.isCrossChain(_bridge);
}

/**
* @dev see {CrossChainEnabled-_crossChainSender}
*/
function _crossChainSender() internal view virtual override onlyCrossChain returns (address) {
return LibArbitrumL1.crossChainSender(_inbox);
return LibArbitrumL1.crossChainSender(_bridge);
}
}
15 changes: 7 additions & 8 deletions contracts/crosschain/arbitrum/LibArbitrumL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,24 @@ import "../errors.sol";
library LibArbitrumL1 {
/**
* @dev Returns whether the current function call is the result of a
* cross-chain message relayed by the bridge attached to `inbox`.
* cross-chain message relayed by the `bridge`.
*/
function isCrossChain(address inbox) internal view returns (bool) {
return msg.sender == ArbitrumL1_Inbox(inbox).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 attached to `inbox`.
* 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 inbox) internal view returns (address) {
if (!isCrossChain(inbox)) revert NotCrossChainCall();
function crossChainSender(address bridge) internal view returns (address) {
if (!isCrossChain(bridge)) revert NotCrossChainCall();

address sender = ArbitrumL1_Outbox(ArbitrumL1_Bridge(ArbitrumL1_Inbox(inbox).bridge()).activeOutbox())
.l2ToL1Sender();
address sender = ArbitrumL1_Outbox(ArbitrumL1_Bridge(bridge).activeOutbox()).l2ToL1Sender();
require(sender != address(0), "LibArbitrumL1: system messages without sender");

return sender;
Expand Down
2 changes: 1 addition & 1 deletion test/crosschain/CrossChainEnabled.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contract('CrossChainEnabled', function () {
CrossChainHelper.before('Arbitrum-L1');

beforeEach(async function () {
this.receiver = await CrossChainEnabledArbitrumL1Mock.new(await CrossChainHelper.bridge.inbox());
this.receiver = await CrossChainEnabledArbitrumL1Mock.new(CrossChainHelper.bridge.address);
});

shouldBehaveLikeReceiver();
Expand Down