EIP-4881: Spec implementation (#11720)

* Initial spec rewrite

* Finish adding merkle tree implementation

* Last bits

* Move reverse function

* Add comments

* Add deposit tree snapshot

* Add deposit tree

* Add comments + cleanup

* Fixes

* Add missing errors

* Small fixes

* Add unhandled error

* Cleanup

* Fix unsafe file.Close

* Add missing comments

* Small fixes

* Address some of deepSource' compaints

* Add depositCount check

* Add finalizedDeposit check

* Replace pointer magic with copy()

* Add test for slice reversal

* add back bytes method

* Add package level description

* Remove zerohash gen and add additional checks

* Add additional comments

* Small lint fixes

* Forgot an error

* Small fixes

* Move Uint64ToBytesLittleEndian32 + test

* Fix uint subtraction issue

* Move mixInLength below error handling

* Fix

* Fix deposit root

---------

Co-authored-by: rauljordan <raul@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Sammy Rosso
2023-01-27 18:35:25 +01:00
committed by GitHub
parent eca129d8ff
commit 9529c73ff1
9 changed files with 672 additions and 5 deletions

View File

@@ -382,3 +382,12 @@ func Unique[T comparable](a []T) []T {
}
return result[:end]
}
// Reverse reverses any slice in place
// Taken from https://github.com/faiface/generics/blob/8cf65f0b43803410724d8c671cb4d328543ba07d/examples/sliceutils/sliceutils.go
func Reverse[E any](s []E) []E {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
return s
}

View File

@@ -599,3 +599,20 @@ func TestUnique(t *testing.T) {
require.DeepEqual(t, []uint64{1, 2}, result)
})
}
func TestReverse(t *testing.T) {
tests := []struct {
value [][32]byte
want [][32]byte
}{
{[][32]byte{}, [][32]byte{}},
{[][32]byte{{'A'}, {'B'}, {'C'}, {'D'}},
[][32]byte{{'D'}, {'C'}, {'B'}, {'A'}}},
{[][32]byte{{1}, {2}, {3}, {4}},
[][32]byte{{4}, {3}, {2}, {1}}},
}
for _, tt := range tests {
b := slice.Reverse(tt.value)
require.DeepEqual(t, tt.want, b)
}
}