Submitted by Ruhum, also found by V_B, adriro, immeas, supernova, MalfurionWhitehat, cccz, and ladboy233
contracts/smart-contract-wallet/SmartAccount.sol#L288
contracts/smart-contract-wallet/SmartAccount.sol#L429-L444
The submitter of a transaction is paid back the transactions gas costs either in ETH or in ERC20 tokens. With ERC20 tokens the following formula is used: $(gasUsed + baseGas) \* gasPrice / tokenGasPriceFactor$. baseGas, gasPrice, and tokenGasPriceFactor are values specified by the tx submitter. Since you dont want the submitter to choose arbitrary values and pay themselves as much as they want, those values are supposed to be signed off by the owner of the wallet. The signature of the user is included in the tx so that the contract can verify that all the values are correct. But, the tokenGasPriceFactor value is not included in those checks. Thus, the submitter is able to simulate the tx with value $x$, get the user to sign that tx, and then submit it with $y$ for tokenGasPriceFactor. That way they can increase the actual gas repayment and steal the users funds.
In encodeTransactionData() we can see that tokenGasPriceFactor is not included:
The value is used to determine the gas repayment in handlePayment() and handlePaymentRevert():
Thats called at the end of execTransaction():
As an example, given that:
You get $(1,000,000 + 100,000) \* 10,000,000,000 / 18 = 6.1111111e14$. If the submitter executes the transaction with tokenGasPriceFactor = 1 they get $1.1e16$ instead, i.e. 18 times more.
tokenGasPriceFactor should be included in the encoded transaction data and thus verified by the users signature.
livingrockrises (Biconomy) confirmed
