1

I have the following arguments to call a function in a smart contract:

    ERC20Reward[] calldata _erc20Rewards
    ERC721Reward[] calldata _erc721Rewards
    ERC1155Reward[] calldata _erc1155Rewards
    uint256 _nonce
    uint8 _v
    bytes32 _r
    bytes32 _s

What I want to do is to generate a hash with all of them, to check against a mapping that this exact signature has not been used before.

I was thinking of doing something like this:

    mapping(bytes32 => bool) signatures;

    bytes32 s = keccak256(abi.encodePacked(
        _erc20Rewards,
        _erc721Rewards,
        _erc1155Rewards,
        _nonce,
        _v,
        _r,
        _s
    ));

    require(signatures[s] == false);
    
    signatures[s] == true;

The problem I am having with this is that abi.encodePacked does not accept any of these types: ERC20Reward[], ERC721Reward[] and ERC1155Reward[] (struct arrays).

I am getting the following error: Type not supported in packed mode.solidity(9578).

What should I do to be able to include these types in this call? Or is there any other way of achieving this behaviour?

1 Answer 1

0

You should use abi.encode instead, like this:

    bytes32 s = keccak256(abi.encode(
        _erc20Rewards,
        _erc721Rewards,
        _erc1155Rewards,
        _nonce,
        _v,
        _r,
        _s
    ));

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.