Skip to content

Commit

Permalink
Range mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
asdacap committed Nov 1, 2024
1 parent b9f020c commit 1a65051
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Buffers.Binary;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -72,7 +73,7 @@ public ProgressTracker(IBlockTree blockTree, IDb db, ILogManager logManager, int

_pivot = new Pivot(blockTree, logManager);

if (accountRangePartitionCount < 1 || accountRangePartitionCount > 256)
if (accountRangePartitionCount < 1 || accountRangePartitionCount > int.MaxValue)
throw new ArgumentException("Account range partition must be between 1 to 256.");

_accountRangePartitionCount = accountRangePartitionCount;
Expand All @@ -87,20 +88,20 @@ private void SetupAccountRangePartition()
// Confusingly dividing the range evenly via UInt256 for example, consistently cause root hash mismatch.
// The mismatch happens on exactly the same partition every time, suggesting tome kind of boundary issues
// either on proof generation or validation.
byte curStartingPath = 0;
int partitionSize = (256 / _accountRangePartitionCount);
uint curStartingPath = 0;
uint partitionSize = (uint.MaxValue / (uint)_accountRangePartitionCount);

for (var i = 0; i < _accountRangePartitionCount; i++)
{
AccountRangePartition partition = new AccountRangePartition();

Hash256 startingPath = new Hash256(Keccak.Zero.Bytes);
startingPath.Bytes[0] = curStartingPath;
BinaryPrimitives.WriteUInt32BigEndian(startingPath.Bytes, curStartingPath);

partition.NextAccountPath = startingPath;
partition.AccountPathStart = startingPath;

curStartingPath += (byte)partitionSize;
curStartingPath += partitionSize;

Hash256 limitPath;

Expand All @@ -112,7 +113,7 @@ private void SetupAccountRangePartition()
else
{
limitPath = new Hash256(Keccak.Zero.Bytes);
limitPath.Bytes[0] = curStartingPath;
BinaryPrimitives.WriteUInt32BigEndian(limitPath.Bytes, curStartingPath);
}

partition.AccountPathLimit = limitPath;
Expand Down

0 comments on commit 1a65051

Please sign in to comment.