Neo Tokyo contest - cccz's results

A staking contract for the crypto gaming illuminati.

General Information

Platform: Code4rena

Start Date: 08/03/2023

Pot Size: $60,500 USDC

Total HM: 2

Participants: 123

Period: 7 days

Judge: hansfriese

Id: 220

League: ETH

Neo Tokyo

Findings Distribution

Researcher Performance

Rank: 41/123

Findings: 1

Award: $154.74

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

154.74 USDC - $154.74

Labels

bug
3 (High Risk)
satisfactory
upgraded by judge
duplicate-261

External Links

Lines of code

https://github.com/code-423n4/2023-03-neotokyo/blob/dfa5887062e47e2d0c801ef33062d44c09f6f36e/contracts/staking/NeoTokyoStaker.sol#L1155-L1156

Vulnerability details

Impact

NeoTokyoStaker contracts have three calculations where the division is before the multiplication, which can lead to a slight loss of precision.

  1. The * _PRECISION here is to prevent precision loss and is ok.
				uint256 share = points * _PRECISION / pool.totalPoints * totalReward;
				uint256 daoShare = share * pool.daoTax / (100 * _DIVISOR);
				share /= _PRECISION;
				daoShare /= _PRECISION;
  1. The loss of precision here will result in a loss of points of up to 0.01 * 1e18 LP tokens when the user stake LP tokens.
			uint256 points = amount * 100 / 1e18 * timelockMultiplier / _DIVISOR;

			// Update the caller's LP token stake.
			stakerLPPosition[msg.sender].timelockEndTime =
				block.timestamp + timelockDuration;
			stakerLPPosition[msg.sender].amount += amount;
			stakerLPPosition[msg.sender].points += points;

			// Update the pool point weights for rewards.
			pool.totalPoints += points;
  1. The loss of precision here will result in points of up to 0.01 * 1e18 LP tokens not being lost when the user withdraws the LP tokens
			uint256 points = amount * 100 / 1e18 * lpPosition.multiplier / _DIVISOR;

			// Update the caller's LP token stake.
			lpPosition.amount -= amount;
			lpPosition.points -= points;

			// Update the pool point weights for rewards.
			pool.totalPoints -= points;

Proof of Concept

https://github.com/code-423n4/2023-03-neotokyo/blob/dfa5887062e47e2d0c801ef33062d44c09f6f36e/contracts/staking/NeoTokyoStaker.sol#L1388-L1391 https://github.com/code-423n4/2023-03-neotokyo/blob/dfa5887062e47e2d0c801ef33062d44c09f6f36e/contracts/staking/NeoTokyoStaker.sol#L1155-L1156 https://github.com/code-423n4/2023-03-neotokyo/blob/dfa5887062e47e2d0c801ef33062d44c09f6f36e/contracts/staking/NeoTokyoStaker.sol#L1623-L1624

Tools Used

None

Place multiplication before division to reduce loss of precision

-			uint256 points = amount * 100 / 1e18 * timelockMultiplier / _DIVISOR;
+			uint256 points = amount * 100 * timelockMultiplier / 1e18  / _DIVISOR;

			// Update the caller's LP token stake.
			stakerLPPosition[msg.sender].timelockEndTime =
				block.timestamp + timelockDuration;
			stakerLPPosition[msg.sender].amount += amount;
			stakerLPPosition[msg.sender].points += points;

			// Update the pool point weights for rewards.
			pool.totalPoints += points;
...
-			uint256 points = amount * 100 / 1e18 * lpPosition.multiplier / _DIVISOR;
+			uint256 points = amount * 100 * lpPosition.multiplier / 1e18 / _DIVISOR;

			// Update the caller's LP token stake.
			lpPosition.amount -= amount;
			lpPosition.points -= points;

			// Update the pool point weights for rewards.
			pool.totalPoints -= points;

#0 - hansfriese

2023-03-16T09:42:31Z

duplicate of #304 and #348. Will check again later.

#1 - c4-judge

2023-03-16T09:42:43Z

hansfriese marked the issue as satisfactory

#2 - c4-judge

2023-03-16T09:42:55Z

hansfriese marked the issue as duplicate of #304

#3 - c4-judge

2023-03-21T09:26:22Z

hansfriese marked the issue as duplicate of #261

#4 - c4-judge

2023-03-29T00:19:02Z

hansfriese marked the issue as not a duplicate

#5 - c4-judge

2023-03-29T00:19:20Z

hansfriese changed the severity to 3 (High Risk)

#6 - c4-judge

2023-03-29T00:19:59Z

hansfriese marked the issue as duplicate of #261

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