question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can not detect Bec.sol int overflow

See original GitHub issue

Describe the bug Try ./myth -x Bec.sol. But no excepted report given, the only thing is the bellow. I am not sure if I missed some options, can anyone help?

==== Exception state ====
Type: Informational
Contract: BecToken
Function name: **ambiguous** t
PC address: 5260
A reachable exception (opcode 0xfe) has been detected. This can be caused by type errors, division by zero, out-of-bounds array access, or assert violations. This is acceptable in most situations. Note however that `assert()` should only be used to check invariants. Use `require()` for regular input checking. 
--------------------
In file: solidity_examples/BECToken.sol:28

assert(c >= a)

--------------------

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
muellerberndtcommented, Jul 23, 2018

Hmm, we don’t do multi-transactional analysis yet (it’s being implemented in #355) so it shouldn’t matter.

0reactions
JoranHonigcommented, Jul 23, 2018

Update:

pragma solidity ^0.4.16;
/**
 * @title SafeMath
 * @dev Math operations with safety checks that throw on error
 */
library SafeMath {
  function sub(uint256 a, uint256 b) internal constant returns (uint256) {
    assert(b <= a);
    return a - b;
  }

  function add(uint256 a, uint256 b) internal constant returns (uint256) {
    uint256 c = a + b;
    assert(c >= a);
    return c;
  }
}
/**
 * @title Ownable
 * @dev The Ownable contract has an owner address, and provides basic authorization control
 * functions, this simplifies the implementation of "user permissions".
 */
contract Ownable {
  address public owner;


  event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);


  /**
   * @dev The Ownable constructor sets the original `owner` of the contract to the sender
   * account.
   */
  function Ownable() {
    owner = msg.sender;
  }


  /**
   * @dev Throws if called by any account other than the owner.
   */
  modifier onlyOwner() {
    require(msg.sender == owner);
    _;
  }


  /**
   * @dev Allows the current owner to transfer control of the contract to a newOwner.
   * @param newOwner The address to transfer ownership to.
   */
  function transferOwnership(address newOwner) onlyOwner public {
    require(newOwner != address(0));
    OwnershipTransferred(owner, newOwner);
    owner = newOwner;
  }
}


/**
 * @title Pausable
 * @dev Base contract which allows children to implement an emergency stop mechanism.
 */
contract Pausable is Ownable {
  event Pause();
  event Unpause();

  bool public paused = false;


  /**
   * @dev Modifier to make a function callable only when the contract is not paused.
   */
  modifier whenNotPaused() {
    require(!paused);
    _;
  }

  /**
   * @dev Modifier to make a function callable only when the contract is paused.
   */
  modifier whenPaused() {
    require(paused);
    _;
  }

  /**
   * @dev called by the owner to pause, triggers stopped state
   */
  function pause() whenNotPaused public {
    paused = true;
    Pause();
  }

  /**
   * @dev called by the owner to unpause, returns to normal state
   */
  function unpause() whenPaused public {
    paused = false;
    Unpause();
  }
}

contract IntegerOverflow2 is Pausable{
    using SafeMath for uint256;
    uint256 public count = 7;
    mapping(address => uint256) balances;


//     function run(uint256 input, uint256 _value, address[] _receivers) public whenNotPaused {
//         uint256 cnt = 2;
//
//         require(cnt > 0 && cnt <= 20);
//         require(_value > 0 && balances[msg.sender] >= _value);
//         balances[msg.sender] = balances[msg.sender].sub(_value);
//
//         for (uint i = 0; i < cnt; i++) {
//             balances[_receivers[i]] = balances[_receivers[i]].add(_value);
//         }
//
//         count *= input;
//    }
//
  function batchTransfer(address[] _receivers, uint256 _value) public {
    uint cnt = _receivers.length;
    uint256 amount = uint256(cnt) * _value;

    require(cnt > 0 && cnt <= 20);

    balances[msg.sender] -= amount;
  }

}
pragma solidity ^0.4.16;
/**
 * @title SafeMath
 * @dev Math operations with safety checks that throw on error
 */
