This is the report from a security audit performed on TokenTrader by gorbunovperm.
Decentralized trustless ether/ERC20-compliant token exchange contract on the Ethereum blockchain.
In total, 6 issues were reported including:
-
0 high severity issue.
-
3 medium severity issues.
-
0 low severity issues.
-
3 minor observations.
Issues for TestERC20Token.sol
function approve(
address _spender,
uint256 _amount
) returns (bool success) {
allowed[msg.sender][_spender] = _amount;
Approval(msg.sender, _spender, _amount);
return true;
}
When changing the allowance value is it possible to spend previous allowance funds(with high gas price for example) and after it changed spend already new allowance funds.
Change the implementation of approve mechanism. For example, before change allowance you can check if the funds already spent.
Issues for TokenSellerFactory.sol
if (msg.value > (can_sell * sellPrice)) {
change = msg.value - (can_sell * sellPrice);
order = can_sell;
}
if (!ERC20Partial(asset).transfer(msg.sender, order * units)) throw;
In some cases can_sell * sellPrice
may be more than max possible value for uint256
. For example, if sellPrice
is 2^248
and can_sell
is 256
. This can lead to execution of the order almost for free.
Use SafeMath
library.
Issues for TokenTraderFactory.sol
if (!msg.sender.send(order * buyPrice)) throw;
if (!ERC20(asset).transferFrom(msg.sender, address(this), order * units)) throw;
if (msg.value > (can_sell * sellPrice)) {
change = msg.value - (can_sell * sellPrice);
order = can_sell;
}
if (order > 0) {
if (!ERC20(asset).transfer(msg.sender, order * units)) throw;
}
TakerBoughtAsset(msg.sender, msg.value, change, order * units);
In some cases there may be more than max possible value for uint256
. This can lead to execution of the order almost for free.
Use SafeMath
library.
function verify(address tradeContract) constant returns ( /* ... */ ) { /* ... */ }
if (!msg.sender.send(change)) throw;
pragma solidity ^0.4.4;
constant
label for functions is deprecated.throw
is deprecated.- Compiler version is set as "more than"(
pragma solidity ^0.4.4;
). Future versions of the compiler may use constructions not intended by the developer.
- Use
view
label insteadconstant
for functions. - Use
require()
insteadif-throw
constructions. - Set fixed version of the compiler, like this
pragma solidity 0.4.4;
(without^
).
There is several issues in these contracts. One high severity, but in token for testing(is why I marked it as medium severity). And one type of issue in work contracts with medium severity. It is recommended to fix it.