provable-things / ethereum-api

Provable API for Ethereum smart contracts
https://docs.provable.xyz/#ethereum
MIT License
801 stars 427 forks source link

This does not work in solidity 0.8.0 #102

Closed MoMannn closed 3 years ago

MoMannn commented 3 years ago

https://github.com/provable-things/ethereum-api/blob/9f34daaa550202c44f48cdee7754245074bde65d/provableAPI_0.6.sol#L1028

Looks like it fails because of 0.8 math underflow/overflow detection in [k--].

MoMannn commented 3 years ago

This is a revised version that works in 0.8.0

 function uint2str(
  uint256 _i
)
  internal
  pure
  returns (string memory str)
{
  if (_i == 0)
  {
    return "0";
  }
  uint256 j = _i;
  uint256 length;
  while (j != 0)
  {
    length++;
    j /= 10;
  }
  bytes memory bstr = new bytes(length);
  uint256 k = length;
  j = _i;
  while (j != 0)
  {
    bstr[--k] = bytes1(uint8(48 + j % 10));
    j /= 10;
  }
  str = string(bstr);
}
eduardoamdev commented 2 years ago

It works perfectly with in 0.8.0. Thank you very much!!!