Submitted by RadiantLabs, also found by minglei-wang-3570
The DualVmToken is a utility EVM contract allowing Kakarot EVM accounts to operate Starknet ERC-20s via classic balanceOf(), transfer(), etc., operations.
These classic operations are offered in two flavors, one that accepts Starknet addresses (uint256) and one that accepts EVM addresses (address). In case an EVM address is provided, the corresponding Starknet address is looked up through Kakarot first.
If we look at the approve(uint256, ...) function in DualVmToken:
We can see that no check whatsoever is done on the spender input, except for felt overflow at L217.
This means that the provided address could be any Starknet account, including a contract that is not an EVM account, and most importantly including the Kakarot contract.
This is particularly relevant because native token transfers in the Kakarot EVM work under the assumption that Starknet account contracts have infinite approval granted to the Kakarot contract, as we can see from the account_contract initialization:
By removing this approval and attempting to move native tokens, an EVM contract account can jeopardize EVM state finalization (that is where native token transfers are settled on the Starknet ERC20) and cause RPC-level crashes in the Kakarot EVM, regardless of how defensively they were called. Protective measures generally considered safe in the EVM space like ExcessivelySafeCall (which is used in LayerZero cross-chain applications to prevent channel DoSes that can permanently freeze in-flight tokens), can be bypassed by causing a RPC-level Cairo revert.
The following contract can trigger an RPC-level revert whenever called with any calldata, assuming that target is initialized with the DualVmToken associated to Kakarots native ERC20.
Consider adding the following check to the DualVmToken.approve function:
ClementWalter (Kakarot) confirmed and commented:
LSDan (judge) decreased severity to Medium and commented:
EV_om (warden) commented:
LSDan (judge) commented:
Kakarot mitigated:
Status: Mitigation confirmed.
