Skip to content

Commit

Permalink
Merge 4ece8a5 into 5414d21
Browse files Browse the repository at this point in the history
  • Loading branch information
k06a committed May 15, 2018
2 parents 5414d21 + 4ece8a5 commit f8843b8
Show file tree
Hide file tree
Showing 9 changed files with 1,164 additions and 389 deletions.
6 changes: 3 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"web3": false
},
"rules": {

// Strict mode
"strict": [2, "global"],

// Code style
"indent": [2, 4],
"quotes": [2, "single"],
Expand All @@ -44,7 +44,7 @@
"no-debugger": 0,
"no-undef": 2,
"object-curly-spacing": [2, "always"],
"max-len": [2, 120, 2],
"max-len": [2, 130, 2],
"generator-star-spacing": ["error", "before"],
"promise/avoid-new": 0,
"promise/always-return": 0
Expand Down
287 changes: 186 additions & 101 deletions contracts/Multiownable.sol

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions contracts/Set.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
pragma solidity ^0.4.23;


library Set {

struct Data {
bytes32[] items;
mapping(bytes32 => uint) lookup;
}

function length(Data storage s) internal view returns(uint) {
return s.items.length;
}

function at(Data storage s, uint index) internal view returns(bytes32) {
return s.items[index];
}

function contains(Data storage s, bytes32 item) internal view returns(bool) {
return s.lookup[item] != 0;
}

function add(Data storage s, bytes32 item) public returns(bool) {
if (s.lookup[item] > 0) {
return false;
}
s.lookup[item] = s.items.push(item);
return true;
}

function remove(Data storage s, bytes32 item) public returns(bool) {
uint index = s.lookup[item];
if (index == 0) {
return false;
}
if (index < s.items.length) {
bytes32 lastItem = s.items[s.items.length - 1];
s.items[index - 1] = lastItem;
s.lookup[lastItem] = index;
}
s.items.length -= 1;
delete s.lookup[item];
return true;
}

}
4 changes: 3 additions & 1 deletion migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const Multiownable = artifacts.require('Multiownable');
const Set = artifacts.require('Set');

module.exports = function (deployer) {
module.exports = async function (deployer) {
Multiownable.link('Set', (await Set.new()).address);
deployer.deploy(Multiownable);
};
8 changes: 7 additions & 1 deletion test/MultiAttack.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ require('chai')
.use(require('chai-bignumber')(web3.BigNumber))
.should();

const Set = artifacts.require('Set.sol');
const MultiAttackable = artifacts.require('./impl/MultiAttackable.sol');
const MultiAttacker = artifacts.require('./impl/MultiAttacker.sol');

contract('MultiAttack', function ([_, wallet1, wallet2, wallet3, wallet4, wallet5]) {
before(async function () {
MultiAttackable.link('Set', (await Set.new()).address);
});

it('should handle reentracy attack', async function () {
const victim = await MultiAttackable.new();
const hacker = await MultiAttacker.new();

// Prepare victim wallet
await victim.transferOwnership([wallet1, wallet2]);
await victim.addOwners([wallet1, wallet2]);
await victim.resignOwnership({ from: _ });
await web3.eth.sendTransaction({ from: _, to: victim.address, value: ether(3) });

// Try reentrace attack
Expand Down

0 comments on commit f8843b8

Please sign in to comment.