diff --git a/.gitignore b/.gitignore index 7d69cce..e75f826 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules build -*.orig \ No newline at end of file +*.orig +yarn.lock \ No newline at end of file diff --git a/contracts/SimpleMultiSig.sol b/contracts/SimpleMultiSig.sol index 34036c5..fc0e050 100644 --- a/contracts/SimpleMultiSig.sol +++ b/contracts/SimpleMultiSig.sol @@ -1,4 +1,5 @@ -pragma solidity ^0.4.24; +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.17; contract SimpleMultiSig { @@ -25,7 +26,7 @@ bytes32 constant SALT = 0x251543af6a222378665a76fe38dbceae4871a070b7fdaf5c6c30cf bytes32 DOMAIN_SEPARATOR; // hash for EIP712, computed from contract address // Note that owners_ must be strictly increasing, in order to prevent duplicates - constructor(uint threshold_, address[] owners_, uint chainId) public { + constructor(uint threshold_, address[] memory owners_, uint chainId) { require(owners_.length <= 10 && threshold_ <= owners_.length && threshold_ > 0); address lastAdd = address(0); @@ -46,7 +47,16 @@ bytes32 constant SALT = 0x251543af6a222378665a76fe38dbceae4871a070b7fdaf5c6c30cf } // Note that address recovered from signatures must be strictly increasing, in order to prevent duplicates - function execute(uint8[] sigV, bytes32[] sigR, bytes32[] sigS, address destination, uint value, bytes data, address executor, uint gasLimit) public { + function execute( + uint8[] memory sigV, + bytes32[] memory sigR, + bytes32[] memory sigS, + address destination, + uint value, + bytes memory data, + address executor, + uint gasLimit + ) public { require(sigR.length == threshold); require(sigR.length == sigS.length && sigR.length == sigV.length); require(executor == msg.sender || executor == address(0)); @@ -71,5 +81,5 @@ bytes32 constant SALT = 0x251543af6a222378665a76fe38dbceae4871a070b7fdaf5c6c30cf require(success); } - function () payable external {} + receive() payable external {} } diff --git a/contracts/TestRegistry.sol b/contracts/TestRegistry.sol index 028efe1..dce454f 100644 --- a/contracts/TestRegistry.sol +++ b/contracts/TestRegistry.sol @@ -1,4 +1,5 @@ -pragma solidity ^0.4.18; +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.17; // This contract is only used for testing purposes. contract TestRegistry { diff --git a/test/simplemultisig.js b/test/simplemultisig.js index 50d51c7..25dcc09 100644 --- a/test/simplemultisig.js +++ b/test/simplemultisig.js @@ -17,6 +17,8 @@ const SALT = '0x251543af6a222378665a76fe38dbceae4871a070b7fdaf5c6c30cf758dc33cc0 const CHAINID = 1 const ZEROADDR = '0x000000000000000000000000000000000000000000000' +const etherToWei = (v) => web3.utils.toWei(v.toString(), 'ether') + contract('SimpleMultiSig', function(accounts) { let keyFromPw @@ -26,13 +28,13 @@ contract('SimpleMultiSig', function(accounts) { let createSigs = function(signers, multisigAddr, nonce, destinationAddr, value, data, executor, gasLimit) { const domainData = EIP712DOMAINTYPE_HASH + NAME_HASH.slice(2) + VERSION_HASH.slice(2) + CHAINID.toString('16').padStart(64, '0') + multisigAddr.slice(2).padStart(64, '0') + SALT.slice(2) - DOMAIN_SEPARATOR = web3.sha3(domainData, {encoding: 'hex'}) + DOMAIN_SEPARATOR = web3.utils.sha3(domainData, {encoding: 'hex'}) - let txInput = TXTYPE_HASH + destinationAddr.slice(2).padStart(64, '0') + value.toString('16').padStart(64, '0') + web3.sha3(data, {encoding: 'hex'}).slice(2) + nonce.toString('16').padStart(64, '0') + executor.slice(2).padStart(64, '0') + gasLimit.toString('16').padStart(64, '0') - let txInputHash = web3.sha3(txInput, {encoding: 'hex'}) + let txInput = TXTYPE_HASH + destinationAddr?.slice(2).padStart(64, '0') + value.toString(16).padStart(64, '0') + web3.utils.sha3(data, {encoding: 'hex'})?.slice(2) + nonce.toString(16).padStart(64, '0') + executor?.slice(2).padStart(64, '0') + gasLimit.toString(16).padStart(64, '0') + let txInputHash = web3.utils.sha3(txInput, {encoding: 'hex'}) let input = '0x19' + '01' + DOMAIN_SEPARATOR.slice(2) + txInputHash.slice(2) - let hash = web3.sha3(input, {encoding: 'hex'}) + let hash = web3.utils.sha3(input, {encoding: 'hex'}) let sigV = [] let sigR = [] @@ -66,26 +68,26 @@ contract('SimpleMultiSig', function(accounts) { let executeSendSuccess = async function(owners, threshold, signers, done) { let multisig = await SimpleMultiSig.new(threshold, owners, CHAINID, {from: accounts[0]}) - let randomAddr = web3.sha3(Math.random().toString()).slice(0,42) + let randomAddr = web3.utils.sha3(Math.random().toString()).slice(0,42) let executor = accounts[0] let msgSender = accounts[0] // Receive funds - await web3SendTransaction({from: accounts[0], to: multisig.address, value: web3.toWei(web3.toBigNumber(0.1), 'ether')}) + await web3SendTransaction({from: accounts[0], to: multisig.address, value: etherToWei(0.1)}) let nonce = await multisig.nonce.call() assert.equal(nonce.toNumber(), 0) let bal = await web3GetBalance(multisig.address) - assert.equal(bal, web3.toWei(0.1, 'ether')) + assert.equal(bal, etherToWei(0.1)) // check that owners are stored correctly for (var i=0; i { it("uses correct hash for EIP712DOMAINTYPE", (done) => { const eip712DomainType = 'EIP712Domain(string name,string version,uint256 chainId,address verifyingContract,bytes32 salt)' - assert.equal(web3.sha3(eip712DomainType), EIP712DOMAINTYPE_HASH) + assert.equal(web3.utils.sha3(eip712DomainType), EIP712DOMAINTYPE_HASH) done() }) it("uses correct hash for NAME", (done) => { - assert.equal(web3.sha3('Simple MultiSig'), NAME_HASH) + assert.equal(web3.utils.sha3('Simple MultiSig'), NAME_HASH) done() }) it("uses correct hash for VERSION", (done) => { - assert.equal(web3.sha3('1'), VERSION_HASH) + assert.equal(web3.utils.sha3('1'), VERSION_HASH) done() }) it("uses correct hash for MULTISIGTX", (done) => { const multiSigTxType = 'MultiSigTransaction(address destination,uint256 value,bytes data,uint256 nonce,address executor,uint256 gasLimit)' - assert.equal(web3.sha3(multiSigTxType), TXTYPE_HASH) + assert.equal(web3.utils.sha3(multiSigTxType), TXTYPE_HASH) done() }) }) @@ -317,7 +319,7 @@ contract('SimpleMultiSig', function(accounts) { const walletAddress = '0xe3de7de481cbde9b4d5f62c6d228ec62277560c8' const destination = '0x8582afea2dd8e47297dbcdcf9ca289756ee21430' - const value = web3.toWei(web3.toBigNumber(0.01), 'ether') + const value = etherToWei(0.1) const data = '0xf207564e0000000000000000000000000000000000000000000000000000000000003039' const nonce = 2 const executor = '0x0be430662ec0659ee786c04925c0146991fbdc0f' diff --git a/truffle.js b/truffle.js index 2491c7c..2ac5981 100644 --- a/truffle.js +++ b/truffle.js @@ -1,4 +1,9 @@ module.exports = { + compilers: { + solc: { + version: "0.8.17", + }, + }, networks: { development: { host: "localhost",