Platform: Code4rena
Start Date: 05/05/2022
Pot Size: $125,000 DAI
Total HM: 17
Participants: 62
Period: 14 days
Judge: leastwood
Total Solo HM: 15
Id: 120
League: ETH
Rank: 25/62
Findings: 2
Award: $305.02
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: IllIllI
Also found by: 0x1f8b, 0x4non, 0xDjango, 0xNazgul, 0xkatana, 0xsomeone, AuditsAreUS, BouSalman, BowTiedWardens, Cityscape, Funen, GimelSec, Hawkeye, JC, MaratCerby, MiloTruck, Picodes, Ruhum, TerrierLover, WatchPug, Waze, bobirichman, catchup, cccz, cryptphi, csanuragjain, delfin454000, ellahi, fatherOfBlocks, hake, horsefacts, hyh, jayjonah8, joestakey, kebabsec, kenta, mics, oyc_109, robee, samruna, shenwilly, sikorico, simon135, throttle, tintin
178.4612 DAI - $178.46
Severity: Low
Context: gALCX.sol#L39-L41
, gALCX.sol#L46-L59
Description: Several functions update critical parameters that are missing event emission. These should be performed to ensure tracking of changes of such critical parameters.
Recommendation: Add events to functions that change critical parameters.
Severity: Informational
Context: AlchemicTokenV2.sol
, CrossChainCanonicalAlchemicTokenV2.sol
, gALCX.sol
, AlchemistV2.sol
, TransmuterBuffer.sol
, TransmuterV2.sol
, YearnTokenAdapter.sol
, StakingPools.sol
, WETHGateway.sol
, AutoleverageCurveFactoryethpool.sol
, AutoleverageCurveMetapool.sol
, Whitelist.sol
, FixedPointMath.sol
, LiquidityMath.sol
, Limiters.sol
, TokenUtils.sol
, Tick.sol
, Sets.sol
, SafeCast.sol
Description:
Contracts should be deployed using the same compiler version/flags with which they have been tested. Locking the pragma (for e.g. by not using ^
in pragma solidity 0.5.10
) ensures that contracts do not accidentally get deployed using an older compiler version with unfixed bugs.
Recommendation:
Remove ^
from in front of your pragma version.
Severity: Informational
Context: FuseTokenAdapterV1.sol
, WstETHAdapterV1.sol
, RETHAdapterV1.sol
, VesperAdapterV1.sol
, TransmuterConduit.sol
, EthAssetManager.sol
, ThreePoolAssetManager.sol
Description: It is better to use one Solidity compiler version across all contracts instead of different versions with different bugs and security checks.
Recommendation: Ensure all pragma versions are the same one.
Severity Informational
Context: FuseTokenAdapterV1.sol
, WstETHAdapterV1.sol
, RETHAdapterV1.sol
, VesperAdapterV1.sol
, TransmuterConduit.sol
, EthAssetManager.sol
, ThreePoolAssetManager.sol
Description: Using too recent of a pragma is risky since they are not battle tested. A rise of a bug that wasn't known on release would cause either a hack or a need to secure funds and redeploy.
Recommendation:
Use a Pragma version that has been used for sometime. I would suggest 0.8.4
for the decrease of risk and still has the gas optimizations implemented.
🌟 Selected for report: IllIllI
Also found by: 0v3rf10w, 0x1f8b, 0x4non, 0xDjango, 0xNazgul, 0xf15ers, 0xkatana, 0xsomeone, AlleyCat, BowTiedWardens, Cityscape, Fitraldys, Funen, GimelSec, Hawkeye, JC, MaratCerby, MiloTruck, Randyyy, TerrierLover, Tomio, UnusualTurtle, WatchPug, Waze, _Adam, augustg, bobirichman, catchup, csanuragjain, ellahi, fatherOfBlocks, hake, hansfriese, horsefacts, ignacio, joestakey, kenta, mics, oyc_109, robee, samruna, sashik_eth, sikorico, simon135, throttle
126.5591 DAI - $126.56
++index
instead of index++
to increment a loop counterContext: AlchemistV2.sol#L988-L993
, AlchemistV2.sol#L1280-L1285
, AlchemistV2.sol#L1353-L1358
, AlchemistV2.sol#L1457-L1471
, AlchemistV2.sol#L1520-L1546
, TransmuterBuffer.sol#L165-L175
, TransmuterBuffer.sol#L178-L209
, TransmuterBuffer.sol#L230-L248 (For both)
, TransmuterBuffer.sol#L263-L286
, TransmuterBuffer.sol#L371-L397 (For both)
, TransmuterBuffer.sol#L471-L484
, EthAssetManager.sol#L200-L226
, EthAssetManager.sol#L561-L595
, ThreePoolAssetManager.sol#L235-L264 (For both)
, ThreePoolAssetManager.sol#L330-L402
, ThreePoolAssetManager.sol#L763-L805
, ThreePoolAssetManager.sol#L896-L922
, StakingPools.sol#L182-L203
, StakingPools.sol#L362-L367
Description:
Due to reduced stack operations, using ++index
saves 5 gas per iteration.
Recommendation:
Use ++index
to increment a loop counter.
Context: AlchemistV2.sol#L988-L993
, AlchemistV2.sol#L1280-L1285
, AlchemistV2.sol#L1353-L1358
, AlchemistV2.sol#L1457-L1471
, AlchemistV2.sol#L1520-L1546
, TransmuterBuffer.sol#L165-L175
, TransmuterBuffer.sol#L178-L209
, TransmuterBuffer.sol#L230-L248 (For both)
, TransmuterBuffer.sol#L263-L286
, TransmuterBuffer.sol#L371-L397 (For L382)
, TransmuterBuffer.sol#L471-L484
, StakingPools.sol#L182-L203
, StakingPools.sol#L362-L367
Description: One can save gas by caching the array length (in stack) and using that set variable in the loop. Replace state variable reads and writes within loops with local variable reads and writes. This is done by assigning state variable values to new local variables, reading and/or writing the local variables in a loop, then after the loop assigning any changed local variables to their equivalent state variables.
Recommendation:
Simply do something like so before the for loop: uint length = variable.length
. Then add length
in place of variable.length
in the for loop.
calldata
Instead of memory
For Function ParametersContext: TransmuterBuffer.sol#L178-L209 (For both)
Description: The dynamic array arr has the storage location memory. When the function gets called externally, the array values are kept in calldata and copied to memory during ABI decoding (using the opcode calldataload and mstore). And during the for loop, arr[i] accesses the value in memory using a mload. However, for the above example this is inefficient.
Recommendation:
Use calldata
instead of memory
for function parameters to avoid using memory with array values whena function is getting called externally.
Immutable
Context: gALCX.sol#L12
, gALCX.sol#L13
, gALCX.sol#L17
Description:
Solidity 0.6.5
introduced immutable
as a major feature. It allows setting contract-level variables at construction time which gets stored in code rather than storage. Each call to it reads from storage, using a sload
costing 2100 gas cold or 100 gas warm. Setting it to immutable
will have each storage read of the state variable to be replaced by the instruction push32 value
, where value
is set during contract construction time and this costs only 3 gas.
Recommendation:
Set the state variable to immutable
Context: All Contracts
Description:
You can cut out 10 opcodes in the creation-time EVM bytecode if you declare a constructor payable. Making the constructor payable eliminates the need for an initial check of msg.value == 0
and saves 21 gas on deployment with no security risks.
Recommendation: Set the constructor to payable.
Context: All Contracts
Description:
Contracts most called functions could simply save gas by function ordering via Method ID. Calling a function at runtime will be cheaper if the function is positioned earlier in the order (has a relatively lower Method ID) because 22 gas are added to the cost of a function for every position that came before it. The caller can save on gas if you prioritize most called functions. One could use This tool
to help find alternative function names with lower Method IDs while keeping the original name intact.
Recommendation:
Find a lower method ID name for the most called functions for example mostCalled()
vs. mostCalled_41q()
is cheaper by 44 gas.
#0 - 0xfoobar
2022-05-30T07:09:11Z
Good point on calldata vs memory for array parameters