Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated: solidity version to 0.8 & web3.js API #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
build
*.orig
*.orig
yarn.lock
18 changes: 14 additions & 4 deletions contracts/SimpleMultiSig.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.4.24;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

contract SimpleMultiSig {

Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -71,5 +81,5 @@ bytes32 constant SALT = 0x251543af6a222378665a76fe38dbceae4871a070b7fdaf5c6c30cf
require(success);
}

function () payable external {}
receive() payable external {}
}
3 changes: 2 additions & 1 deletion contracts/TestRegistry.sol
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
36 changes: 19 additions & 17 deletions test/simplemultisig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = []
Expand Down Expand Up @@ -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<owners.length; i++) {
let ownerFromContract = await multisig.ownersArr.call(i)
assert.equal(owners[i], ownerFromContract)
assert.equal(owners[i].toUpperCase(), ownerFromContract.toUpperCase())
}

let value = web3.toWei(web3.toBigNumber(0.01), 'ether')
let value = etherToWei(0.1)

let sigs = createSigs(signers, multisig.address, nonce, randomAddr, value, '', executor, 21000)

Expand Down Expand Up @@ -144,10 +146,10 @@ contract('SimpleMultiSig', function(accounts) {
assert.equal(nonce.toNumber(), 0)

// Receive funds
await web3SendTransaction({from: accounts[0], to: multisig.address, value: web3.toWei(web3.toBigNumber(2), 'ether')})
await web3SendTransaction({from: accounts[0], to: multisig.address, value: etherToWei(2)})

let randomAddr = web3.sha3(Math.random().toString()).slice(0,42)
let value = web3.toWei(web3.toBigNumber(0.1), 'ether')
let randomAddr = web3.utils.sha3(Math.random().toString()).slice(0,42)
let value = etherToWei(0.1)
let sigs = createSigs(signers, multisig.address, nonce + nonceOffset, randomAddr, value, '', executor, gasLimit)

let errMsg = ''
Expand Down Expand Up @@ -274,23 +276,23 @@ contract('SimpleMultiSig', function(accounts) {
describe("Hash constants", () => {
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()
})
})
Expand All @@ -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'
Expand Down
5 changes: 5 additions & 0 deletions truffle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
module.exports = {
compilers: {
solc: {
version: "0.8.17",
},
},
networks: {
development: {
host: "localhost",
Expand Down