VTVL contest - carrotsmuggler's results

Building no-code token management tools to empower web3 founders and investors, starting with token vesting.

General Information

Platform: Code4rena

Start Date: 20/09/2022

Pot Size: $30,000 USDC

Total HM: 12

Participants: 198

Period: 3 days

Judge: 0xean

Total Solo HM: 2

Id: 164

League: ETH

VTVL

Findings Distribution

Researcher Performance

Rank: 126/198

Findings: 2

Award: $27.95

🌟 Selected for report: 0

🚀 Solo Findings: 0

QA

  1. Contract VariableSupplyERC20Token.sol has a variable named maxSupply, which has a different meaning than mintable supply. maxSupply's meaning is closer to mintablesupply + initialsupply, or the ceiling for totalsupply. It is better to rename it to maxMintableSupply or something similar, to make it clear that it is only counting tokens yet to be minted.

Awards

9.0866 USDC - $9.09

Labels

bug
G (Gas Optimization)
edited-by-warden

External Links

Gas

1. VTVLVesting.sol:353: ++i is more efficient than i++

i++ increments i and returns the initial value of i, but ++i returns the actual incremented value skipping the creation of a temporary variable, saving ~5 gas/iteration.

2. VTVLVesting.sol:374,377,381 usrClaim.amountWithdrawn should be cached in memory

require(allowance > usrClaim.amountWithdrawn, "NOTHING_TO_WITHDRAW");
//
uint112 amountRemaining = allowance - usrClaim.amountWithdrawn;
//
usrClaim.amountWithdrawn += amountRemaining;

Multiple use of storage variable costs 100 gas to load from warm state each time. Caching in memory makes future calls cost 3 gas, saving ~97 gas each call. Caching here changes average gas cost from 69082 to 68740 (hardhat gas reporter average)

Use cached value for increment as:

numTokensReservedForVesting = cached + allocatedAmount;

3. VTVLVesting.sol:426,429 usrClaim.amountWithdrawn should be cached in memory

require( _claim.amountWithdrawn < finalVestAmt, "NO_UNVESTED_AMOUNT");
//
uint112 amountRemaining = finalVestAmt - _claim.amountWithdrawn;

Multiple use of storage variable costs 100 gas to load from warm state each time. Caching in memory makes future calls cost 3 gas, saving ~97 gas each call. Caching here changes average gas cost from 36548 to 36451 (hardhat gas reporter average)

4. VTVLVesting.sol:295,301 numTokensReservedForVesting should be cached in memory

require(tokenAddress.balanceOf(address(this)) >= numTokensReservedForVesting + allocatedAmount, "INSUFFICIENT_BALANCE");
//
numTokensReservedForVesting += allocatedAmount; // track the allocated amount

Multiple use of storage variable costs 100 gas to load from warm state each time. Caching in memory makes future calls cost 3 gas, saving ~97 gas each call. Caching here changes average gas cost from 36548 to 36451 (hardhat gas reporter average)

Use cached value for increment as:

numTokensReservedForVesting = cached + allocatedAmount;

5. VTVLVesting.sol:166,167,170 startTimestamp should be cached in memory

if(_referenceTs > _claim.startTimestamp) {
//
uint40 currentVestingDurationSecs = _referenceTs - _claim.startTimestamp; // How long since the start
//
uint40 finalVestingDurationSecs = _claim.endTimestamp - _claim.startTimestamp; // length of the interval

Multiple use of storage variable costs 100 gas to load from warm state each time. Caching in memory makes future calls cost 3 gas, saving ~97 gas each call. Caching here changes average gas cost from 36548 to 36451 (hardhat gas reporter average)

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