library SafeMath {
  function sub(uint256 a, uint256 b) internal constant returns (uint256) {
    assert(b <= a);
    return a - b;
  }

  function add(uint256 a, uint256 b) internal constant returns (uint256) {
    uint256 c = a + b;
    assert(c >= a);
    return c;
  }
}
/**
 * @title Ownable
 * @dev The Ownable contract has an owner address, and provides basic authorization control
 * functions, this simplifies the implementation of "user permissions".
 */
contract Ownable {
  address public owner;


  event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);


  /**
   * @dev The Ownable constructor sets the original `owner` of the contract to the sender
   * account.
   */
  function Ownable() {
    owner = msg.sender;
  }


  /**
   * @dev Throws if called by any account other than the owner.
   */
  modifier onlyOwner() {
    require(msg.sender == owner);
    _;
  }


  /**
   * @dev Allows the current owner to transfer control of the contract to a newOwner.
   * @param newOwner The address to transfer ownership to.
   */
  function transferOwnership(address newOwner) onlyOwner public {
    require(newOwner != address(0));
    OwnershipTransferred(owner, newOwner);
    owner = newOwner;
  }
}


/**
 * @title Pausable
 * @dev Base contract which allows children to implement an emergency stop mechanism.
 */
contract Pausable is Ownable {
  event Pause();
  event Unpause();

  bool public paused = false;


  /**
   * @dev Modifier to make a function callable only when the contract is not paused.
   */
  modifier whenNotPaused() {
    require(!paused);
    _;
  }

  /**
   * @dev Modifier to make a function callable only when the contract is paused.
   */
  modifier whenPaused() {
    require(paused);
    _;
  }

  /**
   * @dev called by the owner to pause, triggers stopped state
   */
  function pause() whenNotPaused public {
    paused = true;
    Pause();
  }

  /**
   * @dev called by the owner to unpause, returns to normal state
   */
  function unpause() whenPaused public {
    paused = false;
    Unpause();
  }
}

contract IntegerOverflow2 is Pausable{
    using SafeMath for uint256;
    uint256 public count = 7;
    mapping(address => uint256) balances;


//     function run(uint256 input, uint256 _value, address[] _receivers) public whenNotPaused {
//         uint256 cnt = 2;
//
//         require(cnt > 0 && cnt <= 20);
//         require(_value > 0 && balances[msg.sender] >= _value);
//         balances[msg.sender] = balances[msg.sender].sub(_value);
//
//         for (uint i = 0; i < cnt; i++) {
//             balances[_receivers[i]] = balances[_receivers[i]].add(_value);
//         }
//
//         count *= input;
//    }
//
  function batchTransfer(address[] _receivers, uint256 _value) public {
    uint cnt = _receivers.length;
    uint256 amount = uint256(cnt) * _value;

    require(cnt > 0 && cnt <= 20);

    balances[msg.sender] -= amount;
  }

}

Minimal contract that cannot be solved with increased max-depth and solve timeout

Read more comments on GitHub >

github_iconTop Results From Across the Web

BEC BatchOverflow: Could not detect the Integer Overflow in ...
Hi @vietlq . Currently, Oyente only detects overflow caused by addition. Will consider adding support for other operations like: multiplication, ...
Read more >
Integer Overflow in Ethereum - Valid Network
In some cases, you can deduce that an overflow has occurred from the values that are stored after the execution of the transaction....
Read more >
Detecting integer arithmetic bugs in Ethereum smart contracts
In this article, I'll show how to detect batchOverflow and similar issues in both Solidity source code and contract instances on the Ethereum ......
Read more >
Ethereum Smart Contracts Vulnerabilities: Integer Overflow ...
1) BeautyChain (BEC) contract is a great example of using an integer overflow as a vulnerability to perform an attack on a contract....
Read more >
SWC-101 · Overview
An overflow/underflow happens when an arithmetic operation reaches the maximum or minimum size of a type. For instance if a number is stored...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found