You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Key Collision in ethStreamEndingAtTick Mapping Allows Miscalculation of ETH Streaming Balances
Summary
The ethStreamEndingAtTick mapping, defined here, uses streamLastTick as a key. This implementation leads to potential key collisions when multiple users create streams that resolve to the same streamLastTick value. Collisions result in incorrect ETH balances in the mapping, which impacts subsequent functionality such as forwardAll and increaseTicksAndFinishStreams.
Root Cause
The createStream function (source) calculates streamLastTick using the formula currentTick + streamLengthInTicks. If two users create streams with overlapping ticks or identical streamLengthInTicks while sharing the same currentTick, the resulting key (streamLastTick) will overwrite previous values in the mapping, conflating unrelated streams.
Internal Precondition
currentTick is a shared state variable, and multiple users rely on its value to calculate streamLastTick.
Users create streams with overlapping or identical streamLengthInTicks.
External Precondition
Multiple users are allowed to create streams.
The system assumes unique entries in the ethStreamEndingAtTick mapping.
Attack Path
User A creates a stream with streamLengthInTicks = 5.
The mapping updates ethStreamEndingAtTick[5].
User B creates a stream while the currentTick is still at the same state, and streamLengthInTicks = 3.
The mapping overwrites ethStreamEndingAtTick[5].
Impact
Incorrect ETH balances in ethStreamEndingAtTick affect calculations during stream processing (e.g., in forwardAll and increaseTicksAndFinishStreams).
May result in incorrect deductions, misallocations, or unexpected behavior for users and the DAO.
PoC
function test_createStream_keyCollision_withoutForwardAll() public {
address user2 =makeAddr("User2");
assertEq(nounsToken.ownerOf(1), streamCreator);
vm.prank(streamCreator);
escrow.createStream(1, 5); //// Mock an increment in currentTick (simulate time progression without forwardAll)uint256 mockedTick = escrow.currentTick() +2;
vm.store(address(escrow), keccak256("currentTick"), bytes32(uint256(mockedTick)));
// Step 2: User2 creates another stream with nounId = 2 and streamLength = 3assertEq(nounsToken.ownerOf(2), user2);
vm.prank(user2);
escrow.createStream(2, 3); // ethPerTick for this stream: msg.value / 3// Step 3: Verify that ethStreamEndingAtTick contains a collisionuint128 expectedEthPerTick =uint128(msg.value/5); // Original value for User1uint128 actualEthPerTick = escrow.ethStreamEndingAtTick(mockedTick +3);
assertEq(expectedEthPerTick, actualEthPerTick, "ethStreamEndingAtTick contains an incorrect value due to key collision");
}
Mitigation
Introduce a unique identifier for ethStreamEndingAtTick keys:
Use a composite key (e.g., keccak256(abi.encodePacked(streamLastTick, nounId))).
Refactor functions that rely on ethStreamEndingAtTick to use the updated structure.
The text was updated successfully, but these errors were encountered:
sherlock-admin4
changed the title
Generous Peanut Platypus - Key Collision in ethStreamEndingAtTick Mapping Allows Miscalculation of ETH Streaming Balances
OlaHamid - Key Collision in ethStreamEndingAtTick Mapping Allows Miscalculation of ETH Streaming Balances
Dec 4, 2024
OlaHamid
High
Key Collision in
ethStreamEndingAtTick
Mapping Allows Miscalculation of ETH Streaming BalancesSummary
The
ethStreamEndingAtTick
mapping, defined here, usesstreamLastTick
as a key. This implementation leads to potential key collisions when multiple users create streams that resolve to the samestreamLastTick
value. Collisions result in incorrect ETH balances in the mapping, which impacts subsequent functionality such asforwardAll
andincreaseTicksAndFinishStreams
.Root Cause
The
createStream
function (source) calculatesstreamLastTick
using the formulacurrentTick + streamLengthInTicks
. If two users create streams with overlapping ticks or identicalstreamLengthInTicks
while sharing the samecurrentTick
, the resulting key (streamLastTick
) will overwrite previous values in the mapping, conflating unrelated streams.Internal Precondition
currentTick
is a shared state variable, and multiple users rely on its value to calculatestreamLastTick
.streamLengthInTicks
.External Precondition
ethStreamEndingAtTick
mapping.Attack Path
streamLengthInTicks = 5
.ethStreamEndingAtTick[5]
.currentTick
is still at the same state, andstreamLengthInTicks = 3
.ethStreamEndingAtTick[5]
.Impact
ethStreamEndingAtTick
affect calculations during stream processing (e.g., inforwardAll
andincreaseTicksAndFinishStreams
).PoC
Mitigation
Introduce a unique identifier for
ethStreamEndingAtTick
keys:keccak256(abi.encodePacked(streamLastTick, nounId))
).ethStreamEndingAtTick
to use the updated structure.The text was updated successfully, but these errors were encountered: