Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return value of ERC-20 operations is not checked #51

Closed
c4-bot-6 opened this issue Oct 25, 2024 · 5 comments
Closed

Return value of ERC-20 operations is not checked #51

c4-bot-6 opened this issue Oct 25, 2024 · 5 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working primary issue Highest quality submission among a set of duplicates 🤖_primary AI based primary recommendation 🤖_23_group AI based duplicate group recommendation sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@c4-bot-6
Copy link
Contributor

Lines of code

https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/solidity_contracts/src/CairoPrecompiles/DualVmToken.sol#L269
https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/solidity_contracts/src/CairoPrecompiles/DualVmToken.sol#L353
https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/backend/starknet.cairo#L264

Vulnerability details

Among the ERC20 token behaviors in scope, there is Doesn't revert on failure that is not properly accounted for and has a unique root cause.

The code in scope for the audit directly handles ERC-20s only in the following forms:

  1. the Starknet ERC-20 used in Kakarot's cairo code as native token;
  2. generic Starknet ERC-20s handled within the Kakarot EVM through a DualVmToken wrapper.

As we can see in the snippets from both cases, if the ERC-20 doesn't revert on failure, and instead returns FALSE, the protocol will interpret the failure as a success

File: starknet.cairo
256:     func _transfer_eth{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
257:         token_address: felt, transfers_len: felt, transfers: model.Transfer*
258:     ) {
---          // 🚨 @audit return value is ignored
264:         IERC20.transferFrom(
265:             token_address, transfer.sender.starknet, transfer.recipient.starknet, transfer.amount
266:         );
267:         return _transfer_eth(token_address, transfers_len - 1, transfers + model.Transfer.SIZE);
268:     }
File: DualVmToken.sol
216:     function _approve(uint256 spender, uint256 amount) private {
---          // 🚨 @audit return value is ignored
228:         starknetToken.delegatecallCairo("approve", approveCallData);
229:     }
---
256:     function _transfer(uint256 to, uint256 amount) private {
---          // 🚨 @audit return value is ignored
269:         starknetToken.delegatecallCairo("transfer", transferCallData);
270:     }
---
339:     function _transferFrom(uint256 from, uint256 to, uint256 amount) private {
---          // 🚨 @audit return value is ignored
353:         starknetToken.delegatecallCairo("transfer_from", transferFromCallData);
354:     }

EVM protocols running in Kakarot are therefore at risk of having their accounting broken when interacting through DualVmToken with ERC-20s that don't revert on failures.

A more unlikely, but still possible impact on the Kakarot native token, where Kakarot doesn't revert when failing to settle native tokens transactions, can be achieved when chaining this with other vulnerabilities that we reported separately.

Proof of Concept

  • Deploy a non-standard Starknet ERC-20 token that always returns FALSE
  • Deploy a DualVmToken wrapper for it
  • Make a DualVmToken.transferFrom() EVM call
  • The call will return true despite the underlying returned FALSE

Recommended Mitigation Steps

Consider adding checks for the values returned in the four instances highlighted above.

Assessed type

Other

@c4-bot-6 c4-bot-6 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Oct 25, 2024
c4-bot-8 added a commit that referenced this issue Oct 25, 2024
@c4-bot-11 c4-bot-11 added the 🤖_23_group AI based duplicate group recommendation label Oct 25, 2024
@c4-bot-12 c4-bot-12 added the 🤖_primary AI based primary recommendation label Oct 25, 2024
@howlbot-integration howlbot-integration bot added primary issue Highest quality submission among a set of duplicates sufficient quality report This report is of sufficient quality labels Oct 27, 2024
@ClementWalter
Copy link

Severity: Informative

Comment: Ok see comment dup #43

@ClementWalter ClementWalter added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Nov 4, 2024
@c4-judge c4-judge closed this as completed Nov 8, 2024
@c4-judge c4-judge added the unsatisfactory does not satisfy C4 submission criteria; not eligible for awards label Nov 8, 2024
@c4-judge
Copy link
Contributor

c4-judge commented Nov 8, 2024

dmvt marked the issue as unsatisfactory:
Overinflated severity

@3docSec
Copy link

3docSec commented Nov 10, 2024

Hi @dmvt,

as per the verdict you mentioned, it's worth mentioning that the SC's recommendation was followed: the sponsor opted in for the "does not revert on failure" behavior as per contest README.

This finding clearly mentions the impact that Kakarot will fail to settle the native token transfers, which means loss of funds from account contracts.

We'd therefore kindly ask to reconsider the invalidation of the finding.

@dmvt
Copy link

dmvt commented Nov 12, 2024

I understand and would have considered this a valid low risk. You submitted it as high, so overinflated severity applies. Ruling stands.

ClementWalter added a commit to kkrt-labs/kakarot that referenced this issue Nov 20, 2024
…VMToken (#1616)

code-423n4/2024-09-kakarot-findings#51
code-423n4/2024-09-kakarot-findings#42

Checks the return value for DualVMToken. If the SN call returned false,
panicking the EVM call will make the starknet tx revert as a side
effect.

---------

Co-authored-by: Clément Walter <clement0walter@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working primary issue Highest quality submission among a set of duplicates 🤖_primary AI based primary recommendation 🤖_23_group AI based duplicate group recommendation sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

7 participants