Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 11 additions & 2 deletions sszgen/render/htrprogressive.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ func generateProgressiveHTR(vc *gentypes.ValueContainer, ctx *core.GenContext) (
if vc.ActiveFields == nil {
return nil, nil
}

// Inactive positions need zero leaves to preserve the positions of later fields.
steps := make([]string, 0)
for i, c := range vc.Contents {
i := 0
for pos, active := range vc.ActiveFields {
if !active {
steps = append(steps, fmt.Sprintf("\t// Position %d: inactive (zero chunk)\n\thh.PutBool(false)", pos))
continue
}
c := vc.Contents[i]
ref := fmt.Sprintf("%s.%s", htrReceiver, c.Key)
steps = append(steps, fmt.Sprintf("\t// Field %d: %s", i, c.Key))
steps = append(steps, fmt.Sprintf("\t// Position %d: %s", pos, c.Key))
steps = append(steps, core.Dispatch(htrOp{field: c.Key}, c.Value, ref, ctx))
i++
}
buf := bytes.NewBuffer(nil)
err := progressiveHTRTmpl.Execute(buf, struct {
Expand Down
12 changes: 7 additions & 5 deletions sszgen/render/testdata/progressive.ssz.go.expected
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ func (c *Prog) ProgressiveHashTreeRoot() ([32]byte, error) {

func (c *Prog) ProgressiveHashTreeRootWith(hh *ssz.Hasher) (err error) {
indx := hh.Index()
// Field 0: A
// Position 0: A
hh.PutUint64(c.A)
// Field 1: B
// Position 1: B
{
subIndx := hh.Index()
for _, o := range c.B {
Expand All @@ -238,7 +238,9 @@ func (c *Prog) ProgressiveHashTreeRootWith(hh *ssz.Hasher) (err error) {
hh.FillUpTo32()
hh.MerkleizeProgressiveWithMixin(subIndx, uint64(len(c.B)))
}
// Field 2: C
// Position 2: inactive (zero chunk)
hh.PutBool(false)
// Position 3: C
{
subIndx := hh.Index()
for _, o := range c.C {
Expand All @@ -248,12 +250,12 @@ func (c *Prog) ProgressiveHashTreeRootWith(hh *ssz.Hasher) (err error) {
}
hh.MerkleizeProgressiveWithMixin(subIndx, uint64(len(c.C)))
}
// Field 3: D
// Position 4: D
if len(c.D) == 0 {
return ssz.ErrEmptyBitlist
}
hh.PutProgressiveBitlist(c.D)
// Field 4: E
// Position 5: E
if err := c.E.HashTreeRootWith(hh); err != nil {
return fmt.Errorf("E: %w", err)
}
Expand Down
Loading