Skip to content

Commit

Permalink
Merge pull request #51 from Moonsong-Labs/feat/zksync
Browse files Browse the repository at this point in the history
fix: compatibility with zkSync
  • Loading branch information
sendra authored May 21, 2024
2 parents 85e557b + 93733c0 commit ba9ce98
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 234 deletions.
4 changes: 4 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@ celo={key="${ETHERSCAN_API_KEY_CELO}", chain=42220, utl='https://api.celoscan.io
celo-testnet={key="${ETHERSCAN_API_KEY_CELO}", chain=44787, url='https://api-alfajores.celoscan.io/api'}

# See more config options https://github.com/gakonst/foundry/tree/master/config
[fuzz]
no_zksync_reserved_addresses = true
[invariant]
no_zksync_reserved_addresses = true
14 changes: 7 additions & 7 deletions tests/BaseCrossChainController.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {Errors} from '../src/contracts/libs/Errors.sol';
import {IBaseAdapter} from '../src/contracts/adapters/IBaseAdapter.sol';

abstract contract BaseCrossChainControllerTest is Test {
address public constant OWNER = address(123);
address public constant GUARDIAN = address(1234);
address public constant BRIDGE_ADAPTER = address(123456);
address public constant OWNER = address(65536 + 123);
address public constant GUARDIAN = address(65536 + 1234);
address public constant BRIDGE_ADAPTER = address(65536 + 123456);

uint8 public constant CONFIRMATIONS = 1;

Expand Down Expand Up @@ -76,21 +76,21 @@ abstract contract BaseCrossChainControllerTest is Test {

// forwarder configs
address[] memory sendersToApprove = new address[](1);
sendersToApprove[0] = address(102);
sendersToApprove[0] = address(65536 + 102);
ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[]
memory forwarderBridgeAdaptersToEnable = new ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[](
1
);
forwarderBridgeAdaptersToEnable[0] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
currentChainBridgeAdapter: address(103),
destinationBridgeAdapter: address(110),
currentChainBridgeAdapter: address(65536 + 103),
destinationBridgeAdapter: address(65536 + 110),
destinationChainId: ChainIds.POLYGON
});

crossChainControllerImpl = _deployControllerImplementation();

vm.mockCall(
address(103),
address(65536 + 103),
abi.encodeWithSelector(IBaseAdapter.setupPayments.selector),
abi.encode()
);
Expand Down
48 changes: 24 additions & 24 deletions tests/CrossChainControllerWithEmergencyMode.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ICLEmergencyOracle} from '../src/contracts/emergency/interfaces/ICLEmerg
import {CrossChainControllerWithEmergencyMode, ICrossChainControllerWithEmergencyMode} from '../src/contracts/CrossChainControllerWithEmergencyMode.sol';

contract CrossChainControllerWithEmergencyModeTest is BaseCrossChainControllerTest {
address public constant CL_EMERGENCY_ORACLE = address(12345);
address public constant CL_EMERGENCY_ORACLE = address(65536 + 12345);
event CLEmergencyOracleUpdated(address indexed newChainlinkEmergencyOracle);

function _deployControllerImplementation() internal override returns (address) {
Expand Down Expand Up @@ -55,14 +55,14 @@ contract CrossChainControllerWithEmergencyModeTest is BaseCrossChainControllerTe

// forwarder configs
address[] memory sendersToApprove = new address[](1);
sendersToApprove[0] = address(102);
sendersToApprove[0] = address(65536 + 102);
ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[]
memory forwarderBridgeAdaptersToEnable = new ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[](
1
);
forwarderBridgeAdaptersToEnable[0] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
currentChainBridgeAdapter: address(103),
destinationBridgeAdapter: address(110),
currentChainBridgeAdapter: address(65536 + 103),
destinationBridgeAdapter: address(65536 + 110),
destinationChainId: ChainIds.POLYGON
});

Expand Down Expand Up @@ -101,7 +101,7 @@ contract CrossChainControllerWithEmergencyModeTest is BaseCrossChainControllerTe
1
);
receiverBridgeAdaptersToAllow[0] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
bridgeAdapter: address(201),
bridgeAdapter: address(65536 + 201),
chainIds: originChainIds
});
uint8 newConfirmation = 1;
Expand Down Expand Up @@ -131,16 +131,16 @@ contract CrossChainControllerWithEmergencyModeTest is BaseCrossChainControllerTe

