Skip to content

Commit

Permalink
revert deactivation + import fixes from 454 (#461)
Browse files Browse the repository at this point in the history
* revert deactivation + import fixes from 454

Signed-off-by: Guillaume Ballet <[email protected]>

* fix

Signed-off-by: Ignacio Hagopian <[email protected]>

* fix lint

Signed-off-by: Ignacio Hagopian <[email protected]>

---------

Signed-off-by: Guillaume Ballet <[email protected]>
Signed-off-by: Ignacio Hagopian <[email protected]>
Co-authored-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
gballet and jsign authored Oct 30, 2024
1 parent af95552 commit 7dd8079
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
15 changes: 4 additions & 11 deletions encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ const (
leafC1CommitmentOffset = leafCommitmentOffset + banderwagon.UncompressedSize
leafC2CommitmentOffset = leafC1CommitmentOffset + banderwagon.UncompressedSize
leafChildrenOffset = leafC2CommitmentOffset + banderwagon.UncompressedSize
leafBalanceSize = 32
leafNonceSize = 8
leafBasicDataSize = 32
leafSlotSize = 32
leafValueIndexSize = 1
singleSlotLeafSize = nodeTypeSize + StemSize + 2*banderwagon.UncompressedSize + leafValueIndexSize + leafSlotSize
eoaLeafSize = nodeTypeSize + StemSize + 2*banderwagon.UncompressedSize + leafBalanceSize + leafNonceSize
eoaLeafSize = nodeTypeSize + StemSize + 2*banderwagon.UncompressedSize + leafBasicDataSize
)

func bit(bitlist []byte, nr int) bool {
Expand Down Expand Up @@ -138,14 +137,8 @@ func parseLeafNode(serialized []byte, depth byte) (VerkleNode, error) {
func parseEoAccountNode(serialized []byte, depth byte) (VerkleNode, error) {
var values [NodeWidth][]byte
offset := leafStemOffset + StemSize + 2*banderwagon.UncompressedSize
values[0] = zero32[:] // 0 version
values[1] = serialized[offset : offset+leafBalanceSize] // balance
var nonce [32]byte
offset += leafBalanceSize
copy(nonce[:leafNonceSize], serialized[offset:offset+leafNonceSize])
values[2] = nonce[:] // nonce
values[3] = EmptyCodeHash[:]
values[4] = zero32[:] // 0 code size
values[0] = serialized[offset : offset+leafBasicDataSize] // basic data
values[1] = EmptyCodeHash[:]
ln := NewLeafNodeWithNoComms(serialized[leafStemOffset:leafStemOffset+StemSize], values[:])
ln.setDepth(depth)
ln.c1 = new(Point)
Expand Down
26 changes: 8 additions & 18 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,6 @@ func (n *InternalNode) serializeInternalWithUncompressedCommitment(pointsIdx map
}

var (
zero24 [24]byte
zero32 [32]byte
EmptyCodeHash, _ = hex.DecodeString("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")
)
Expand All @@ -1845,7 +1844,7 @@ func (n *LeafNode) serializeLeafWithUncompressedCommitments(cBytes, c1Bytes, c2B
children := make([]byte, 0, NodeWidth*LeafValueSize)
var (
bitlist [bitlistSize]byte
isEoA = false // TODO: EoA serialization optimization is broken -- re-enable when fixed.
isEoA = true
count, lastIdx int
)
for i, v := range n.values {
Expand All @@ -1863,29 +1862,17 @@ func (n *LeafNode) serializeLeafWithUncompressedCommitments(cBytes, c1Bytes, c2B
switch i {
case 0:
// Version should be 0
isEoA = v != nil && bytes.Equal(v, zero32[:])
case 1:
// Balance should not be nil
isEoA = v != nil
case 2:
// Nonce should have its last 24 bytes set to 0
isEoA = v != nil && bytes.Equal(v[leafNonceSize:], zero24[:])
case 3:
case 1:
// Code hash should be the empty code hash
isEoA = v != nil && bytes.Equal(v, EmptyCodeHash[:])
case 4:
// Code size must be 0
isEoA = v != nil && bytes.Equal(v, zero32[:])
default:
// All other values must be nil
isEoA = v == nil
}
}
}

// TODO: single slot serialization optimization is apparently broken -- force disabling it until is fixed.
count = 256

// Create the serialization.
var result []byte
switch {
Expand All @@ -1894,7 +1881,11 @@ func (n *LeafNode) serializeLeafWithUncompressedCommitments(cBytes, c1Bytes, c2B
result = buf[:]
result[0] = singleSlotType
copy(result[leafStemOffset:], n.stem[:StemSize])
copy(result[leafStemOffset+StemSize:], c1Bytes[:])
if lastIdx < 128 {
copy(result[leafStemOffset+StemSize:], c1Bytes[:])
} else {
copy(result[leafStemOffset+StemSize:], c2Bytes[:])
}
copy(result[leafStemOffset+StemSize+banderwagon.UncompressedSize:], cBytes[:])
result[leafStemOffset+StemSize+2*banderwagon.UncompressedSize] = byte(lastIdx)
copy(result[leafStemOffset+StemSize+2*banderwagon.UncompressedSize+leafValueIndexSize:], n.values[lastIdx][:])
Expand All @@ -1905,8 +1896,7 @@ func (n *LeafNode) serializeLeafWithUncompressedCommitments(cBytes, c1Bytes, c2B
copy(result[leafStemOffset:], n.stem[:StemSize])
copy(result[leafStemOffset+StemSize:], c1Bytes[:])
copy(result[leafStemOffset+StemSize+banderwagon.UncompressedSize:], cBytes[:])
copy(result[leafStemOffset+StemSize+2*banderwagon.UncompressedSize:], n.values[1]) // copy balance
copy(result[leafStemOffset+StemSize+2*banderwagon.UncompressedSize+leafBalanceSize:], n.values[2][:leafNonceSize]) // copy nonce
copy(result[leafStemOffset+StemSize+2*banderwagon.UncompressedSize:], n.values[0]) // copy basic data
default:
result = make([]byte, nodeTypeSize+StemSize+bitlistSize+3*banderwagon.UncompressedSize+len(children))
result[0] = leafType
Expand Down

0 comments on commit 7dd8079

Please sign in to comment.