Coder Social home page Coder Social logo

balancer-core's People

Contributors

bun919tw avatar camelwater avatar dependabot-preview[bot] avatar fernandomartinelli avatar mhchia avatar mikemcdonald avatar montyly avatar nmushegian avatar stanleyding avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

balancer-core's Issues

Add deployment script

  1. Deploy the contract to Ropsten.
  2. Verify the contract on etherscan.
  3. Register thegraph for the deployed contract.
  4. Modify our frontend code to fetch data from our thegraph API.

Add error message back

What is wrong?

Error messages are removed to let us have more space to add new functions. Find out a way to add some messages back.

Slither: incorrect-equality error in #18

#18slither failed。在這 PR 中,我們在 gulp 中對 IERC20(token).balanceOf(address(this)) 的結果運算,在看似無關的地方觸發了 slither 的 incorrect-equality 錯誤。

Error message

$ slither . --filter-paths "test" --exclude=naming-convention,unused-state,solc-version,constable-states,external-function,reentrancy-events

...
INFO:Detectors:
BNum.bdiv(uint256,uint256) (BNum.sol#75-86) uses a dangerous strict equality:
        - require(bool)(a == 0 || c0 / a == BONE) (BNum.sol#81)
BNum.bmul(uint256,uint256) (BNum.sol#63-73) uses a dangerous strict equality:
        - require(bool)(a == 0 || c0 / a == b) (BNum.sol#68)
BNum.bpow(uint256,uint256) (BNum.sol#108-126) uses a dangerous strict equality:
        - remain == 0 (BNum.sol#120)
BNum.bpowApprox(uint256,uint256,uint256) (BNum.sol#128-161) uses a dangerous strict equality:
        - term == 0 (BNum.sol#149)
Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#dangerous-strict-equalities
INFO:Slither:. analyzed (16 contracts with 40 detectors), 4 result(s) found
INFO:Slither:Use https://crytic.io/ to get access to additional detectors and Github integration
...

試著 debug 後發現 slither 會偵測「有沒有 balance 在 require 中被用 == 比較」,因此我猜測有被丟到 BNum.bdivBNum.bmulBNum.bpow 、及 BNum.bpowApprox 的參數,在這 PR 後被標記為是 balance。因為這些函數會對這些參數做像是 BNum.bmulrequire(a == 0 || c0 / a == b) 這種違反 incorrect-equality 的行為。

目前我傾向先讓 slither 忽略 incorrect-equality 不檢查,因為要 debug 需要滿多時間的,然後感覺問題很可能是在 slither。

Reference

  • slither 中做標記 balance 的 code

Add `collectTotalReserves`

In #1 , we have totalReserves storing all reserved fees. Eventually, we transfer all these tokens in all pools back to an address provided by BFactory.

Possible structure

BFactory

contract BFactory {
    ...
    function getReservesAddress() returns (address);
    // Can only be called by the admin who deployed this contract.
    function setReservesAddress(address reservesAddress);
    // Transfer the reserves tokens in `pool` to the `reservesAddress`.
    function collectTokens(BPool pool);
}

BPool

contract BPool {
    ...
    function withdrawReserves(address reserveAddress) {
        require(msg.sender == _factory);
        for (t in _tokens) {
            // transfer reserves tokens to `reserveAddress`
            ...
        }
    }
}

Avoid calling `collect` with unknown pool address

TL;DR

Don't call BFactory.collect(BPool pool) because

  1. This way we avoid any security concerns.
  2. We don't need to call it anyway since the exit fee is zero.

What's wrong

BPool.drainTotalReserves should be secure in most of the condition thanks to the guard at

require(msg.sender == _factory);

However, a possible attack is to to make BFactory call another malicious contract and then this contract calls BPool.drainTotalReserves through a delegate call. This way, msg.sender in BPool.drainTotalReserves will be _factory and require is bypassed. Thus, we should prevent BFactory from calling any contract we don't know. Currently, BFactory calls other contracts in the following snippets:

  1. In BFactory.newBPool
    bpool.setController(msg.sender);

This is fine because bpool is created by BFactory and the code is known to us.

  1. In BFactory.collect
    uint collected = IERC20(pool).balanceOf(address(this));
    bool xfer = pool.transfer(_blabs, collected);

This is possibly manipulated if pool is a contract with malicious/malformed balanceOf or transfer. If it calls any pool's drainTotalReserves with delegatecall, totalReserves can be withdrawn to attackers address.

  1. In BFactory.collectTokenReserves
    pool.drainTotalReserves(_reservesAddress);

This is fine because we have require(_isBPool[address(pool)]) guarding us, which is only passed through when pool is one of our pools.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.