SKALE contest - 0x1f8b'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: 6/24

Findings: 4

Award: $5,575.72

🌟 Selected for report: 1

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: cccz

Also found by: 0x1f8b

Labels

bug
duplicate
2 (Med Risk)
sponsor disputed

Awards

2697.0588 USDC - $2,697.06

External Links

Lines of code

https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/schain/tokens/EthErc20.sol#L64

Vulnerability details

Proof of Concept

Using the forceBurn() function of EthErc20, an address with BURNER_ROLE can burn an arbitrary amount of tokens from any address.

We believe this is unnecessary and poses a serious centralization risk.

A malicious or compromised BURNER_ROLE address can take advantage of this.

Consider removing the BURNER_ROLE and change forceBurn() function to:

function forceBurn(uint256 amount) external override { _burn(_msgSender(), amount); }

#0 - cstrangedk

2022-03-04T00:32:38Z

Duplicate of #16, sponsor disputed, see #16

Findings Information

🌟 Selected for report: 0x1f8b

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

Labels

bug
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#L299-L308

Vulnerability details

Proof of Concept

The DepositBoxERC20 contract do not appear to support rebasing/deflationary/inflationary tokens whose balance changes during transfers or over time. The necessary checks include at least verifying the amount of tokens transferred to contracts before and after the actual transfer to infer any fees/interest.

Add support in contracts for such tokens before accepting user-supplied tokens Consider to check before/after balance on the vault.

#0 - cstrangedk

2022-03-08T18:07:17Z

Reference https://github.com/code-423n4/2022-02-skale-findings/issues/8, https://github.com/code-423n4/2022-02-skale-findings/issues/9, https://github.com/code-423n4/2022-02-skale-findings/issues/10, https://github.com/code-423n4/2022-02-skale-findings/issues/12, https://github.com/code-423n4/2022-02-skale-findings/issues/19 #42

Only standard functions are applied to out-of-the-box DepositBoxes and TokenManagers. It's up to the SKALE chain owner's discretion to create custom DepositBoxes/TokenManagers that specifically support non-standard functions like Rebasing/Deflationary/Inflationary tokens, and add these custom contracts to the bridge using registerExtraContract() functions in MessageProxy.

#1 - GalloDaSballo

2022-06-01T16:41:03Z

Because this is reliant on configuration, I believe the finding to be valid and of medium severity.

End users can verify if the DepositBoxes are properly handling rebasing tokens at the time they wish to bridge

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

1220.2645 USDC - $1,220.26

External Links

  1. Used an outdated solidity compiler with known bugs.
  1. It seems that was used an outdated version of openzeppelin, the last version is 4.5.0

"@openzeppelin/contracts-upgradeable": "^4.3.2"

  1. DepositBox whitelist is enabled by default, so it's more a black list than a whitelist.

  2. There are a lack of input checks around the contracts:

  1. The logic applied to emit an event of the change of a variable, does not check that the change is to the same value as the current one, it should be omitted to launch a change event if the defined value is the same, otherwise, the dApps could have wrong logics
  1. Is not possible to change the owner, this is a very bad practice, the private key could be leaked, or the admin could be revoked.

#0 - DimaStebaev

2022-03-14T13:49:35Z

  1. Initialization is performed automatically by a script
  2. It's just an example and should not be used in production

#1 - GalloDaSballo

2022-05-05T14:06:08Z

Used an outdated solidity compiler with known bugs.

Agree because of actual evidence, would recommend the sponsor to update to 0.8.9+ (0.8.11 seems to be fairly used)

It seems that was used an outdated version of openzeppelin, the last version is 4.5.0

I think the finding has validity but I wouldn't stress too much on that, would recommend diffind the codebases for any patches

Depositbox whitelist is enabled by default, so it's more a black list than a whitelist.

Don't think it's a vulnerability

There are a lack of input checks around the contracts:

Finding is valid

The logic applied to emit an event of the change of a variable, does not check that the change is to the same value as the current one, it should be omitted to launch a change event if the defined value is the same, otherwise, the dApps could have wrong logics

Agree but non-critical / informational

Is not possible to change the owner, this is a very bad practice, the private key could be leaked, or the admin could be revoked.

Appreciate the finding, but believe this is a testing contract

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

871.945 USDC - $871.94

External Links

  1. There are require messages bigger than 32 bytes. More than 32 bytes for message will incur an extra gas costs.

MessageProxyForMainnet.sol

Messages.sol:

  1. Change the incremental logic from i++ to ++i in order to save some opcodes:
  1. It's possible to avoid storage access a save gas using immutable keyword for the following variables:
  1. The returns is not used and could be removed in:
  1. Change these methods to inline
  1. Cache the constant value keccak256(xxxxxxxxxxxx) as a constant
  1. Use delete instead of set to default value (false or 0)
  1. allowance not needed. The transferFrom already check the expected amount.
  1. The data variable is assigned, but in the case of isMainChainToken=true, the previous content will be discarded and the calculation could be saved if done inside the else block

#0 - yavrsky

2022-03-14T14:33:26Z

Only marginal gas improvements.

#1 - GalloDaSballo

2022-04-28T15:08:05Z

Require messages gas savings. I'll detail my reasoning here and then link to this for my thoughts.

Ultimately this is saving a small amount of runtime gas but it's saving a pretty hefty amount of gas for deployment.

If we assume that 32bytes costs 20k gas (SSTORE), then each extra char will save 625 gas.

As a convention in this context, I'll rate each shortened message with 2.5k of gas savings although a more correct estimate would be CHAR * 625

Shorten Messages

21 Shortened Messages * 2500 = 52500

i++ to ++i

Saves 3 gas * 25 = 75

### Use of immutable This would not only save the SSTORE but also save on the SLOAD each time the functions are called, in lack of further details I'll give one SLOAD per variable 5 * 2100 = 10500

Unused return

I don't believe this saves gas

Inline 2 functions

Would save 8 * 2 = 16 gas

Cache the constant value keccak256(xxxxxxxxxxxx) as a constant

Would save 30 gas for each time this is done = 30 * 4 = 120

Use delete instead of set to default value (false or 0)

Doesn't save gas

allowance not needed. The transferFrom already check the expected amount.

Agree that the check is not necessary, would save a STATICCALL (100) + a Hot SLOAD (100) = 200 * 2 = 400

The data variable is assigned, but in the case of isMainChainToken=true, the previous content will be discarded and the calculation could be saved if done inside the else block

Skipping the extra computation would save 100 gas (STATICCALL) as well as the cost of copying from memory again (3 * params=4 = 12) 112

Total Gas Saved: 63648

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