xTRIBE contest - Scocco's results

A TRIBE tokenomic upgrade with multi-delegation, autocompounding rewards, and reward delegation

General Information

Platform: Code4rena

Start Date: 21/04/2022

Pot Size: $75,000 USDC

Total HM: 7

Participants: 45

Period: 7 days

Judge: 0xean

Total Solo HM: 5

Id: 111

League: ETH

Tribe

Findings Distribution

Researcher Performance

Rank: 34/45

Findings: 1

Award: $81.64

🌟 Selected for report: 0

šŸš€ Solo Findings: 0

Awards

81.6446 USDC - $81.64

Labels

bug
G (Gas Optimization)
sponsor acknowledged

External Links

Bad Comparison with Zero

Impact

In If conditionals, prefer to use !=0 than > 0 when possible to save Gas

Proof of Concept

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L167

167┆ if (oldRewardBalance > 0) {
168┆     rewardToken.safeTransferFrom(address(flywheelRewards), address(newFlywheelRewards), oldRewardBalance);
169┆ }

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L218

218┆ if (strategyRewardsAccrued > 0) {

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L467

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L487

467┆ if (weight > 0) {
⋮┆----------------------------------------
487┆ if (weight > 0) {

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L287

287┆ if (pos > 0 && ckpts[pos - 1].fromBlock == block.number) {

Tools Used

Static code analysis

Replace the > 0 to != 0

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L167

167┆ if (oldRewardBalance != 0) {

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L218

218┆ if (strategyRewardsAccrued != 0) {

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L467

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L487

467┆ if (weight != 0) {
⋮┆----------------------------------------
487┆ if (weight != 0) {

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L287

287┆ if (pos != 0 && ckpts[pos - 1].fromBlock == block.number) {

Postfix to Prefix

Impact

There is no risk of overflow caused by increasing the iteration index in for loops (the ++i in for (uint256 i = 0; i < numIterations; ++i)), but increments perform overflow checks that are not needed in this case.

So, to save gas, prefer ++i to i++ in loops.

Proof of Concept

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L189

189┆ for (uint256 i = 0; i < size; i++) {

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L346

346┆ for (uint256 i = 0; i < size && (userFreeVotes + totalFreed) < votes; i++) {

Tools Used

Static code analysis

To save gas, prefer ++i to i++ in loops.

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L189

189┆ for (uint256 i = 0; i < size; ++i) {

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L346

346┆ for (uint256 i = 0; i < size && (userFreeVotes + totalFreed) < votes; ++i) {
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