1

I'm exploring Gnosis conditional tokens (which are adapted ERC1155). The _mint method in ERC1155 requires an id that is uint. Gnosis has a method called getPositionId which converts a keccak256 hash into a uint:

    /**
     * @dev Constructs a position ID from a collateral token and an outcome collection
     * @param _collateralToken: ERC20 token collateralizing the position
     * @param _collectionId: ID of the outcome collection associated with this position
     */
    function getPositionId(IERC20 _collateralToken, bytes32 _collectionId) internal pure returns (uint) {
        return uint(keccak256(abi.encodePacked(_collateralToken, _collectionId)));
    }

The return value is used as the id in the _mint function. However, the value is massive (BigNumber) and causes overflow issues while working with hardhat tests.

For example, let:

  • _collateralToken = 0x2Dd78Fd9B8F40659Af32eF98555B8b31bC97A351
  • _collectionId = 0x6f6f41ff811f45c6dfe727fcb2a278f07323fb85ec753bece2f9a690cca7a01d

Then packing these into a keccak256 and then converting to a uint generates the return value of getPositionId:

  • 74229324384859666491956367114251131107901747002219700387957564294760735619703

Now if I wanted to check the balanceOf an address, I need to pass in two parameters:

  • balanceOf(address account, uint256 id)

This requires me to convert the positionId into a uint using positionId.toNumber() but then the overflow error occurs!

Is there a trivial solution I'm overlooking or should I refactor the getPositionId into something more simplistic?

3
  • So the issue you are having is present when you are writing Hardhat test?
    – Sky
    Dec 11, 2022 at 20:02
  • Yes - but it will be present in any frontend dev work because it's a Javascript generated overflow error
    – alpo
    Dec 11, 2022 at 20:08
  • I remember having this issues and solving it by simply sending string instead of number. Instead of number 1000, I would send "1000"
    – Sky
    Dec 11, 2022 at 20:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.