mirror of
https://github.com/tornadocash/tornado-nova
synced 2024-02-02 14:53:56 +01:00
fix crosschainproxy
This commit is contained in:
parent
e7889c4010
commit
a93caef5fa
@ -1,25 +1,14 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
pragma solidity ^0.7.0;
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
import { IAMB } from "./interfaces/Bridge.sol";
|
||||||
import "@openzeppelin/contracts/contracts/proxy/TransparentUpgradeableProxy.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.
|
* @dev TransparentUpgradeableProxy where admin acts from a different chain.
|
||||||
*/
|
*/
|
||||||
contract CrossChainUpgradeableProxy is TransparentUpgradeableProxy {
|
contract CrossChainUpgradeableProxy is TransparentUpgradeableProxy {
|
||||||
IOmniBridge public immutable omniBridge;
|
IAMB public immutable ambBridge;
|
||||||
bytes32 public immutable adminChainId;
|
bytes32 public immutable adminChainId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,10 +18,10 @@ contract CrossChainUpgradeableProxy is TransparentUpgradeableProxy {
|
|||||||
address _logic,
|
address _logic,
|
||||||
address _admin,
|
address _admin,
|
||||||
bytes memory _data,
|
bytes memory _data,
|
||||||
IOmniBridge _omniBridge,
|
IAMB _ambBridge,
|
||||||
uint256 _adminChainId
|
uint256 _adminChainId
|
||||||
) TransparentUpgradeableProxy(_logic, _admin, _data) {
|
) TransparentUpgradeableProxy(_logic, _admin, _data) {
|
||||||
omniBridge = _omniBridge;
|
ambBridge = _ambBridge;
|
||||||
adminChainId = bytes32(uint256(_adminChainId));
|
adminChainId = bytes32(uint256(_adminChainId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,9 +30,9 @@ contract CrossChainUpgradeableProxy is TransparentUpgradeableProxy {
|
|||||||
*/
|
*/
|
||||||
modifier ifAdmin() override {
|
modifier ifAdmin() override {
|
||||||
if (
|
if (
|
||||||
msg.sender == address(omniBridge) &&
|
msg.sender == address(ambBridge) &&
|
||||||
omniBridge.bridgeContract().messageSourceChainId() == adminChainId &&
|
ambBridge.messageSourceChainId() == adminChainId &&
|
||||||
omniBridge.bridgeContract().messageSender() == _admin()
|
ambBridge.messageSender() == _admin()
|
||||||
) {
|
) {
|
||||||
_;
|
_;
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,4 +23,8 @@ contract MockAMB is IAMB {
|
|||||||
function messageSourceChainId() external view override returns (bytes32) {
|
function messageSourceChainId() external view override returns (bytes32) {
|
||||||
return xDomainMessageChainId;
|
return xDomainMessageChainId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function execute(address _who, bytes calldata _calldata) external returns (bool success, bytes memory result) {
|
||||||
|
(success, result) = _who.call(_calldata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
pragma solidity ^0.7.0;
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
import { IAMB, IOmniBridge } from "../CrossChainUpgradeableProxy.sol";
|
import { IAMB, IOmniBridge } from "../interfaces/Bridge.sol";
|
||||||
|
|
||||||
contract MockOmniBridge is IOmniBridge {
|
contract MockOmniBridge is IOmniBridge {
|
||||||
IAMB public AMB;
|
IAMB public AMB;
|
||||||
|
13
contracts/interfaces/Bridge.sol
Normal file
13
contracts/interfaces/Bridge.sol
Normal 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);
|
||||||
|
}
|
@ -50,14 +50,14 @@ describe('TornadoPool', function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function fixtureUpgradeable() {
|
async function fixtureUpgradeable() {
|
||||||
const { tornadoPool, omniBridge } = await loadFixture(fixture)
|
const { tornadoPool, omniBridge, amb } = await loadFixture(fixture)
|
||||||
const [, gov] = await ethers.getSigners()
|
const [, gov] = await ethers.getSigners()
|
||||||
const proxy = await deploy(
|
const proxy = await deploy(
|
||||||
'CrossChainUpgradeableProxy',
|
'CrossChainUpgradeableProxy',
|
||||||
tornadoPool.address,
|
tornadoPool.address,
|
||||||
gov.address,
|
gov.address,
|
||||||
[],
|
[],
|
||||||
omniBridge.address,
|
amb.address,
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -66,14 +66,14 @@ describe('TornadoPool', function () {
|
|||||||
const tornadoPoolProxied = TornadoPool.attach(proxy.address)
|
const tornadoPoolProxied = TornadoPool.attach(proxy.address)
|
||||||
await tornadoPoolProxied.initialize()
|
await tornadoPoolProxied.initialize()
|
||||||
|
|
||||||
return { tornadoPool: tornadoPoolProxied, proxy, gov, omniBridge }
|
return { tornadoPool: tornadoPoolProxied, proxy, gov, omniBridge, amb }
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Upgradeability tests', () => {
|
describe('Upgradeability tests', () => {
|
||||||
it('admin should be gov', async () => {
|
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 { 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())
|
expect('0x' + result.slice(26)).to.be.equal(gov.address.toLowerCase())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user