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
This commit is contained in:
Leo Arias
2018-09-03 07:53:28 -06:00
committed by Francisco Giordano
parent 964bc4044a
commit 2441fd7d17
21 changed files with 64 additions and 161 deletions

View File

@ -1,31 +0,0 @@
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);
_;
}
}

View File

@ -2,7 +2,7 @@ pragma solidity ^0.4.24;
import "../ownership/Ownable.sol";
import "../access/rbac/RBAC.sol";
import "../ECRecovery.sol";
import "../cryptography/ECDSA.sol";
/**
@ -30,7 +30,7 @@ import "../ECRecovery.sol";
* much more complex. See https://ethereum.stackexchange.com/a/50616 for more details.
*/
contract SignatureBouncer is Ownable, RBAC {
using ECRecovery for bytes32;
using ECDSA for bytes32;
string public constant ROLE_BOUNCER = "bouncer";
uint internal constant METHOD_ID_SIZE = 4;

View File

@ -1,15 +1,15 @@
pragma solidity ^0.4.24;
import "./payment/PullPayment.sol";
import "./lifecycle/Destructible.sol";
import "../payment/PullPayment.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.
*/
contract Bounty is PullPayment, Destructible {
contract BreakInvariantBounty is PullPayment, Destructible {
bool public claimed;
mapping(address => address) public researchers;

View File

@ -8,7 +8,7 @@ pragma solidity ^0.4.24;
* See https://github.com/ethereum/solidity/issues/864
*/
library ECRecovery {
library ECDSA {
/**
* @dev Recover signer address from a message by using their signature

View File

@ -1,6 +1,6 @@
pragma solidity ^0.4.24;
import "../AutoIncrementing.sol";
import "../utils/AutoIncrementing.sol";
contract AutoIncrementingImpl {

View File

@ -1,11 +1,11 @@
pragma solidity ^0.4.24;
import "../ECRecovery.sol";
import "../cryptography/ECDSA.sol";
contract ECRecoveryMock {
using ECRecovery for bytes32;
contract ECDSAMock {
using ECDSA for bytes32;
function recover(bytes32 _hash, bytes _signature)
public

View File

@ -0,0 +1,20 @@
pragma solidity ^0.4.24;
// 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 InsecureInvariantTargetMock is Target {
function checkInvariant() public returns(bool) {
return false;
}
}
contract InsecureInvariantTargetBounty is BreakInvariantBounty {
function deployContract() internal returns (address) {
return new InsecureInvariantTargetMock();
}
}

View File

@ -1,17 +0,0 @@
pragma solidity ^0.4.24;
import {Bounty, Target} from "../../contracts/Bounty.sol";
contract InsecureTargetMock is Target {
function checkInvariant() public returns(bool) {
return false;
}
}
contract InsecureTargetBounty is Bounty {
function deployContract() internal returns (address) {
return new InsecureTargetMock();
}
}

View File

@ -1,13 +0,0 @@
pragma solidity ^0.4.24;
import "../LimitBalance.sol";
// mock class using LimitBalance
contract LimitBalanceMock is LimitBalance(1000) {
function limitedDeposit() public payable limitedPayable {
}
}

View File

@ -1,6 +1,6 @@
pragma solidity ^0.4.24;
import { MerkleProof } from "../MerkleProof.sol";
import { MerkleProof } from "../cryptography/MerkleProof.sol";
contract MerkleProofWrapper {

View File

@ -1,6 +1,6 @@
pragma solidity ^0.4.24;
import "../ReentrancyGuard.sol";
import "../utils/ReentrancyGuard.sol";
import "./ReentrancyAttack.sol";

View File

@ -0,0 +1,20 @@
pragma solidity ^0.4.24;
// 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 SecureInvariantTargetMock is Target {
function checkInvariant() public returns(bool) {
return true;
}
}
contract SecureInvariantTargetBounty is BreakInvariantBounty {
function deployContract() internal returns (address) {
return new SecureInvariantTargetMock();
}
}

View File

@ -1,17 +0,0 @@
pragma solidity ^0.4.24;
import {Bounty, Target} from "../../contracts/Bounty.sol";
contract SecureTargetMock is Target {
function checkInvariant() public returns(bool) {
return true;
}
}
contract SecureTargetBounty is Bounty {
function deployContract() internal returns (address) {
return new SecureTargetMock();
}
}

View File

@ -3,7 +3,7 @@ pragma solidity ^0.4.24;
import "./IERC721Basic.sol";
import "./IERC721Receiver.sol";
import "../../math/SafeMath.sol";
import "../../AddressUtils.sol";
import "../../utils/Address.sol";
import "../../introspection/SupportsInterfaceWithLookup.sol";
@ -14,7 +14,7 @@ import "../../introspection/SupportsInterfaceWithLookup.sol";
contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
using SafeMath for uint256;
using AddressUtils for address;
using Address for address;
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `IERC721Receiver(0).onERC721Received.selector`

View File

@ -4,7 +4,7 @@ pragma solidity ^0.4.24;
/**
* Utility library of inline functions on addresses
*/
library AddressUtils {
library Address {
/**
* Returns whether the target address is a contract

View File

@ -2,8 +2,8 @@ const { ethGetBalance, ethSendTransaction } = require('./helpers/web3');
const expectEvent = require('./helpers/expectEvent');
const { assertRevert } = require('./helpers/assertRevert');
const SecureTargetBounty = artifacts.require('SecureTargetBounty');
const InsecureTargetBounty = artifacts.require('InsecureTargetBounty');
const SecureInvariantTargetBounty = artifacts.require('SecureInvariantTargetBounty');
const InsecureInvariantTargetBounty = artifacts.require('InsecureInvariantTargetBounty');
require('chai')
.use(require('chai-bignumber')(web3.BigNumber))
@ -17,10 +17,10 @@ const sendReward = async (from, to, value) => ethSendTransaction({
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 () {
beforeEach(async function () {
this.bounty = await SecureTargetBounty.new({ from: owner });
this.bounty = await SecureInvariantTargetBounty.new({ from: owner });
});
it('can set reward', async function () {
@ -53,7 +53,7 @@ contract('Bounty', function ([_, owner, researcher, nonTarget]) {
context('against broken contract', function () {
beforeEach(async function () {
this.bounty = await InsecureTargetBounty.new();
this.bounty = await InsecureInvariantTargetBounty.new();
const result = await this.bounty.createTarget({ from: researcher });
const event = expectEvent.inLogs(result.logs, 'TargetCreated');

View File

@ -1,59 +0,0 @@
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 }));
});
});

View File

@ -1,7 +1,7 @@
const { signMessage, toEthSignedMessageHash } = require('../helpers/sign');
const { expectThrow } = require('../helpers/expectThrow');
const ECRecoveryMock = artifacts.require('ECRecoveryMock');
const ECDSAMock = artifacts.require('ECDSAMock');
require('chai')
.should();
@ -9,9 +9,9 @@ require('chai')
const TEST_MESSAGE = web3.sha3('OpenZeppelin');
const WRONG_MESSAGE = web3.sha3('Nope');
contract('ECRecovery', function ([_, anyone]) {
contract('ECDSA', function ([_, anyone]) {
beforeEach(async function () {
this.mock = await ECRecoveryMock.new();
this.mock = await ECDSAMock.new();
});
it('recover v0', async function () {