Commit 2441fd7d by Leo Arias Committed by Francisco Giordano

Move contracts to subdirectories (#1253)

* Move contracts to subdirectories

Fixes #1177.

This Change also removes the LimitBalance contract.

* fix import

* move MerkleProof to cryptography

* Fix import
parent 964bc404
pragma solidity ^0.4.24;
/**
* @title LimitBalance
* @dev Simple contract to limit the balance of child contract.
* Note this doesn't prevent other contracts to send funds by using selfdestruct(address);
* See: https://github.com/ConsenSys/smart-contract-best-practices#remember-that-ether-can-be-forcibly-sent-to-an-account
*/
contract LimitBalance {
uint256 public limit;
/**
* @dev Constructor that sets the passed value as a limit.
* @param _limit uint256 to represent the limit.
*/
constructor(uint256 _limit) public {
limit = _limit;
}
/**
* @dev Checks if limit was reached. Case true, it throws.
*/
modifier limitedPayable() {
require(address(this).balance <= limit);
_;
}
}
...@@ -2,7 +2,7 @@ pragma solidity ^0.4.24; ...@@ -2,7 +2,7 @@ pragma solidity ^0.4.24;
import "../ownership/Ownable.sol"; import "../ownership/Ownable.sol";
import "../access/rbac/RBAC.sol"; import "../access/rbac/RBAC.sol";
import "../ECRecovery.sol"; import "../cryptography/ECDSA.sol";
/** /**
...@@ -30,7 +30,7 @@ import "../ECRecovery.sol"; ...@@ -30,7 +30,7 @@ import "../ECRecovery.sol";
* much more complex. See https://ethereum.stackexchange.com/a/50616 for more details. * much more complex. See https://ethereum.stackexchange.com/a/50616 for more details.
*/ */
contract SignatureBouncer is Ownable, RBAC { contract SignatureBouncer is Ownable, RBAC {
using ECRecovery for bytes32; using ECDSA for bytes32;
string public constant ROLE_BOUNCER = "bouncer"; string public constant ROLE_BOUNCER = "bouncer";
uint internal constant METHOD_ID_SIZE = 4; uint internal constant METHOD_ID_SIZE = 4;
......
pragma solidity ^0.4.24; pragma solidity ^0.4.24;
import "./payment/PullPayment.sol"; import "../payment/PullPayment.sol";
import "./lifecycle/Destructible.sol"; import "../lifecycle/Destructible.sol";
/** /**
* @title Bounty * @title BreakInvariantBounty
* @dev This bounty will pay out to a researcher if they break invariant logic of the contract. * @dev This bounty will pay out to a researcher if they break invariant logic of the contract.
*/ */
contract Bounty is PullPayment, Destructible { contract BreakInvariantBounty is PullPayment, Destructible {
bool public claimed; bool public claimed;
mapping(address => address) public researchers; mapping(address => address) public researchers;
......
...@@ -8,7 +8,7 @@ pragma solidity ^0.4.24; ...@@ -8,7 +8,7 @@ pragma solidity ^0.4.24;
* See https://github.com/ethereum/solidity/issues/864 * See https://github.com/ethereum/solidity/issues/864
*/ */
library ECRecovery { library ECDSA {
/** /**
* @dev Recover signer address from a message by using their signature * @dev Recover signer address from a message by using their signature
......
pragma solidity ^0.4.24; pragma solidity ^0.4.24;
import "../AutoIncrementing.sol"; import "../utils/AutoIncrementing.sol";
contract AutoIncrementingImpl { contract AutoIncrementingImpl {
......
pragma solidity ^0.4.24; pragma solidity ^0.4.24;
import "../ECRecovery.sol"; import "../cryptography/ECDSA.sol";
contract ECRecoveryMock { contract ECDSAMock {
using ECRecovery for bytes32; using ECDSA for bytes32;
function recover(bytes32 _hash, bytes _signature) function recover(bytes32 _hash, bytes _signature)
public public
......
pragma solidity ^0.4.24; pragma solidity ^0.4.24;
import {Bounty, Target} from "../../contracts/Bounty.sol"; // When this line is split, truffle parsing fails.
// See: https://github.com/ethereum/solidity/issues/4871
// solium-disable-next-line max-len
import {BreakInvariantBounty, Target} from "../../contracts/bounties/BreakInvariantBounty.sol";
contract InsecureTargetMock is Target { contract InsecureInvariantTargetMock is Target {
function checkInvariant() public returns(bool) { function checkInvariant() public returns(bool) {
return false; return false;
} }
} }
contract InsecureTargetBounty is Bounty { contract InsecureInvariantTargetBounty is BreakInvariantBounty {
function deployContract() internal returns (address) { function deployContract() internal returns (address) {
return new InsecureTargetMock(); return new InsecureInvariantTargetMock();
} }
} }
pragma solidity ^0.4.24;
import "../LimitBalance.sol";
// mock class using LimitBalance
contract LimitBalanceMock is LimitBalance(1000) {
function limitedDeposit() public payable limitedPayable {
}
}
pragma solidity ^0.4.24; pragma solidity ^0.4.24;
import { MerkleProof } from "../MerkleProof.sol"; import { MerkleProof } from "../cryptography/MerkleProof.sol";
contract MerkleProofWrapper { contract MerkleProofWrapper {
......
pragma solidity ^0.4.24; pragma solidity ^0.4.24;
import "../ReentrancyGuard.sol"; import "../utils/ReentrancyGuard.sol";
import "./ReentrancyAttack.sol"; import "./ReentrancyAttack.sol";
......
pragma solidity ^0.4.24; pragma solidity ^0.4.24;
import {Bounty, Target} from "../../contracts/Bounty.sol"; // When this line is split, truffle parsing fails.
// See: https://github.com/ethereum/solidity/issues/4871
// solium-disable-next-line max-len
import {BreakInvariantBounty, Target} from "../../contracts/bounties/BreakInvariantBounty.sol";
contract SecureTargetMock is Target { contract SecureInvariantTargetMock is Target {
function checkInvariant() public returns(bool) { function checkInvariant() public returns(bool) {
return true; return true;
} }
} }
contract SecureTargetBounty is Bounty { contract SecureInvariantTargetBounty is BreakInvariantBounty {
function deployContract() internal returns (address) { function deployContract() internal returns (address) {
return new SecureTargetMock(); return new SecureInvariantTargetMock();
} }
} }
...@@ -3,7 +3,7 @@ pragma solidity ^0.4.24; ...@@ -3,7 +3,7 @@ pragma solidity ^0.4.24;
import "./IERC721Basic.sol"; import "./IERC721Basic.sol";
import "./IERC721Receiver.sol"; import "./IERC721Receiver.sol";
import "../../math/SafeMath.sol"; import "../../math/SafeMath.sol";
import "../../AddressUtils.sol"; import "../../utils/Address.sol";
import "../../introspection/SupportsInterfaceWithLookup.sol"; import "../../introspection/SupportsInterfaceWithLookup.sol";
...@@ -14,7 +14,7 @@ import "../../introspection/SupportsInterfaceWithLookup.sol"; ...@@ -14,7 +14,7 @@ import "../../introspection/SupportsInterfaceWithLookup.sol";
contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic { contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
using SafeMath for uint256; using SafeMath for uint256;
using AddressUtils for address; using Address for address;
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector`
......
...@@ -4,7 +4,7 @@ pragma solidity ^0.4.24; ...@@ -4,7 +4,7 @@ pragma solidity ^0.4.24;
/** /**
* Utility library of inline functions on addresses * Utility library of inline functions on addresses
*/ */
library AddressUtils { library Address {
/** /**
* Returns whether the target address is a contract * Returns whether the target address is a contract
......
...@@ -2,8 +2,8 @@ const { ethGetBalance, ethSendTransaction } = require('./helpers/web3'); ...@@ -2,8 +2,8 @@ const { ethGetBalance, ethSendTransaction } = require('./helpers/web3');
const expectEvent = require('./helpers/expectEvent'); const expectEvent = require('./helpers/expectEvent');
const { assertRevert } = require('./helpers/assertRevert'); const { assertRevert } = require('./helpers/assertRevert');
const SecureTargetBounty = artifacts.require('SecureTargetBounty'); const SecureInvariantTargetBounty = artifacts.require('SecureInvariantTargetBounty');
const InsecureTargetBounty = artifacts.require('InsecureTargetBounty'); const InsecureInvariantTargetBounty = artifacts.require('InsecureInvariantTargetBounty');
require('chai') require('chai')
.use(require('chai-bignumber')(web3.BigNumber)) .use(require('chai-bignumber')(web3.BigNumber))
...@@ -17,10 +17,10 @@ const sendReward = async (from, to, value) => ethSendTransaction({ ...@@ -17,10 +17,10 @@ const sendReward = async (from, to, value) => ethSendTransaction({
const reward = new web3.BigNumber(web3.toWei(1, 'ether')); const reward = new web3.BigNumber(web3.toWei(1, 'ether'));
contract('Bounty', function ([_, owner, researcher, nonTarget]) { contract('BreakInvariantBounty', function ([_, owner, researcher, nonTarget]) {
context('against secure contract', function () { context('against secure contract', function () {
beforeEach(async function () { beforeEach(async function () {
this.bounty = await SecureTargetBounty.new({ from: owner }); this.bounty = await SecureInvariantTargetBounty.new({ from: owner });
}); });
it('can set reward', async function () { it('can set reward', async function () {
...@@ -53,7 +53,7 @@ contract('Bounty', function ([_, owner, researcher, nonTarget]) { ...@@ -53,7 +53,7 @@ contract('Bounty', function ([_, owner, researcher, nonTarget]) {
context('against broken contract', function () { context('against broken contract', function () {
beforeEach(async function () { beforeEach(async function () {
this.bounty = await InsecureTargetBounty.new(); this.bounty = await InsecureInvariantTargetBounty.new();
const result = await this.bounty.createTarget({ from: researcher }); const result = await this.bounty.createTarget({ from: researcher });
const event = expectEvent.inLogs(result.logs, 'TargetCreated'); const event = expectEvent.inLogs(result.logs, 'TargetCreated');
......
const { assertRevert } = require('./helpers/assertRevert');
const { ethGetBalance } = require('./helpers/web3');
const LimitBalanceMock = artifacts.require('LimitBalanceMock');
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
contract('LimitBalance', function () {
let limitBalance;
beforeEach(async function () {
limitBalance = await LimitBalanceMock.new();
});
const LIMIT = 1000;
it('should expose limit', async function () {
const limit = await limitBalance.limit();
limit.should.be.bignumber.equal(LIMIT);
});
it('should allow sending below limit', async function () {
const amount = 1;
await limitBalance.limitedDeposit({ value: amount });
const balance = await ethGetBalance(limitBalance.address);
balance.should.be.bignumber.equal(amount);
});
it('shouldnt allow sending above limit', async function () {
const amount = 1110;
await assertRevert(limitBalance.limitedDeposit({ value: amount }));
});
it('should allow multiple sends below limit', async function () {
const amount = 500;
await limitBalance.limitedDeposit({ value: amount });
const balance = await ethGetBalance(limitBalance.address);
balance.should.be.bignumber.equal(amount);
await limitBalance.limitedDeposit({ value: amount });
const updatedBalance = await ethGetBalance(limitBalance.address);
updatedBalance.should.be.bignumber.equal(amount * 2);
});
it('shouldnt allow multiple sends above limit', async function () {
const amount = 500;
await limitBalance.limitedDeposit({ value: amount });
const balance = await ethGetBalance(limitBalance.address);
balance.should.be.bignumber.equal(amount);
await assertRevert(limitBalance.limitedDeposit({ value: amount + 1 }));
});
});
const { signMessage, toEthSignedMessageHash } = require('../helpers/sign'); const { signMessage, toEthSignedMessageHash } = require('../helpers/sign');
const { expectThrow } = require('../helpers/expectThrow'); const { expectThrow } = require('../helpers/expectThrow');
const ECRecoveryMock = artifacts.require('ECRecoveryMock'); const ECDSAMock = artifacts.require('ECDSAMock');
require('chai') require('chai')
.should(); .should();
...@@ -9,9 +9,9 @@ require('chai') ...@@ -9,9 +9,9 @@ require('chai')
const TEST_MESSAGE = web3.sha3('OpenZeppelin'); const TEST_MESSAGE = web3.sha3('OpenZeppelin');
const WRONG_MESSAGE = web3.sha3('Nope'); const WRONG_MESSAGE = web3.sha3('Nope');
contract('ECRecovery', function ([_, anyone]) { contract('ECDSA', function ([_, anyone]) {
beforeEach(async function () { beforeEach(async function () {
this.mock = await ECRecoveryMock.new(); this.mock = await ECDSAMock.new();
}); });
it('recover v0', async function () { it('recover v0', async function () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment