Asymmetry contest - Jerry0x's results

A protocol to help diversify and decentralize liquid staking derivatives.

General Information

Platform: Code4rena

Start Date: 24/03/2023

Pot Size: $49,200 USDC

Total HM: 20

Participants: 246

Period: 6 days

Judge: Picodes

Total Solo HM: 1

Id: 226

League: ETH

Asymmetry Finance

Findings Distribution

Researcher Performance

Rank: 178/246

Findings: 1

Award: $13.13

QA:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Confirm the derivative address to avoid incorrectly setting weight.

https://github.com/code-423n4/2023-03-asymmetry/blob/main/contracts/SafEth/SafEth.sol#L165-L175 function adjustWeight( uint256 _derivativeIndex, uint256 _weight, address _checkDerivative ) external onlyOwner { require(_checkDerivative == address(derivatives[_derivativeIndex]), "wrong derivative"); weights[_derivativeIndex] = _weight; uint256 localTotalWeight = 0; for (uint256 i = 0; i < derivativeCount; i++) localTotalWeight += weights[i]; totalWeight = localTotalWeight; for (uint i = 0; i < derivativeCount; i++) { uint256 weight = weights[i]; if (weight == 0) continue; uint256 ethAmount = (minAmount * weight) / totalWeight; require(ethAmount > 0, "weight too low"); } emit WeightChange(_derivativeIndex, _weight); }

Adding and removing functions can reduce gas costs and minimize unknown risks.

function removeDerivative( uint256 _derivativeIndex, address _checkDerivative ) external onlyOwner { require(_checkDerivative != address(0), "invalid address"); require(_checkDerivative == address(derivatives[_derivativeIndex]), "wrong derivative"); adjustWeight(_derivativeIndex, 0,_checkDerivative); rebalanceToWeights(); --derivativeCount; derivatives[_derivativeIndex] = derivatives[derivativeCount]; weights[_derivativeIndex] = weights[derivativeCount]; }

Lower gas, reduced risk, easier to understand.

struct Derivative { IDerivative derivative; uint96 weight; } mapping(uint256 => Derivative) public derivatives;

totalEth and totalEthAmount are not always equal, Whether returning or depositing, we should handle it.

https://github.com/code-423n4/2023-03-asymmetry/blob/main/contracts/SafEth/SafEth.sol#L83-L96 uint256 totalEth = msg.value; uint256 totalEthAmount; for (uint i = 0; i < derivativeCount; i++) { uint256 weight = weights[i]; IDerivative derivative = derivatives[i]; if (weight == 0) continue; uint256 ethAmount = (totalEth * weight) / totalWeight; totalEthAmount += ethAmount; // This is slightly less than ethAmount because slippage uint256 depositAmount = derivative.deposit{value: ethAmount}(); uint derivativeReceivedEthValue = (derivative.ethPerDerivative( depositAmount ) * depositAmount) / 10 ** 18; totalStakeValueEth += derivativeReceivedEthValue; } uint256 remaining = totalEth - totalEthAmount; // They are not always equal, Whether returning or depositing, we should handle it.

Convert uint to uint256

#0 - c4-sponsor

2023-04-10T16:47:47Z

toshiSat marked the issue as sponsor confirmed

#1 - c4-judge

2023-04-24T17:33:40Z

Picodes marked the issue as grade-b

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