User can redirect fees by using a proxy contract
The fee-refund mechanism credits the transaction's recipient address, and anyone can register any address with the Turnstile contract. An attacker could therefore route transactions through their own proxy contract so that the gas refunds meant for an application are paid to them instead.
Ruhum Follow with ronnyx2017 and hihen
Originally disclosed on Code4rena
Submitted by Ruhum, also found by ronnyx2017 and hihen
https://github.com/code-423n4/2022-11-canto/blob/main/CIP-001/src/Turnstile.sol#L86-L101
https://github.com/code-423n4/2022-11-canto/blob/main/Canto/x/csr/keeper/evm_hooks.go#L51
Impact
For any given tx, the fees are sent to its recipient (To). Anybody can register an address using the Turnstile contract. Thus, a user is able to create a proxy contract with which they execute other smart contracts. That way, the fees are sent to their own contract instead of the actual application they are using. People who use smart contract wallets don’t even have to bother with setting up a proxy structure. They just add their own wallet to the Turnstile contract.
Also, there might be a possibility of someone setting up a proxy for high-usage contracts where the fees are sent back to the caller. So for contract $X$, we create $X'$ which calls $X$ for the caller. Since $X'$ is the recipient of the tx, it gets the gas refund. To incentivize the user to use $X'$ instead of $X$, $X'$ sends a percentage of the refund to the caller. The feasibility both technically and economically depends on the contract that is attacked. But, theoretically, it’s possible.
The incentive to take it for yourself instead of giving it to the app is pretty high. Since this causes a loss of funds for the app I rate it as HIGH.
Proof of Concept
Registering an address is permissionless:
function register(address _recipient) public onlyUnregistered returns (uint256 tokenId) {
address smartContract = msg.sender;
if (_recipient == address(0)) revert InvalidRecipient();
tokenId = _tokenIdTracker.current();
_mint(_recipient, tokenId);
_tokenIdTracker.increment();
emit Register(smartContract, _recipient, tokenId);
feeRecipient[smartContract] = NftData({
tokenId: tokenId,
registered: true
});
}
Fees are sent to the recipient of the tx:
func (h Hooks) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *ethtypes.Receipt) error {
// Check if the csr module has been enabled
params := h.k.GetParams(ctx)
if !params.EnableCsr {
return nil
}
// Check and process turnstile events if applicable
h.processEvents(ctx, receipt)
contract := msg.To()
if contract == nil {
return nil
}
// ...
Recommended Mitigation Steps
It’s pretty difficult to fix this properly. The ideal solution is to distribute fees according to each contract’s gas usage. That will be a little more complicated to implement. Also, you have to keep an eye on whether it incentivizes developers to make their contracts less efficient. Another solution is to make this feature permissioned so that only select contracts are allowed to participate. For example, you could say that an address has to be triggered $X$ amount of times before it is eligible for gas refunds.
tkkwon1998 (Canto) acknowledged and commented:
We acknowledge this as true, but it’s a drawback that was discussed during the design of CSR.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the refund is paid to the transaction recipient rather than to the contract whose code actually did the work, and registration of recipients is permissionless.
Impact
Applications lose the fee refunds they expected, and the report rates this as a high-severity loss of funds, though the proxy-for-hire scheme's feasibility is only theoretical and depends on the contract attacked.
What the attacker needed
Ability to deploy a contract; permissionless registration open
The fix
The report suggests distributing fees according to each contract's gas usage, or making the feature permissioned so only contracts triggered a certain number of times qualify; the project acknowledged the issue as a known design drawback.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Some blockchains give back part of the transaction fee to a smart contract that is used a lot. Here, the refund goes to whoever is listed as the receiver of the transaction, and anyone is allowed to sign up an address for refunds. So a person can put their own contract in the middle, use the real app through it, and collect the refund that was meant for the app.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.