fix crosschainproxy

This commit is contained in:
Alexey 2021-10-05 12:08:04 +03:00
parent e7889c4010
commit a93caef5fa
5 changed files with 30 additions and 24 deletions

View File

@ -1,25 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import { IAMB } from "./interfaces/Bridge.sol";
import "@openzeppelin/contracts/contracts/proxy/TransparentUpgradeableProxy.sol";
// https://docs.tokenbridge.net/amb-bridge/development-of-a-cross-chain-application/how-to-develop-xchain-apps-by-amb#call-a-method-in-another-chain-using-the-amb-bridge
interface IAMB {
function messageSender() external view returns (address);
function messageSourceChainId() external view returns (bytes32);
}
interface IOmniBridge {
function bridgeContract() external view returns (IAMB);
}
/**
* @dev TransparentUpgradeableProxy where admin acts from a different chain.
*/
contract CrossChainUpgradeableProxy is TransparentUpgradeableProxy {
IOmniBridge public immutable omniBridge;
IAMB public immutable ambBridge;
bytes32 public immutable adminChainId;
/**
@ -29,10 +18,10 @@ contract CrossChainUpgradeableProxy is TransparentUpgradeableProxy {
address _logic,
address _admin,
bytes memory _data,
IOmniBridge _omniBridge,
IAMB _ambBridge,
uint256 _adminChainId
) TransparentUpgradeableProxy(_logic, _admin, _data) {
omniBridge = _omniBridge;
ambBridge = _ambBridge;
adminChainId = bytes32(uint256(_adminChainId));
}
@ -41,9 +30,9 @@ contract CrossChainUpgradeableProxy is TransparentUpgradeableProxy {
*/
modifier ifAdmin() override {
if (
msg.sender == address(omniBridge) &&
omniBridge.bridgeContract().messageSourceChainId() == adminChainId &&
omniBridge.bridgeContract().messageSender() == _admin()
msg.sender == address(ambBridge) &&
ambBridge.messageSourceChainId() == adminChainId &&
ambBridge.messageSender() == _admin()
) {
_;
} else {

View File

@ -23,4 +23,8 @@ contract MockAMB is IAMB {
function messageSourceChainId() external view override returns (bytes32) {
return xDomainMessageChainId;
}
function execute(address _who, bytes calldata _calldata) external returns (bool success, bytes memory result) {
(success, result) = _who.call(_calldata);
}
}

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import { IAMB, IOmniBridge } from "../CrossChainUpgradeableProxy.sol";
import { IAMB, IOmniBridge } from "../interfaces/Bridge.sol";
contract MockOmniBridge is IOmniBridge {
IAMB public AMB;

View File

@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
// https://docs.tokenbridge.net/amb-bridge/development-of-a-cross-chain-application/how-to-develop-xchain-apps-by-amb#call-a-method-in-another-chain-using-the-amb-bridge
interface IAMB {
function messageSender() external view returns (address);
function messageSourceChainId() external view returns (bytes32);
}
interface IOmniBridge {
function bridgeContract() external view returns (IAMB);
}

View File

@ -50,14 +50,14 @@ describe('TornadoPool', function () {
}
async function fixtureUpgradeable() {
const { tornadoPool, omniBridge } = await loadFixture(fixture)
const { tornadoPool, omniBridge, amb } = await loadFixture(fixture)
const [, gov] = await ethers.getSigners()
const proxy = await deploy(
'CrossChainUpgradeableProxy',
tornadoPool.address,
gov.address,
[],
omniBridge.address,
amb.address,
1,
)
@ -66,14 +66,14 @@ describe('TornadoPool', function () {
const tornadoPoolProxied = TornadoPool.attach(proxy.address)
await tornadoPoolProxied.initialize()
return { tornadoPool: tornadoPoolProxied, proxy, gov, omniBridge }
return { tornadoPool: tornadoPoolProxied, proxy, gov, omniBridge, amb }
}
describe('Upgradeability tests', () => {
it('admin should be gov', async () => {
const { proxy, omniBridge, gov } = await loadFixture(fixtureUpgradeable)
const { proxy, amb, gov } = await loadFixture(fixtureUpgradeable)
const { data } = await proxy.populateTransaction.admin()
const { result } = await omniBridge.callStatic.execute(proxy.address, data)
const { result } = await amb.callStatic.execute(proxy.address, data)
expect('0x' + result.slice(26)).to.be.equal(gov.address.toLowerCase())
})