浏览代码

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
Leo Arias 7 年之前
父节点
当前提交
2441fd7d17

+ 0 - 31
contracts/LimitBalance.sol

@@ -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);
-    _;
-
-  }
-
-}

+ 2 - 2
contracts/access/SignatureBouncer.sol

@@ -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;

+ 4 - 4
contracts/Bounty.sol → contracts/bounties/BreakInvariantBounty.sol

@@ -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;
 

+ 1 - 1
contracts/ECRecovery.sol → contracts/cryptography/ECDSA.sol

@@ -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

+ 0 - 0
contracts/MerkleProof.sol → contracts/cryptography/MerkleProof.sol


+ 1 - 1
contracts/mocks/AutoIncrementingImpl.sol

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

+ 3 - 3
contracts/mocks/ECRecoveryMock.sol → contracts/mocks/ECDSAMock.sol

@@ -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

+ 20 - 0
contracts/mocks/InsecureInvariantTargetBounty.sol

@@ -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();
+  }
+}

+ 0 - 17
contracts/mocks/InsecureTargetBounty.sol

@@ -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();
-  }
-}

+ 0 - 13
contracts/mocks/LimitBalanceMock.sol

@@ -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 {
-  }
-
-}

+ 1 - 1
contracts/mocks/MerkleProofWrapper.sol

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

+ 1 - 1
contracts/mocks/ReentrancyMock.sol

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

+ 20 - 0
contracts/mocks/SecureInvariantTargetBounty.sol

@@ -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();
+  }
+}

+ 0 - 17
contracts/mocks/SecureTargetBounty.sol

@@ -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();
-  }
-}

+ 2 - 2
contracts/token/ERC721/ERC721Basic.sol

@@ -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`

+ 1 - 1
contracts/AddressUtils.sol → contracts/utils/Address.sol

@@ -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

+ 0 - 0
contracts/AutoIncrementing.sol → contracts/utils/AutoIncrementing.sol


+ 0 - 0
contracts/ReentrancyGuard.sol → contracts/utils/ReentrancyGuard.sol


+ 5 - 5
test/Bounty.test.js → test/BreakInvariantBounty.test.js

@@ -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');

+ 0 - 59
test/LimitBalance.test.js

@@ -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 }));
-  });
-});

+ 3 - 3
test/library/ECRecovery.test.js → test/library/ECDSA.test.js

@@ -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 () {