hats-finance / Tapioca--Lending-Engine--0x5bee198f5b060eecd86b299fdbea6b0c07c728dd

Other
0 stars 0 forks source link

MarketERC20::permit lacks of access control, enabling xChain calls relying on permits to be DoSed #15

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

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

Github username: @CergyK Twitter username: -- Submission hash (on-chain): 0x154803094095bc5c6319f596cd6217ccd02f0d3b6a454c7e1f76624ebebdaf45 Severity: medium

Description: Description Any user can call MarketERC20::permit on behalf of an owner,

Attack Scenario\

Recommendation Check that spender is msg.sender (or add a field caller to be checked on).

contracts/market/MarketERC20.sol:

function _permit(
    bool asset, // true = asset, false = collateral
    address owner,
    address spender,
    uint256 value,
    uint256 deadline,
    uint8 v,
    bytes32 r,
    bytes32 s
) internal {
    require(block.timestamp <= deadline, "ERC20Permit: expired deadline");
+   require(msg.sender == spender, "not spender");

    bytes32 structHash;

    structHash = keccak256(
        abi.encode(
            asset ? _PERMIT_TYPEHASH : _PERMIT_TYPEHASH_BORROW, owner, spender, value, _useNonce(owner), deadline
        )
    );

    bytes32 hash = _hashTypedDataV4(structHash);

    address signer = ECDSA.recover(hash, v, r, s);

    require(signer == owner, "ERC20Permit: invalid signature");

    if (asset) {
        _approve(owner, spender, value);
    } else {
        _approveBorrow(owner, spender, value);
    }
}
cryptotechmaker commented 1 month ago

It's a valid issue, but this is used 1 time only to permit pearlmit. I'll mark it as a Low because there's no risk here. However, the suggested fix doesn't seem right. I think a better one would be check if the sender is whitelisted and execute permit with owner param if so, otherwise execute permit with msg.sender instead of owner

maarcweiss commented 4 weeks ago

Hi! We said we were not going to reward lows, but we are going to reward you with 150 USDC as a token of appreciation