// forwarder config
address[] memory sendersToApprove = new address[](1);
sendersToApprove[0] = address(202);
sendersToApprove[0] = address(65536 + 202);
address[] memory sendersToRemove = new address[](1);
sendersToRemove[0] = address(102);
sendersToRemove[0] = address(65536 + 102);
ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[]
memory forwarderBridgeAdaptersToEnable = new ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[](
1
);
forwarderBridgeAdaptersToEnable[0] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
currentChainBridgeAdapter: address(203),
destinationBridgeAdapter: address(210),
currentChainBridgeAdapter: address(65536 + 203),
destinationBridgeAdapter: address(65536 + 210),
destinationChainId: ChainIds.POLYGON
});
ICrossChainForwarder.BridgeAdapterToDisable[]
Expand All @@ -150,7 +150,7 @@ contract CrossChainControllerWithEmergencyModeTest is BaseCrossChainControllerTe
uint256[] memory chainIds = new uint256[](1);
chainIds[0] = ChainIds.POLYGON;
forwarderBridgeAdaptersToDisable[0] = ICrossChainForwarder.BridgeAdapterToDisable({
bridgeAdapter: address(103),
bridgeAdapter: address(65536 + 103),
chainIds: chainIds
});

Expand All @@ -163,7 +163,7 @@ contract CrossChainControllerWithEmergencyModeTest is BaseCrossChainControllerTe
abi.encode(uint80(0), int256(1), 0, 0, uint80(0))
);
vm.mockCall(
address(203),
address(65536 + 203),
abi.encodeWithSelector(IBaseAdapter.setupPayments.selector),
abi.encode()
);
Expand All @@ -183,22 +183,22 @@ contract CrossChainControllerWithEmergencyModeTest is BaseCrossChainControllerTe
assertEq(receiverConfig.requiredConfirmation, newConfirmation);
assertEq(receiverConfig.validityTimestamp, newValidityTimestamp);
assertEq(
crossChainController.isReceiverBridgeAdapterAllowed(address(201), ChainIds.ETHEREUM),
crossChainController.isReceiverBridgeAdapterAllowed(address(65536 + 201), ChainIds.ETHEREUM),
true
);
assertEq(
crossChainController.isReceiverBridgeAdapterAllowed(BRIDGE_ADAPTER, ChainIds.ETHEREUM),
false
);
assertEq(crossChainController.isSenderApproved(address(202)), true);
assertEq(crossChainController.isSenderApproved(address(102)), false);
assertEq(crossChainController.isSenderApproved(address(65536 + 202)), true);
assertEq(crossChainController.isSenderApproved(address(65536 + 102)), false);

ICrossChainForwarder.ChainIdBridgeConfig[] memory forwarderBridgeAdapters = crossChainController
.getForwarderBridgeAdaptersByChain(ChainIds.POLYGON);

assertEq(forwarderBridgeAdapters.length, 1);
assertEq(forwarderBridgeAdapters[0].destinationBridgeAdapter, address(210));
assertEq(forwarderBridgeAdapters[0].currentChainBridgeAdapter, address(203));
assertEq(forwarderBridgeAdapters[0].destinationBridgeAdapter, address(65536 + 210));
assertEq(forwarderBridgeAdapters[0].currentChainBridgeAdapter, address(65536 + 203));
}

function testSolveEmergencyWhenUnreachableConfirmations() public {
Expand All @@ -210,7 +210,7 @@ contract CrossChainControllerWithEmergencyModeTest is BaseCrossChainControllerTe
1
);
receiverBridgeAdaptersToAllow[0] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
bridgeAdapter: address(201),
bridgeAdapter: address(65536 + 201),
chainIds: originChainIds
});
uint8 newConfirmation = 3;
Expand Down Expand Up @@ -240,16 +240,16 @@ contract CrossChainControllerWithEmergencyModeTest is BaseCrossChainControllerTe

// forwarder config
address[] memory sendersToApprove = new address[](1);
sendersToApprove[0] = address(202);
sendersToApprove[0] = address(65536 + 202);
address[] memory sendersToRemove = new address[](1);
sendersToRemove[0] = address(102);
sendersToRemove[0] = address(65536 + 102);
ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[]
memory forwarderBridgeAdaptersToEnable = new ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[](
1
);
forwarderBridgeAdaptersToEnable[0] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
currentChainBridgeAdapter: address(203),
destinationBridgeAdapter: address(210),
currentChainBridgeAdapter: address(65536 + 203),
destinationBridgeAdapter: address(65536 + 210),
destinationChainId: ChainIds.POLYGON
});
ICrossChainForwarder.BridgeAdapterToDisable[]
Expand All @@ -259,7 +259,7 @@ contract CrossChainControllerWithEmergencyModeTest is BaseCrossChainControllerTe
uint256[] memory chainIds = new uint256[](1);
chainIds[0] = ChainIds.POLYGON;
forwarderBridgeAdaptersToDisable[0] = ICrossChainForwarder.BridgeAdapterToDisable({
bridgeAdapter: address(103),
bridgeAdapter: address(65536 + 103),
chainIds: chainIds
});

Expand Down Expand Up @@ -323,7 +323,7 @@ contract CrossChainControllerWithEmergencyModeTest is BaseCrossChainControllerTe
}

