mirror of
https://github.com/tornadocash/tornado-nova
synced 2024-02-02 14:53:56 +01:00
Upgradeability tests
This commit is contained in:
parent
93bc29580b
commit
e15751305c
@ -13,7 +13,7 @@ interface iOVM_CrossDomainMessenger {
|
|||||||
*/
|
*/
|
||||||
contract CrossChainUpgradeableProxy is TransparentUpgradeableProxy {
|
contract CrossChainUpgradeableProxy is TransparentUpgradeableProxy {
|
||||||
// https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts/deployments/README.md
|
// https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts/deployments/README.md
|
||||||
iOVM_CrossDomainMessenger public constant messenger = iOVM_CrossDomainMessenger(0x4200000000000000000000000000000000000007);
|
iOVM_CrossDomainMessenger public immutable messenger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Initializes an upgradeable proxy backed by the implementation at `_logic`.
|
* @dev Initializes an upgradeable proxy backed by the implementation at `_logic`.
|
||||||
@ -21,8 +21,11 @@ contract CrossChainUpgradeableProxy is TransparentUpgradeableProxy {
|
|||||||
constructor(
|
constructor(
|
||||||
address _logic,
|
address _logic,
|
||||||
address _admin,
|
address _admin,
|
||||||
bytes memory _data
|
bytes memory _data,
|
||||||
) TransparentUpgradeableProxy(_logic, _admin, _data) {}
|
iOVM_CrossDomainMessenger _messenger
|
||||||
|
) TransparentUpgradeableProxy(_logic, _admin, _data) {
|
||||||
|
messenger = _messenger;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Modifier used internally that will delegate the call to the implementation unless the sender is the cross chain admin.
|
* @dev Modifier used internally that will delegate the call to the implementation unless the sender is the cross chain admin.
|
||||||
|
14
contracts/Mocks/MockOVM_CrossDomainMessenger.sol
Normal file
14
contracts/Mocks/MockOVM_CrossDomainMessenger.sol
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
contract MockOVM_CrossDomainMessenger {
|
||||||
|
address public xDomainMessageSender;
|
||||||
|
|
||||||
|
constructor(address _xDomainMessageSender) {
|
||||||
|
xDomainMessageSender = _xDomainMessageSender;
|
||||||
|
}
|
||||||
|
|
||||||
|
function execute(address _who, bytes calldata _calldata) external returns (bool success, bytes memory result) {
|
||||||
|
(success, result) = _who.call(_calldata);
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
pragma solidity ^0.7.0;
|
pragma solidity ^0.7.0;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
import "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";
|
||||||
|
|
||||||
interface IVerifier {
|
interface IVerifier {
|
||||||
function verifyProof(bytes memory _proof, uint256[10] memory _input) external view returns (bool);
|
function verifyProof(bytes memory _proof, uint256[10] memory _input) external view returns (bool);
|
||||||
@ -23,7 +24,7 @@ interface ERC20 {
|
|||||||
function transfer(address to, uint256 value) external returns (bool);
|
function transfer(address to, uint256 value) external returns (bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
contract TornadoPool {
|
contract TornadoPool is Initializable {
|
||||||
uint256 public constant FIELD_SIZE = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
uint256 public constant FIELD_SIZE = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
||||||
uint256 public constant MAX_EXT_AMOUNT = 2**248 - 1;
|
uint256 public constant MAX_EXT_AMOUNT = 2**248 - 1;
|
||||||
|
|
||||||
@ -66,15 +67,13 @@ contract TornadoPool {
|
|||||||
@dev The constructor
|
@dev The constructor
|
||||||
@param _verifier2 the address of SNARK verifier for 2 inputs
|
@param _verifier2 the address of SNARK verifier for 2 inputs
|
||||||
@param _verifier16 the address of SNARK verifier for 16 inputs
|
@param _verifier16 the address of SNARK verifier for 16 inputs
|
||||||
@param _currentRoot root of an empty Merkle tree
|
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(IVerifier _verifier2, IVerifier _verifier16) {
|
||||||
IVerifier _verifier2,
|
|
||||||
IVerifier _verifier16,
|
|
||||||
bytes32 _currentRoot
|
|
||||||
) {
|
|
||||||
verifier2 = _verifier2;
|
verifier2 = _verifier2;
|
||||||
verifier16 = _verifier16;
|
verifier16 = _verifier16;
|
||||||
|
}
|
||||||
|
|
||||||
|
function initialize(bytes32 _currentRoot) external initializer {
|
||||||
currentRoot = _currentRoot;
|
currentRoot = _currentRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||||
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
||||||
"@openzeppelin/contracts": "git+https://github.com/tornadocash/openzeppelin-contracts.git#6e46aa6946a7f215e7604169ddf46e1aebea850f",
|
"@openzeppelin/contracts": "git+https://github.com/tornadocash/openzeppelin-contracts.git#6e46aa6946a7f215e7604169ddf46e1aebea850f",
|
||||||
|
"@openzeppelin/contracts-upgradeable": "3.4.1",
|
||||||
"bignumber.js": "^9.0.0",
|
"bignumber.js": "^9.0.0",
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.4",
|
||||||
"circom": "^0.5.45",
|
"circom": "^0.5.45",
|
||||||
|
11
src/utils.js
11
src/utils.js
@ -1,3 +1,4 @@
|
|||||||
|
/* global network */
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
const { ethers } = require('hardhat')
|
const { ethers } = require('hardhat')
|
||||||
const BigNumber = ethers.BigNumber
|
const BigNumber = ethers.BigNumber
|
||||||
@ -73,6 +74,15 @@ async function revertSnapshot(id) {
|
|||||||
await ethers.provider.send('evm_revert', [id])
|
await ethers.provider.send('evm_revert', [id])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getSignerFromAddress(address) {
|
||||||
|
await network.provider.request({
|
||||||
|
method: 'hardhat_impersonateAccount',
|
||||||
|
params: [address],
|
||||||
|
})
|
||||||
|
|
||||||
|
return await ethers.provider.getSigner(address)
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
FIELD_SIZE,
|
FIELD_SIZE,
|
||||||
randomBN,
|
randomBN,
|
||||||
@ -84,4 +94,5 @@ module.exports = {
|
|||||||
takeSnapshot,
|
takeSnapshot,
|
||||||
revertSnapshot,
|
revertSnapshot,
|
||||||
shuffle,
|
shuffle,
|
||||||
|
getSignerFromAddress,
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,11 @@ const { transaction, registerAndTransact } = require('../src/index')
|
|||||||
const { Keypair } = require('../src/keypair')
|
const { Keypair } = require('../src/keypair')
|
||||||
|
|
||||||
describe('TornadoPool', () => {
|
describe('TornadoPool', () => {
|
||||||
let snapshotId, tornadoPool, sender
|
let snapshotId, tornadoPool, sender, gov, proxy, messenger
|
||||||
|
|
||||||
/* prettier-ignore */
|
/* prettier-ignore */
|
||||||
before(async function () {
|
before(async function () {
|
||||||
;[sender] = await ethers.getSigners()
|
;[sender, gov] = await ethers.getSigners()
|
||||||
|
|
||||||
const Verifier2 = await ethers.getContractFactory('Verifier2')
|
const Verifier2 = await ethers.getContractFactory('Verifier2')
|
||||||
const verifier2 = await Verifier2.deploy()
|
const verifier2 = await Verifier2.deploy()
|
||||||
@ -30,10 +30,37 @@ describe('TornadoPool', () => {
|
|||||||
const root = await tree.root()
|
const root = await tree.root()
|
||||||
|
|
||||||
const Pool = await ethers.getContractFactory('TornadoPool')
|
const Pool = await ethers.getContractFactory('TornadoPool')
|
||||||
tornadoPool = await Pool.deploy(verifier2.address, verifier16.address, toFixedHex(root))
|
const tornadoPoolImpl = await Pool.deploy(verifier2.address, verifier16.address)
|
||||||
|
|
||||||
|
const OVM_Messenger = await ethers.getContractFactory('MockOVM_CrossDomainMessenger')
|
||||||
|
messenger = await OVM_Messenger.deploy(gov.address)
|
||||||
|
await messenger.deployed()
|
||||||
|
|
||||||
|
const CrossChainUpgradeableProxy = await ethers.getContractFactory('CrossChainUpgradeableProxy')
|
||||||
|
proxy = await CrossChainUpgradeableProxy.deploy(tornadoPoolImpl.address, gov.address, [], messenger.address)
|
||||||
|
await proxy.deployed()
|
||||||
|
|
||||||
|
tornadoPool = await Pool.attach(proxy.address)
|
||||||
|
|
||||||
|
await tornadoPool.initialize(toFixedHex(root))
|
||||||
|
|
||||||
snapshotId = await takeSnapshot()
|
snapshotId = await takeSnapshot()
|
||||||
})
|
})
|
||||||
|
describe('Upgradeability tests', () => {
|
||||||
|
it('admin should be gov', async () => {
|
||||||
|
const { data } = await proxy.populateTransaction.admin()
|
||||||
|
const { result } = await messenger.callStatic.execute(proxy.address, data)
|
||||||
|
expect('0x' + result.slice(26)).to.be.equal(gov.address.toLowerCase())
|
||||||
|
})
|
||||||
|
|
||||||
|
it('non admin cannot call', async () => {
|
||||||
|
await proxy
|
||||||
|
.admin()
|
||||||
|
.should.be.revertedWith(
|
||||||
|
"Transaction reverted: function selector was not recognized and there's no fallback function",
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('encrypt -> decrypt should work', () => {
|
it('encrypt -> decrypt should work', () => {
|
||||||
const data = Buffer.from([0xff, 0xaa, 0x00, 0x01])
|
const data = Buffer.from([0xff, 0xaa, 0x00, 0x01])
|
||||||
|
@ -683,6 +683,11 @@
|
|||||||
"@types/sinon-chai" "^3.2.3"
|
"@types/sinon-chai" "^3.2.3"
|
||||||
"@types/web3" "1.0.19"
|
"@types/web3" "1.0.19"
|
||||||
|
|
||||||
|
"@openzeppelin/contracts-upgradeable@3.4.1":
|
||||||
|
version "3.4.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-3.4.1.tgz#38dfdfa86fda0a088c6fcdebe6870cfaf897b471"
|
||||||
|
integrity sha512-wBGlUzEkOxcj/ghtcF2yKc8ZYh+PTUtm1mK38zoENulJ6aplij7eH8quo3lMugfzPJy+V6V5qI8QhdQmCn7hkQ==
|
||||||
|
|
||||||
"@openzeppelin/contracts@git+https://github.com/tornadocash/openzeppelin-contracts.git#6e46aa6946a7f215e7604169ddf46e1aebea850f":
|
"@openzeppelin/contracts@git+https://github.com/tornadocash/openzeppelin-contracts.git#6e46aa6946a7f215e7604169ddf46e1aebea850f":
|
||||||
version "3.4.1-solc-0.7-2"
|
version "3.4.1-solc-0.7-2"
|
||||||
resolved "git+https://github.com/tornadocash/openzeppelin-contracts.git#6e46aa6946a7f215e7604169ddf46e1aebea850f"
|
resolved "git+https://github.com/tornadocash/openzeppelin-contracts.git#6e46aa6946a7f215e7604169ddf46e1aebea850f"
|
||||||
|
Loading…
Reference in New Issue
Block a user