SKALE contest - gzeon's results

The only Ethereum native multichain scaling network.

General Information

Platform: Code4rena

Start Date: 18/02/2022

Pot Size: $125,000 USDC

Total HM: 13

Participants: 24

Period: 14 days

Judge: GalloDaSballo

Total Solo HM: 6

Id: 88

League: ETH

SKALE

Findings Distribution

Researcher Performance

Rank: 10/24

Findings: 4

Award: $3,245.99

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: IllIllI

Also found by: gzeon, kirk-baird

Labels

bug
duplicate
2 (Med Risk)
sponsor disputed

Awards

1618.2353 USDC - $1,618.24

External Links

Lines of code

https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/mainnet/DepositBoxes/DepositBoxERC20.sol#L196

Vulnerability details

Impact

After a schain is killed by both the owner and the IMA admin, schain admin can control all the fund using e.g. DepositBoxERC20.getFunds functions. This pose a significant centralization risk after the schain is killed.

Proof of Concept

https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/mainnet/DepositBoxes/DepositBoxERC20.sol#L196

function getFunds(string calldata schainName, address erc20OnMainnet, address receiver, uint amount) external override onlySchainOwner(schainName) whenKilled(keccak256(abi.encodePacked(schainName))) { bytes32 schainHash = keccak256(abi.encodePacked(schainName)); require(transferredAmount[schainHash][erc20OnMainnet] >= amount, "Incorrect amount"); _removeTransferredAmount(schainHash, erc20OnMainnet, amount); require( ERC20Upgradeable(erc20OnMainnet).transfer(receiver, amount), "Transfer was failed" ); }

Require both the owner and IMA admin on the fund distribution process.

#0 - cstrangedk

2022-03-09T00:09:30Z

Issue here incorrectly assumes that the owner is a centralized authority. SKALE Chain owners may be a DAO, multisig, or single owner - the IMA bridge is agnostic to, and cannot control the governance structure adopted in each SKALE Chain. The responsibility and process conducted after kill is executed rests on the Owner and whatever governance structure is adopted.

#1 - GalloDaSballo

2022-06-01T18:32:35Z

Dup of #76

Findings Information

🌟 Selected for report: 0x1f8b

Also found by: IllIllI, cmichel, gzeon, kirk-baird

Labels

bug
duplicate
2 (Med Risk)
sponsor disputed

Awards

786.4623 USDC - $786.46

External Links

Lines of code

https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/mainnet/DepositBoxes/DepositBoxERC20.sol#L118

Vulnerability details

Impact

The transfered amount is saved without checking the actual amount of token received after the transfer.

Proof of Concept

https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/mainnet/DepositBoxes/DepositBoxERC20.sol#L118

_saveTransferredAmount(schainHash, erc20OnMainnet, amount); require( ERC20Upgradeable(erc20OnMainnet).transferFrom( msg.sender, address(this), amount ), "Transfer was failed" );

Check before and after balance

#0 - cstrangedk

2022-03-04T00:38:55Z

Duplicate and disputed of #42

#1 - GalloDaSballo

2022-06-01T16:50:21Z

Dup of #50

Findings Information

🌟 Selected for report: defsec

Also found by: 0x1f8b, 0xwags, cmichel, csanuragjain, gzeon, jayjonah8, kenta, kirk-baird, kyliek, leastwood, rfa, robee, ye0lde

Labels

bug
QA (Quality Assurance)

Awards

662.802 USDC - $662.80

External Links

Schain owner can censor user by not distributing sFUEL

SKALE chains operate in a gas-free environment using a native gas token called sFUEL. sFUEL has no economic value and is allocated from the SKALE chain owner

It is possible for schain owner to censor user / freeze user fund by not distributing enough sFUEL

setMinTransactionGas lack minimum value

Since the base Tx gas cost is 21000, some global minimum can be hardcoded to avoid misconfiguration https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/mainnet/CommunityPool.sol#196