function testUpdateCLEmergencyOracle() public {
address newChainlinkEmergencyOracle = address(101);
address newChainlinkEmergencyOracle = address(65536 + 101);

hoax(OWNER);
vm.expectEmit(true, false, false, true);
Expand All @@ -340,7 +340,7 @@ contract CrossChainControllerWithEmergencyModeTest is BaseCrossChainControllerTe
}

function testUpdateCLEmergencyOracleWhenNotOwner() public {
address newChainlinkEmergencyOracle = address(101);
address newChainlinkEmergencyOracle = address(65536 + 101);

vm.expectRevert(bytes('Ownable: caller is not the owner'));
ICrossChainControllerWithEmergencyMode(address(crossChainController)).updateCLEmergencyOracle(
Expand Down
16 changes: 8 additions & 8 deletions tests/CrossChainForwarder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {Transaction, EncodedTransaction, Envelope} from '../src/contracts/libs/E
import {BaseTest} from './BaseTest.sol';

contract CrossChainForwarderTest is BaseTest {
address public constant OWNER = address(123);
address public constant GUARDIAN = address(12);
address public constant OWNER = address(65536 + 123);
address public constant GUARDIAN = address(65536 + 12);
// mock addresses
address public constant DESTINATION_BRIDGE_ADAPTER = address(12345);
address public constant DESTINATION_BRIDGE_ADAPTER = address(65536 + 12345);
address public constant SENDER = address(123456);

uint256 public constant ORIGIN_LZ_CHAIN_ID = ChainIds.ETHEREUM;
Expand Down Expand Up @@ -186,9 +186,9 @@ contract CrossChainForwarderTest is BaseTest {
3
);

address NEW_BRIDGE_ADAPTER_1 = address(201);
address NEW_BRIDGE_ADAPTER_2 = address(202);
address NEW_DESTINATION_BRIDGE_ADAPTER_A = address(203);
address NEW_BRIDGE_ADAPTER_1 = address(65536 + 201);
address NEW_BRIDGE_ADAPTER_2 = address(65536 + 202);
address NEW_DESTINATION_BRIDGE_ADAPTER_A = address(65536 + 203);

// this one overwrites
newBridgeAdaptersToEnable[0] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
Expand Down Expand Up @@ -327,8 +327,8 @@ contract CrossChainForwarderTest is BaseTest {
2
);

address NEW_BRIDGE_ADAPTER_1 = address(201);
address NEW_DESTINATION_BRIDGE_ADAPTER_A = address(203);
address NEW_BRIDGE_ADAPTER_1 = address(65536 + 201);
address NEW_DESTINATION_BRIDGE_ADAPTER_A = address(65536 + 203);

// new one on same network
newBridgeAdaptersToEnable[0] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
Expand Down
14 changes: 7 additions & 7 deletions tests/CrossChainReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import {BaseTest} from './BaseTest.sol';
import {Transaction, Envelope} from '../src/contracts/libs/EncodingUtils.sol';

contract CrossChainReceiverTest is BaseTest {
address public constant GUARDIAN = address(12);
address public constant OWNER = address(123);
address public constant BRIDGE_ADAPTER = address(1234);
address public constant BRIDGE_ADAPTER_2 = address(1234567);
address public constant GUARDIAN = address(65536 + 12);
address public constant OWNER = address(65536 + 123);
address public constant BRIDGE_ADAPTER = address(65536 + 1234);
address public constant BRIDGE_ADAPTER_2 = address(65536 + 1234567);

address public constant GOVERNANCE_CORE = address(12345);
address public constant VOTING_MACHINE = address(123456);
address public constant GOVERNANCE_CORE = address(65536 + 12345);
address public constant VOTING_MACHINE = address(65536 + 123456);
uint256 public constant DEFAULT_ORIGIN_CHAIN_ID = 1;

ICrossChainReceiver public crossChainReceiver;
Expand Down Expand Up @@ -370,7 +370,7 @@ contract CrossChainReceiverTest is BaseTest {
assertEq(crossChainReceiver.isReceiverBridgeAdapterAllowed(BRIDGE_ADAPTER, 137), true);
}

// // TEST RECEIVE MESSAGES
// TEST RECEIVE MESSAGES
function testReceiveCrossChainMessage(uint256 txNonce, uint256 envelopeNonce) public {
ExtendedTransaction memory txExtended = _generateExtendedTransaction(
TestParams({
Expand Down
1 change: 1 addition & 0 deletions tests/Forwarder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ contract ForwarderTest is BaseCCForwarderTest {
validateTransactionNonceIncrement
validateTransactionRegistry(extendedTx)
{
_mockAdaptersForwardMessage(extendedTx.envelope.destinationChainId);
UsedAdapter[] memory usedAdapters = _currentlyUsedAdaptersByChain[
extendedTx.envelope.destinationChainId
];
Expand Down
Loading

0 comments on commit ba9ce98

Please sign in to comment.