code4rena-2023-01-biconomy-h06

[H-06] FeeRefund.tokenGasPriceFactor is not included in signed transaction data allowing the submitter to steal funds

보고서

Summary

Relayer가 환급받을 Gas 양을 계산하는 데에 User가 지정한 값이 이용된다. 이 값을 서명으로 확인하지 않아 Relayer가 조작할 수 있다. 이를 통해 계산을 조작하여 더 많은 양의 토큰을 Gas 비용으로 받아낼 수 있다.

Keyword

theft, input validation, relayer, gas

Vulnerability

Relayer는 가스를 반환받는다. 반환받을 가스를 계산하는 로직은 (gasUsed + baseGas) * gasPrice / tokenGasPriceFactor 이다. 이 때, baseGas, gasPrice, tokenGasPriceFactor 값은 트랜잭션 제출자(=Wallet 소유자)가 지정한 값이다. 따라서 이 값 역시 서명을 통하여 Wallet 소유자가 요청한 값이 맞는지를 확인할 필요가 있다. 하지만 서명 확인에 tokenGasPriceFactor 값에 대한 확인이 빠져있다.

function encodeTransactionData(
    Transaction memory _tx,
    FeeRefund memory refundInfo,
    uint256 _nonce
) public view returns (bytes memory) {
    bytes32 safeTxHash =
        keccak256(
            abi.encode(
                ACCOUNT_TX_TYPEHASH,
                _tx.to,
                _tx.value,
                keccak256(_tx.data),
                _tx.operation,
                _tx.targetTxGas,
                refundInfo.baseGas,
                refundInfo.gasPrice,
                refundInfo.gasToken,
                refundInfo.refundReceiver,
                _nonce
            )
        );
    return abi.encodePacked(bytes1(0x19), bytes1(0x01), domainSeparator(), safeTxHash);
}

따라서 Relayer가 임의로 tokenGasPriceFactor 값을 낮추어 실행할 수 있다. 이에 따라 Relayer는 원래 받아야 하는 Gas 양보다 많은 Gas를 획득할 수 있다.

Impact

Relayer가 트랜잭션을 실행하는 유저의 토큰을 일부 탈취할 수 있다.

Mitigation

tokenGasPriceFactor 값을 Signature 확인 대상 데이터에 포함하여 확인한다.


tags: bughunting, smart contract, biconomy, account abstraction, erc4337, crypto theft, lack-of-input-validation-vul, gas refund, gas, account abstraction bundler, wallet, severity high