tintinweb/solidity-shell

uint128(~0) ?

Elyx0 opened this issue · 1 comments

Elyx0 commented

Maybe it's me but reading https://eips.ethereum.org/EIPS/eip-1155 I see

Inside the contract code the two pieces of data needed to access the individual non-fungible can be extracted with uint128(~0) and the same mask shifted by 128.

But solidity shell throws when inputting uint128(~0) with:

  {
    component: 'general',
    errorCode: '9640',
    formattedMessage: 'TypeError: Explicit type conversion not allowed from "int_const -1" to "uint128".\n' +
      '\n',
    message: 'Explicit type conversion not allowed from "int_const -1" to "uint128".',
    severity: 'error',
    sourceLocation: { end: 276, file: '', start: 265 },
    type: 'TypeError'
  }

Hey @Elyx0,

Looks like the compiler guesses const_int256 for ~0 and a direct type conversion (truncation) from const_int256(-1) -> uint128() is not allowed anymore with solidity 0.8.10. It used to be with solidity 0.6.11 (I guess that was the reference when the EIP was published).

  »  .reset
 »  uint128(~0)
[
  {
    component: 'general',
    errorCode: '9640',
    formattedMessage: 'TypeError: Explicit type conversion not allowed from "int_const -1" to "uint128".\n' +
      '\n',
    message: 'Explicit type conversion not allowed from "int_const -1" to "uint128".',
    severity: 'error',
    sourceLocation: { end: 186, file: '', start: 175 },
    type: 'TypeError'
  }
]
 »  pragma solidity 0.6.11
 »  uint128(~0)
340282366920938463463374607431768211455

this should work (but dblcheck if this is the intended use case)

 »  uint128(int128(~0))
340282366920938463463374607431768211455

PS: the output you get from solidity-shell is the solc compiler error.