_balanceIsSufficient use current tx.gasprice but the actual gasprice node will pay is unknown

https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/mainnet/CommunityPool.sol#220

Upgrade Solidity Version

Recommended to upgrade to latest Solidity 0.8.12

Unresolved TODO

contracts/schain/CommunityLocker.sol:219: // TODO: uncomment when oracle finished

Out-of-order encode-decode function

Some of the decode function is not adjacent to its encode counterpart, which make reading the code a bit annoying (e.g. encodeTransferErc20Message and decodeTransferErc20Message) https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/Messages.sol

depositERC20 lack input validation

DepositBoxERC20.depositERC20() did not check if amount!=0 https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/mainnet/DepositBoxes/DepositBoxERC20.sol

#0 - DimaStebaev

2022-03-14T14:07:25Z

Agreed.

#1 - GalloDaSballo

2022-05-05T14:42:53Z

Schain owner can censor user by not distributing sFUEL

Given that this is effectively a design decision, I agree with Low Severity

setMinTransactionGas lack minimum value

Agree with lack of validation given rational values

_balanceIsSufficient use current tx.gasprice but the actual gasprice node will pay is unknown

Would have liked to see this finding more developed

Upgrade Solidity Version

In lack of explanation I am not going to count this finding

Out-of-order encode-decode function

That's like, your opinion man.

depositERC20 lack input validation

Valid

Findings Information

🌟 Selected for report: IllIllI

Also found by: 0x1f8b, CertoraInc, TerrierLover, Tomio, WatchPug, d4rk, gzeon, kenta, kyliek, m_smirnova2020, rfa, robee, saian, ye0lde

Labels

bug
G (Gas Optimization)

Awards

178.4876 USDC - $178.49

External Links

> 0 is less efficient than != 0 for uint in require condition

Ref: https://twitter.com/GalloDaSballo/status/1485430908165443590 https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/mainnet/DepositBoxes/DepositBoxEth.sol#L122

require(approveTransfers[msg.sender] > 0, "User has insufficient ETH");

Reuse value from storage

https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/mainnet/CommunityPool.sol#L98

uint userWalletBal = _userWallets[user][schainHash]; if (amount > userWalletBal) { amount = userWalletBal; _userWallets[user][schainHash] = 0; }else{ _userWallets[user][schainHash] = userWalletBal - amount; }

https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/mainnet/CommunityPool.sol#L171

uint userWalletBal = _userWallets[msg.sender][schainHash]; require(amount <= userWalletBal, "Balance is too low"); require(!messageProxy.messageInProgress(), "Message is in progress"); _userWallets[msg.sender][schainHash] = userWalletBal - amount;

Precalc keeack constant

The keccak256(abi.encodePacked("Mainnet")) can be precalculated as constant https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/mainnet/DepositBox.sol

Save gas by using schainName hash as input directly

It is a bit wasteful to use string schainName as input and hash it repeatedly onchain

Optimistic erc20 transfer

Can save some gas by skiping the balance check and let it revert during the transfer https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/mainnet/DepositBoxes/DepositBoxERC20.sol#L157

require(ERC20Upgradeable(message.token).balanceOf(address(this)) >= message.amount, "Not enough money");

#0 - yavrsky

2022-03-14T15:06:18Z

Only marginal gas improvements.

#1 - GalloDaSballo

2022-04-28T16:40:44Z

> 0 is less efficient than != 0 for uint in require condition

Saves 3 gas

Reuse value from storage

100 gas saved * 2 = 200

Precalc keeack constant

Saves 30 gas for the calculation

Save gas by using schainName hash as input directly

Would have liked to see further detail here, as there's potential downsides to applying this advice, for this reason will not give it any points

Optimistic erc20 transfer

Agree, this would save STATICCALL + the Storage check = 200 gas

#2 - GalloDaSballo

2022-04-28T16:40:58Z

Total Gas Saved 433

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter