Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ssz encoding generator #7299

Open
wants to merge 334 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
334 commits
Select commit Hold shift + click to select a range
7c3dedd
add Validator conflig flag
Marchhill Jul 4, 2024
07d44d6
fix ShutterConfig
Marchhill Jul 4, 2024
2a21f82
update bls package to fix linux arm64 issue
Marchhill Jul 4, 2024
f16d65e
Merge remote-tracking branch 'upstream/master' into feature/gnosis-sh…
Marchhill Jul 4, 2024
8b2af7b
add log if try to build block in non-validator mode
Marchhill Jul 5, 2024
9682e4c
fix validator flags
Marchhill Jul 5, 2024
d2fc267
allow loaded transactions to be null
Marchhill Jul 5, 2024
eff7b25
disconnection logs with cancellation token
Marchhill Jul 5, 2024
7ce1f24
update libp2p settings and shuffle peers
Marchhill Jul 5, 2024
3e3542d
add bad signature tx test
Marchhill Jul 8, 2024
b039874
update gnosis config to final deployment
Marchhill Jul 8, 2024
58aad49
fix log
Marchhill Jul 9, 2024
2e155dd
merge master
Marchhill Jul 9, 2024
b0fffd2
check number of decryption keys received
Marchhill Jul 9, 2024
4a0a254
change encrypted gas limit to 1M
Marchhill Jul 9, 2024
80b86c5
fix invalid decryption key logs
Marchhill Jul 9, 2024
aa8661f
move placeholder key check
Marchhill Jul 9, 2024
5859ac7
increase log scan cutoff
Marchhill Jul 9, 2024
18c678f
restore tests
Marchhill Jul 9, 2024
5167691
Merge remote-tracking branch 'upstream/master' into feature/gnosis-sh…
Marchhill Jul 9, 2024
5b1d73e
restore tests properly
Marchhill Jul 9, 2024
79cd09f
roll back launch json
Marchhill Jul 9, 2024
e0da4e0
fix unfinalised log
Marchhill Jul 9, 2024
709a15a
fix slot timing
Marchhill Jul 10, 2024
c5c37b3
move slot timing constants to spec providers
Marchhill Jul 10, 2024
9a203e3
Merge remote-tracking branch 'upstream/master' into feature/gnosis-sh…
Marchhill Jul 10, 2024
a280c0d
move building block log
Marchhill Jul 10, 2024
0c3eaa3
fix tx ordering
Marchhill Jul 10, 2024
1774309
make GetNextTransaction lazy
Marchhill Jul 10, 2024
5aeb2a4
make ispecprovider methods virtual
Marchhill Jul 10, 2024
36e08ff
improve event fetching to remove sort
Marchhill Jul 10, 2024
a3c4f03
add back logs for event fetching
Marchhill Jul 10, 2024
bf5bfb3
move validator registration check
Marchhill Jul 10, 2024
c816170
finish move validator registry
Marchhill Jul 11, 2024
a6f92d6
use constants instead of specprovider txsource
Marchhill Jul 11, 2024
a7e7442
hardcode 10s block age cutoff
Marchhill Jul 11, 2024
96e6cf9
added ssz generator project to this fork
LLHOYH Jul 16, 2024
ce0d925
added generator folder
LLHOYH Jul 16, 2024
58ce3cc
added generator folder
LLHOYH Jul 16, 2024
ac9a27e
create Nethermind.Generator Project
LLHOYH Jul 16, 2024
0f5309b
setup generator properly
LLHOYH Jul 16, 2024
5e528c3
add reference to ssz library
LLHOYH Jul 16, 2024
1c23031
p2p logging shutter
ak88 Jul 16, 2024
ebdccb7
log when keys arrive
ak88 Jul 16, 2024
90ba128
basic type ssz conversion is working
LLHOYH Jul 17, 2024
d48e8a0
configurable build window
ak88 Jul 17, 2024
e8c1a15
small changes
ak88 Jul 17, 2024
145ad61
Make slot seen thread safe
ak88 Jul 17, 2024
78f0dad
removed unneccesary
ak88 Jul 17, 2024
89f63dc
just use lock
ak88 Jul 17, 2024
7c6172b
delete for now
ak88 Jul 17, 2024
84a82e3
fix
ak88 Jul 17, 2024
4e2d707
wait inside tx source for keys
ak88 Jul 18, 2024
05897fc
added ssz to generator project
LLHOYH Jul 18, 2024
5eda9ad
added ssz to generator project
LLHOYH Jul 18, 2024
51554a9
cleanup Shutter improvements
Marchhill Jul 18, 2024
40f3899
use payload timestamp
Marchhill Jul 19, 2024
ad93543
optimse log fetching
Marchhill Jul 19, 2024
ef49ee1
remove unused stuff from chiado spec provider
Marchhill Jul 19, 2024
b2d1e26
merge master
Marchhill Jul 19, 2024
582e848
remove IsNullOrEmpty
Marchhill Jul 19, 2024
abeccac
able to generate fields,structs and functions
LLHOYH Jul 24, 2024
0125045
bug fixed and supported all fields generation, it's now compilable an…
LLHOYH Jul 25, 2024
e34dc00
bug fixed and supported all fields generation, it's now compilable an…
LLHOYH Jul 25, 2024
e1e15af
new wait pattern
ak88 Jul 26, 2024
3b24349
added length calculation and fixed/dynamic type in comments
LLHOYH Jul 26, 2024
031f91d
fixed minor bug for length calculation
LLHOYH Jul 26, 2024
447bd67
fixed minor bug for length calculation
LLHOYH Jul 26, 2024
a141bef
fixed minor bug for length calculation
LLHOYH Jul 26, 2024
f895392
Preparation service can wait for keys in shutter
ak88 Jul 27, 2024
23e853d
err msg
ak88 Jul 29, 2024
1a3e5a2
timestamp fix
ak88 Jul 29, 2024
50fc2fe
added BitArray
LLHOYH Jul 30, 2024
b43d2c7
seperated sszAttribute into a standalone proj
LLHOYH Jul 30, 2024
b556065
seperated sszAttribute into a standalone proj
LLHOYH Jul 30, 2024
d35b21e
slot calc fix
ak88 Jul 30, 2024
d035275
p2p race condition fix
ak88 Jul 30, 2024
1281569
increase no msg in p2p
ak88 Jul 30, 2024
0575310
calculate current time
ak88 Jul 30, 2024
d23bc4a
handle slot not started
ak88 Jul 30, 2024
7f75605
Add the simpliest ssz gen
flcl42 Jul 30, 2024
a7e10a4
refactor
ak88 Jul 30, 2024
67b397c
shutter adjustments
ak88 Jul 31, 2024
4184302
minor refactors
Marchhill Jul 31, 2024
b463958
start key wait task
Marchhill Jul 31, 2024
d5677f8
don't keep improving block
Marchhill Jul 31, 2024
1062492
convert payload timestamp to ms to compare to genesis
Marchhill Jul 31, 2024
3d2f1ad
check cache first in wait
ak88 Jul 31, 2024
cbcf52a
Improve code
flcl42 Jul 31, 2024
74babcb
merge conflicts
LLHOYH Aug 1, 2024
5e7f5ed
resolved conflicts for merge
LLHOYH Aug 1, 2024
eb96d15
Merge remote-tracking branch 'lloyd/feature/ssz-generator' into featu…
flcl42 Aug 1, 2024
f8279b4
merged with 2 implementations
LLHOYH Aug 1, 2024
8ac3120
Merge remote-tracking branch 'lloyd/feature/ssz-generator' into featu…
flcl42 Aug 1, 2024
202a048
fix slot length, hardcode to gnosis
Marchhill Aug 1, 2024
6a80bfb
Merge branch 'feature/shutter-producer-wait' of github.com:Nethermind…
Marchhill Aug 1, 2024
d9da66e
rename option to MaxKeyDelay
Marchhill Aug 1, 2024
f13de6a
slotLength use totalMilliseconds
Marchhill Aug 1, 2024
8b401d3
Merge pull request #1 from NethermindEth/feature/ssz-generator
LLHOYH Aug 1, 2024
22a9a9f
fix slot offset overflow
Marchhill Aug 1, 2024
841f625
make slot offset short
Marchhill Aug 1, 2024
660eceb
fix short
Marchhill Aug 1, 2024
404557d
use cancellation token for key timeout
Marchhill Aug 1, 2024
5191df4
add cancelation source to waitForTransactions
Marchhill Aug 1, 2024
55956dc
temp add logs
Marchhill Aug 1, 2024
07650ac
throw cancelled exception on wait cancel
Marchhill Aug 1, 2024
ba3a8c1
try setting taskcompletionsource exception for key wait task
Marchhill Aug 1, 2024
8dc0be3
add logs to key wait task
Marchhill Aug 2, 2024
7aa5c8c
don't check highest loaded slot
Marchhill Aug 2, 2024
bb1f137
key received offset log
Marchhill Aug 2, 2024
a355882
refactor waiting for transactions, allow longer offsets
Marchhill Aug 2, 2024
e34682c
remove syncobject
Marchhill Aug 2, 2024
1d4a066
fix logs
Marchhill Aug 2, 2024
4fced6f
small refactors in auramergeplugin
Marchhill Aug 2, 2024
242d75e
merge shutter-producer-wait
Marchhill Aug 2, 2024
9874417
merge master
Marchhill Aug 2, 2024
fdbc698
initial shutter plugin
Marchhill Aug 5, 2024
f5e70c9
correct plugin name
Marchhill Aug 5, 2024
9451d08
refactor Shutter config
Marchhill Aug 5, 2024
eeb0218
add back txSource lock
Marchhill Aug 5, 2024
35cc3b6
refactor new head block handling
Marchhill Aug 5, 2024
3e24b58
initial event collector
Marchhill Aug 5, 2024
4ce4b72
load log transactions to cache
Marchhill Aug 6, 2024
bed1803
add lock, track txIndex, improve logging
Marchhill Aug 6, 2024
98a5ac9
check block number
Marchhill Aug 6, 2024
67624f0
receipts cache
Marchhill Aug 7, 2024
f44f7f9
rename to loadfromreceipts
Marchhill Aug 7, 2024
55168c5
filter outdated Shutter events collected when keys missed
Marchhill Aug 7, 2024
4acd4bc
Merge remote-tracking branch 'upstream/master' into feature/gnosis-sh…
Marchhill Aug 7, 2024
aeee60b
set to txPointer+1 if nothing loaded from logs
Marchhill Aug 7, 2024
d8193a7
clearer logs and variable names
Marchhill Aug 7, 2024
3228d4b
fix typo
Marchhill Aug 7, 2024
4e22859
refactor as IConsensusWrapperPlugin
Marchhill Aug 8, 2024
b9cc828
move block improvement context factory to api
Marchhill Aug 8, 2024
90fcae5
fix Shutter plugin loading
Marchhill Aug 8, 2024
4d1dc90
use receipt finder
Marchhill Aug 8, 2024
6f6b2fd
fix typo
Marchhill Aug 8, 2024
75d11dd
merge event collector
Marchhill Aug 8, 2024
83a58f1
merge shutter plugin refactor
Marchhill Aug 8, 2024
3741d1b
whitespace fix
Marchhill Aug 8, 2024
74128b6
remove unnecessary logging condition
Marchhill Aug 8, 2024
b2ac600
isinfo
Marchhill Aug 8, 2024
e119f58
fix shutter plugin to use block handler
Marchhill Aug 8, 2024
7b636f4
remove loaded tx hash filter
Marchhill Aug 9, 2024
c75e225
comment reminders
Marchhill Aug 9, 2024
84da5da
Merge remote-tracking branch 'upstream/master' into feature/gnosis-sh…
Marchhill Aug 9, 2024
ed1a03d
lukasz comments
Marchhill Aug 12, 2024
effed37
rename LoggersAddress to Address
Marchhill Aug 12, 2024
06c34e9
finish replace LoggerAddress with Address
Marchhill Aug 12, 2024
9c3ffaa
add block improvement logs
Marchhill Aug 12, 2024
b982540
wait for block to load transaction
Marchhill Aug 12, 2024
9bf6472
decrease up to date block cutoff
Marchhill Aug 12, 2024
011e73a
wait in previous slot for block
Marchhill Aug 12, 2024
1c67bce
Merge remote-tracking branch 'upstream/master' into feature/gnosis-sh…
Marchhill Aug 12, 2024
795c003
add validated keys type
Marchhill Aug 12, 2024
8869f38
fix block timestamp by changing to ms
Marchhill Aug 12, 2024
d578c0a
fix multiple key validations, add locks
Marchhill Aug 12, 2024
ac7b98c
add logs for debugging
Marchhill Aug 13, 2024
7933545
try decreasing Shutter plugin priority
Marchhill Aug 13, 2024
b7914f7
revert plugin priorities, set api block producer in Shutter plugin
Marchhill Aug 13, 2024
0b07165
try wrapping BlockProducerEnvFactory
Marchhill Aug 13, 2024
01b0560
remove api block producer check
Marchhill Aug 13, 2024
9444e3d
block producer env logging
Marchhill Aug 13, 2024
5d526aa
try alt approach of adding txsource to blockproducer
Marchhill Aug 13, 2024
4723242
cleanup block production fix
Marchhill Aug 13, 2024
9c5d3e0
Merge remote-tracking branch 'upstream/master' into feature/gnosis-sh…
Marchhill Aug 13, 2024
86f9c87
cleanup and improve keepImproving
Marchhill Aug 13, 2024
1c0d3c0
fix head block number of 0
Marchhill Aug 13, 2024
98ec32c
log scanning / fetch to debug logs
Marchhill Aug 13, 2024
3c14a6e
don't retry block production if keys arrived first time
Marchhill Aug 13, 2024
5008b6e
increase block cutoff
Marchhill Aug 13, 2024
8cc955f
increase up to date cutoff more
Marchhill Aug 13, 2024
f2d8444
fix block up to date check
Marchhill Aug 13, 2024
61f6dec
move blssigner from Shutter
Marchhill Aug 14, 2024
de74968
add test package to nuget config
Marchhill Aug 14, 2024
912f535
update bls bindings package
Marchhill Aug 14, 2024
b3597da
Merge remote-tracking branch 'upstream/master' into feature/bls-sig
Marchhill Aug 14, 2024
0bf69eb
add bls tests from Shutter
Marchhill Aug 14, 2024
40065a7
improve tests, pass args by ref
Marchhill Aug 14, 2024
473188a
fix whitespace
Marchhill Aug 14, 2024
da55aa5
Merge remote-tracking branch 'upstream/master' into feature/bls-sig
Marchhill Aug 14, 2024
27713bd
start fixing unit tests
Marchhill Aug 15, 2024
434be24
fix whitespace
Marchhill Aug 15, 2024
d03e277
improve tests, tx loading tests
Marchhill Aug 16, 2024
4d5217e
improve load_transactions test
Marchhill Aug 16, 2024
9e83fd7
shutter event emitter
Marchhill Aug 16, 2024
001c473
finish tx loader can_load test, refactor tx filtering, remove some in…
Marchhill Aug 19, 2024
551b782
maintain slot to block hash mapping instead of blocks
Marchhill Aug 19, 2024
79bd991
Merge remote-tracking branch 'upstream/master' into feature/gnosis-sh…
Marchhill Aug 19, 2024
b996317
Merge branch 'feature/gnosis-shutter' into feature/shutter-tests
Marchhill Aug 19, 2024
d4503df
refactor and add to tx loader tests
Marchhill Aug 19, 2024
96d8fb2
cleanup and remove unused highest slot
Marchhill Aug 20, 2024
8b8093b
add block handler test, refactor shutter time, test common
Marchhill Aug 20, 2024
9ed3caf
refactor Shutter to use API
Marchhill Aug 20, 2024
078f831
use api in tests
Marchhill Aug 21, 2024
406f430
fix whitespace
Marchhill Aug 21, 2024
24d3c4a
Merge remote-tracking branch 'upstream/master' into feature/gnosis-sh…
Marchhill Aug 21, 2024
1d2e934
Merge branch 'feature/gnosis-shutter' into feature/shutter-tests
Marchhill Aug 21, 2024
20eb326
Clean up, add decode, mekleize
flcl42 Aug 21, 2024
123b1e1
block handler tests
Marchhill Aug 21, 2024
530cefe
move event simulation to api
Marchhill Aug 22, 2024
7184ad5
Before unions
flcl42 Aug 23, 2024
1f1b97b
e2e test
Marchhill Aug 23, 2024
b92bdcf
integration tests working
Marchhill Aug 24, 2024
bdd8081
Before remake
flcl42 Aug 26, 2024
9573cb4
Before collections
flcl42 Aug 27, 2024
989e7c6
Before remake
flcl42 Aug 27, 2024
4fcbeaf
missed keys test
Marchhill Aug 28, 2024
5036bee
add metrics
Marchhill Aug 28, 2024
445f8d2
more eon metrics
Marchhill Aug 28, 2024
d3b3c5d
Before remake
flcl42 Aug 28, 2024
eaa161d
tidy up PR
Marchhill Aug 28, 2024
fd10172
validator registration tuple
Marchhill Aug 28, 2024
898e9c1
fix outdated variable names
Marchhill Aug 28, 2024
6915526
fix scanning to genesis
Marchhill Aug 28, 2024
9d250cc
+
flcl42 Aug 29, 2024
cb9a770
refactor log scanner into own component
Marchhill Aug 29, 2024
f195ce7
overlapping eons test
Marchhill Aug 29, 2024
b085c27
multiple event queues for different eons
Marchhill Aug 29, 2024
7fe0692
make keys missed test non parallelizable
Marchhill Aug 29, 2024
11adc39
fix whitespace
Marchhill Aug 29, 2024
b6da3e6
merge master
Marchhill Aug 29, 2024
c96702c
merge bls sig tests
Marchhill Aug 29, 2024
d99733f
add shutter tests to github actions
Marchhill Aug 29, 2024
6b5afed
Add more cases
flcl42 Aug 29, 2024
d69ebc4
tidy up PR
Marchhill Aug 29, 2024
62a6b90
register New head block handler in plugin
Marchhill Aug 29, 2024
fe4ae70
fix offset calculation
Marchhill Aug 29, 2024
d1d71a8
Before union
flcl42 Aug 30, 2024
17215e7
Added unions
flcl42 Aug 30, 2024
a76858a
All working
flcl42 Aug 30, 2024
0220c20
Clean up
flcl42 Aug 30, 2024
12d6406
More space
flcl42 Aug 31, 2024
cc46a61
Add analyzer
flcl42 Aug 31, 2024
431ace1
Merge remote-tracking branch 'origin/feature/gnosis-shutter' into fea…
flcl42 Sep 1, 2024
a951ec0
Fix encoding/decoding
flcl42 Sep 1, 2024
834fef2
Fix merkle, add docs
flcl42 Sep 1, 2024
0b585f7
Clean up
flcl42 Sep 2, 2024
3b0ff94
Return submodules back
flcl42 Sep 2, 2024
4d2b42e
Add SlotDecryptionIdentites
flcl42 Sep 2, 2024
9a8c50e
WS
flcl42 Sep 2, 2024
b3b5019
Add one more analyzer
flcl42 Sep 3, 2024
385394f
Generic Feed for simple types
flcl42 Sep 3, 2024
0173518
Clean up, optimize
flcl42 Sep 3, 2024
32cfd2f
Merge branch 'feature/ssz-generator' of https://github.com/Nethermind…
flcl42 Sep 3, 2024
e71229c
Fox merkle
flcl42 Sep 3, 2024
634f960
Merge remote-tracking branch 'origin/master' into feature/ssz-generator
flcl42 Dec 27, 2024
8155d1e
Cancel merge changes
flcl42 Dec 27, 2024
ecbe647
Merge remote-tracking branch 'origin/master' into feature/ssz-generator
flcl42 Dec 27, 2024
b6c2742
Merge branch 'master' into feature/ssz-generator
flcl42 Jan 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Nethermind/Nethermind.Merkleization/Merkle.BitArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ namespace Nethermind.Merkleization;

public static partial class Merkle
{
public static void IzeBitvector(out UInt256 root, BitArray value)
public static void Ize(out UInt256 root, BitArray value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest renaming this cryptic Ize() method to a more understandable one, say, Merklize or Merkleize. Perhaps the former. Whatever we choose, we need to have a consistent naming.

{
Merkleizer merkleizer = new Merkleizer(0);
merkleizer.FeedBitvector(value);
merkleizer.Feed(value);
merkleizer.CalculateRoot(out root);
}

public static void IzeBitlist(out UInt256 root, BitArray value, ulong maximumBitlistLength)
public static void Ize(out UInt256 root, BitArray value, ulong limit)
{
Merkleizer merkleizer = new Merkleizer(0);
merkleizer.FeedBitlist(value, maximumBitlistLength);
merkleizer.Feed(value, limit);
merkleizer.CalculateRoot(out root);
}

Expand Down
2 changes: 0 additions & 2 deletions src/Nethermind/Nethermind.Merkleization/Merkle.Containers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ namespace Nethermind.Merkleization

public static partial class Merkle
{


//public static void Ize(out UInt256 root, BlsPublicKey container)
//{
// Ize(out root, container.Bytes);
Expand Down
6 changes: 6 additions & 0 deletions src/Nethermind/Nethermind.Merkleization/Merkle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ public static void Ize(out UInt256 root, uint value)
root = new UInt256(value);
}

public static void Ize(out UInt256 root, long value)
{
var v = value < 0 ? ulong.MaxValue : 0L;
root = new UInt256((ulong)value, v, v, v);
}

public static void Ize(out UInt256 root, ulong value)
{
root = new UInt256(value);
Expand Down
181 changes: 172 additions & 9 deletions src/Nethermind/Nethermind.Merkleization/Merkleizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.InteropServices;
using Nethermind.Core;
using Nethermind.Core.Collections;
Expand Down Expand Up @@ -58,9 +59,122 @@ public void Feed(UInt256 chunk)
FeedAtLevel(chunk, 0);
}

public void Feed(Span<byte> bytes)
public void Feed(long value)
{
FeedAtLevel(MemoryMarshal.Cast<byte, UInt256>(bytes)[0], 0);
Merkle.Ize(out _chunks[^1], value);
Feed(_chunks[^1]);
}

public void Feed(Span<byte> data, int? limit = null)
{
if (data.Length is 0)
{
Merkle.Ize(out _chunks[^1], UInt256.Zero);
}
else
{
Merkle.Ize(out _chunks[^1], data);
}

if (limit is not null) Merkle.MixIn(ref _chunks[^1], limit.Value);
}

public void Feed(Span<ushort> data, int? limit = null)
{
if (data.Length is 0)
{
Merkle.Ize(out _chunks[^1], UInt256.Zero);
}
else
{
Merkle.Ize(out _chunks[^1], MemoryMarshal.Cast<ushort, byte>(data));
}

if (limit is not null) Merkle.MixIn(ref _chunks[^1], limit.Value);
}

public void Feed(Span<short> data, int? limit = null)
{
if (data.Length is 0)
{
Merkle.Ize(out _chunks[^1], UInt256.Zero);
}
else
{
Merkle.Ize(out _chunks[^1], MemoryMarshal.Cast<short, byte>(data));
}

if (limit is not null) Merkle.MixIn(ref _chunks[^1], limit.Value);
}

public void Feed(Span<uint> data, int? limit = null)
{
if (data.Length is 0)
{
Merkle.Ize(out _chunks[^1], UInt256.Zero);
}
else
{
Merkle.Ize(out _chunks[^1], MemoryMarshal.Cast<uint, byte>(data));
}

if (limit is not null) Merkle.MixIn(ref _chunks[^1], limit.Value);
}

public void Feed(Span<int> data, int? limit = null)
{
if (data.Length is 0)
{
Merkle.Ize(out _chunks[^1], UInt256.Zero);
}
else
{
Merkle.Ize(out _chunks[^1], MemoryMarshal.Cast<int, byte>(data));
}

if (limit is not null) Merkle.MixIn(ref _chunks[^1], limit.Value);
}

public void Feed(Span<ulong> data, int? limit = null)
{
if (data.Length is 0)
{
Merkle.Ize(out _chunks[^1], UInt256.Zero);
}
else
{
Merkle.Ize(out _chunks[^1], MemoryMarshal.Cast<ulong, byte>(data));
}

if (limit is not null) Merkle.MixIn(ref _chunks[^1], limit.Value);
}

public void Feed(Span<long> data, int? limit = null)
{
if (data.Length is 0)
{
Merkle.Ize(out _chunks[^1], UInt256.Zero);
}
else
{
Merkle.Ize(out _chunks[^1], MemoryMarshal.Cast<long, byte>(data));
}

if (limit is not null) Merkle.MixIn(ref _chunks[^1], limit.Value);
}

public void Feed(Span<UInt128> data, int? limit = null)
{
if (data.Length is 0)
{
Merkle.Ize(out _chunks[^1], UInt256.Zero);
}
else
{
Merkle.Ize(out _chunks[^1], MemoryMarshal.Cast<UInt128, byte>(data));
}

if (limit is not null) Merkle.MixIn(ref _chunks[^1], limit.Value);
}

public void Feed(bool value)
Expand All @@ -74,6 +188,20 @@ public void Feed(uint value)
Merkle.Ize(out _chunks[^1], value);
Feed(_chunks[^1]);
}
public void Feed(int value)
flcl42 marked this conversation as resolved.
Show resolved Hide resolved
{
Merkle.Ize(out _chunks[^1], value);
Feed(_chunks[^1]);
}
public void Feed(int? value)
{
if (value is null)
{
return;
}
Merkle.Ize(out _chunks[^1], value.Value);
Feed(_chunks[^1]);
}

public void Feed(ulong value)
{
Expand Down Expand Up @@ -103,27 +231,48 @@ public void FeedBits(byte[]? value, uint limit)
Feed(_chunks[^1]);
}

public void FeedBitvector(BitArray bitArray)
public void Feed(BitArray? vector)
{
if (vector is null) return;
// bitfield_bytes
byte[] bytes = new byte[(bitArray.Length + 7) / 8];
bitArray.CopyTo(bytes, 0);
byte[] bytes = new byte[(vector.Length + 7) / 8];
vector.CopyTo(bytes, 0);

Merkle.Ize(out _chunks[^1], bytes);
Feed(_chunks[^1]);
}

public void FeedBitlist(BitArray bitArray, ulong maximumBitlistLength)
public void Feed(BitArray? list, ulong maximumBitlistLength)
{
if (list is null) return;

// chunk count
ulong chunkCount = (maximumBitlistLength + 255) / 256;

// bitfield_bytes
byte[] bytes = new byte[(bitArray.Length + 7) / 8];
bitArray.CopyTo(bytes, 0);
byte[] bytes = new byte[(list.Length + 7) / 8];
list.CopyTo(bytes, 0);

Merkle.Ize(out _chunks[^1], bytes, chunkCount);
Merkle.MixIn(ref _chunks[^1], bitArray.Length);
Merkle.MixIn(ref _chunks[^1], list.Length);
Feed(_chunks[^1]);
}

public void Feed(IReadOnlyList<byte[]> value, ulong maxLength)
{
if (value is null)
{
return;
}

UInt256[] subRoots = new UInt256[value.Count];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ArrayPoolList?

for (int i = 0; i < value.Count; i++)
{
Merkle.Ize(out subRoots[i], value[i]);
}

Merkle.Ize(out _chunks[^1], subRoots, maxLength);
Merkle.MixIn(ref _chunks[^1], value.Count);
Feed(_chunks[^1]);
}

Expand Down Expand Up @@ -574,6 +723,20 @@ public void Feed(IReadOnlyList<Bytes32> value, ulong maxLength)
Feed(_chunks[^1]);
}

public void Feed(IReadOnlyList<ulong> value, ulong maxLength)
{
// TODO: If UInt256 is the correct memory layout
UInt256[] subRoots = new UInt256[value.Count];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ArrayPoolList?

for (int i = 0; i < value.Count; i++)
{
Merkle.Ize(out subRoots[i], value[i]);
}

Merkle.Ize(out _chunks[^1], subRoots, maxLength);
Merkle.MixIn(ref _chunks[^1], value.Count);
Feed(_chunks[^1]);
}

public void Feed(IReadOnlyList<Root> value)
{
UInt256[] input = new UInt256[value.Count];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void Can_merkleize_bitarray_bitvector(bool[] value, string expectedByteSt

// Act
var hashTreeRoot = new byte[32];
Merkle.IzeBitvector(out UInt256 root, input);
Merkle.Ize(out UInt256 root, input);
root.ToLittleEndian(hashTreeRoot);

// Assert
Expand Down Expand Up @@ -97,7 +97,7 @@ public void Can_merkleize_bitarray_bitlist(bool[] value, ulong maximumBitlistLen

// Act
var hashTreeRoot = new byte[32];
Merkle.IzeBitlist(out UInt256 root, input, maximumBitlistLength);
Merkle.Ize(out UInt256 root, input, maximumBitlistLength);
root.ToLittleEndian(hashTreeRoot);

// Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public static Root DecodeRoot(ReadOnlySpan<byte> span)
return new Root(span);
}



public static Root[] DecodeRoots(ReadOnlySpan<byte> span)
{
if (span.Length == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static partial class Ssz
{
public const int Bytes32Length = Bytes32.Length;

public static ReadOnlySpan<byte> DecodeBytes(ReadOnlySpan<byte> span)
public static byte[] DecodeBytes(ReadOnlySpan<byte> span)
{
return span.ToArray();
}
Expand Down
Loading
Loading