hats-finance / Tapioca-0xe0b920d38a0900af3bab7ff0ca0af554129f54ad

1 stars 2 forks source link

Cross-chain replay attacks are possible in `getTypedDataHash` #27

Open hats-bug-reporter[bot] opened 1 month ago

hats-bug-reporter[bot] commented 1 month ago

Github username: @mgf15 Twitter username: -- Submission hash (on-chain): 0x2f20ea88bd1feeb1f9e98b69455e0763b8d6a5521b2dd902820013b36148c9ac Severity: medium

Description: Description\ Mistakes made on one chain can be re-applied to a new chain Attack Scenario\ There is no chain.id in the signed data Attachments

  1. Proof of Concept (PoC) File
function getTypedDataHash(ERC20PermitStruct calldata _permitData) public view returns (bytes32) {
        bytes32 permitTypeHash_ =
            keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");

        bytes32 structHash_ = keccak256(
            abi.encode(
                permitTypeHash_,
                _permitData.owner,
                _permitData.spender,
                _permitData.value,
                _permitData.nonce,
                _permitData.deadline
            )
        );
        return _hashTypedDataV4(structHash_);
    }
  1. Revised Code File (Optional)
0xRektora commented 4 weeks ago

This is not possible. Pearlmit uses hashTypedDataV4 from OZ which account for chain id, contract name and version.

    function _checkPermitBatchApproval(IPearlmit.PermitBatchTransferFrom calldata batch, bytes32 hashedData) internal {
        bytes32 digest = _hashTypedDataV4(PearlmitHash.hashBatchTransferFrom(batch, _masterNonces[batch.owner]));
       ...