LSD Network - Stakehouse contest - btk's results

A permissionless 3 pool liquid staking solution for Ethereum.

General Information

Platform: Code4rena

Start Date: 11/11/2022

Pot Size: $90,500 USDC

Total HM: 52

Participants: 92

Period: 7 days

Judge: LSDan

Total Solo HM: 20

Id: 182

League: ETH

Stakehouse Protocol

Findings Distribution

Researcher Performance

Rank: 43/92

Findings: 3

Award: $129.76

Gas:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: ladboy233

Also found by: 0xbepresent, Trust, bitbopper, btk, yixxas

Labels

bug
3 (High Risk)
partial-25
edited-by-warden
duplicate-110

Awards

55.3657 USDC - $55.37

External Links

Reentrancy attack may occur on withdrawETHForKnot()

Note: It wasn't clear to me whether this should be submitted as high severity or medium severity, so I thought it best to leave it up to the judges.

Lines of code:

https://github.com/code-423n4/2022-11-stakehouse/blob/main/contracts/liquid-staking/LiquidStakingManager.sol#L326-L350

Impact: A reentrancy attack can occur when the contract fails to update its state before the interaction, the attacker can make a recursive call back to the original function in an attempt to drain funds.

Proof of concept: The below scenario would be possible.

Since the node runner could be a smart contract, the contract could have a malicious code so that when withdrawETHForKnot() get called, it goes in infinite loop in attempt to drain all the funds.

Tools Used

Manual Review

Use a reentrancy guard

#0 - c4-judge

2022-12-02T22:28:10Z

dmvt marked the issue as duplicate of #110

#1 - c4-judge

2022-12-02T22:28:47Z

dmvt marked the issue as partial-25

Findings Information

Awards

6.2548 USDC - $6.25

Labels

bug
2 (Med Risk)
satisfactory
edited-by-warden
duplicate-378

External Links

Lines of code

https://github.com/code-423n4/2022-11-stakehouse/blob/main/contracts/liquid-staking/LiquidStakingManager.sol#L278-L284

Vulnerability details

Impact

Since the function always revert Due to incorrect require statements, there is no way to add or remove a whitelisted node runner. Therefore, the functions registerBLSPublicKeys that require for a node runner to be whitelisted will also revert.

Proof of Concept

require(isNodeRunnerWhitelisted[_nodeRunner] != isNodeRunnerWhitelisted[_nodeRunner], "Unnecessary update to same status");

In this require statement you are basically saying that if a node runner is whitelisted then require that is not whitelisted and vice versa.

Tools Used

Manual review

Fix:

// Replace the incorrect require statement with this one.
require(isWhitelisted != isNodeRunnerWhitelisted[_nodeRunner], "Unnecessary update to same status");

#0 - c4-judge

2022-11-21T21:24:58Z

dmvt marked the issue as duplicate of #67

#1 - c4-judge

2022-11-30T11:43:55Z

dmvt marked the issue as satisfactory

#2 - C4-Staff

2022-12-21T00:11:17Z

JeeberC4 marked the issue as duplicate of #378

Findings Information

Awards

68.1383 USDC - $68.14

Labels

bug
G (Gas Optimization)
grade-b
edited-by-warden
G-08

External Links

Gas saving 1: State variables should be cached in memory variables rather than re-reading them from storage

Lines of code: https://github.com/code-423n4/2022-11-stakehouse/blob/main/contracts/syndicate/Syndicate.sol#L177-L189

State variable:  numberOfRegisteredKnots 

Deployment gas before: 3219394

Deployment gas used after: 3219178

Gas Saved: 216
Lines of code: https://github.com/code-423n4/2022-11-stakehouse/blob/main/contracts/syndicate/Syndicate.sol#L551

State variable:  totalFreeFloatingShares 

Deployment gas before: 3219394

Deployment gas used after: 3217654

Gas Saved: 1740

We can optimize the above functions by caching the state variables to a memory variables.


Gas saving 2: Add the constant attributes to state variables that never change

Lines of code: https://github.com/code-423n4/2022-11-stakehouse/blob/main/contracts/liquid-staking/LiquidStakingManager.sol#L158

State variable:  MODULO  

Deployment gas before: 5395557

Deployment gas used after: 5373903

Gas Saved: 21654

Gas saving 3: ++ Cost less gas then += 1

Lines of code: 
https://github.com/code-423n4/2022-11-stakehouse/blob/main/contracts/liquid-staking/LiquidStakingManager.sol#L782
https://github.com/code-423n4/2022-11-stakehouse/blob/main/contracts/liquid-staking/LiquidStakingManager.sol#L839

State variable:  numberOfKnots 

Use ++numberOfKnots instead of numberOfKnots += 1

Deployment gas before: 5395557

Deployment gas used after: 5393181

Gas Saved: 2376

#0 - c4-judge

2022-12-02T00:07:02Z

dmvt 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