Skip to content

Commit b41eb8e

Browse files
committed
change byte layout of deduplicated file due to too many vanities (>64) in Sepolia data
1 parent c8ce9d9 commit b41eb8e

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

rollup/missing_header_fields/export-headers-toolkit/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ Where:
2929
- unique_vanity_i: unique vanity i
3030
- header_i: block header i
3131
- header:
32-
<flags:uint8><seal:[65|85]byte>
32+
<flags:uint8><vanity_index:uint8><seal:[65|85]byte>
3333
- flags: bitmask, lsb first
34-
- bit 0-5: index of the vanity in the sorted vanities list
3534
- bit 6: 0 if difficulty is 2, 1 if difficulty is 1
3635
- bit 7: 0 if seal length is 65, 1 if seal length is 85
3736
```

rollup/missing_header_fields/export-headers-toolkit/cmd/dedup.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,6 @@ func verifyOutputFile(verifyFile, outputFile string) {
293293
log.Fatalf("ExtraData mismatch: headerNum %d: %x != %x", header.Number, header.ExtraData, extraData)
294294
}
295295
}
296+
297+
log.Printf("All headers match in %s and %s\n", verifyFile, outputFile)
296298
}

rollup/missing_header_fields/export-headers-toolkit/cmd/missing_header_reader.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,20 @@ func (r *Reader) ReadNext() (difficulty uint64, extraData []byte, err error) {
8686

8787
bits := newBitMaskFromByte(bitmaskByte)
8888

89+
// read the vanity index
90+
vanityIndex, err := r.reader.ReadByte()
91+
if err != nil {
92+
return 0, nil, fmt.Errorf("failed to read vanity index: %v", err)
93+
}
94+
8995
seal := make([]byte, bits.sealLen())
9096

9197
if _, err = io.ReadFull(r.reader, seal); err != nil {
9298
return 0, nil, fmt.Errorf("failed to read seal: %v", err)
9399
}
94100

95101
// construct the extraData field
96-
vanity := r.sortedVanities[bits.vanityIndex()]
102+
vanity := r.sortedVanities[int(vanityIndex)]
97103
var b bytes.Buffer
98104
b.Write(vanity[:])
99105
b.Write(seal)

rollup/missing_header_fields/export-headers-toolkit/cmd/missing_header_writer.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import (
55
"bytes"
66
"io"
77
"log"
8+
"math"
89
"os"
910
"sort"
1011

1112
"github.com/scroll-tech/go-ethereum/export-headers-toolkit/types"
1213
)
1314

14-
// maxVanityCount is the maximum number of unique vanities that can be represented with 6 bits in the bitmask
15-
const maxVanityCount = 1 << 6
15+
// maxVanityCount is the maximum number of unique vanities that can be represented with a single byte.
16+
const maxVanityCount = math.MaxUint8
1617

1718
type missingHeaderFileWriter struct {
1819
file *os.File
@@ -94,21 +95,27 @@ func (m *missingHeaderWriter) writeVanities() {
9495

9596
func (m *missingHeaderWriter) write(header *types.Header) {
9697
// 1. prepare the bitmask
97-
bits := newBitMask(m.sortedVanitiesMap[header.Vanity()], int(header.Difficulty), header.SealLen())
98+
bits := newBitMask(int(header.Difficulty), header.SealLen())
99+
vanityIndex := m.sortedVanitiesMap[header.Vanity()]
98100

99-
// 2. write the header: bitmask and seal
101+
if vanityIndex >= maxVanityCount {
102+
log.Fatalf("Vanity index %d exceeds maximum allowed %d", vanityIndex, maxVanityCount-1)
103+
}
104+
105+
// 2. write the header: bitmask, vanity index and seal
100106
if _, err := m.writer.Write(bits.Bytes()); err != nil {
101107
log.Fatalf("Error writing bitmask: %v", err)
102108
}
103-
109+
if _, err := m.writer.Write([]byte{uint8(vanityIndex)}); err != nil {
110+
log.Fatalf("Error writing vanity index: %v", err)
111+
}
104112
if _, err := m.writer.Write(header.Seal()); err != nil {
105113
log.Fatalf("Error writing seal: %v", err)
106114
}
107115
}
108116

109117
// bitMask is a bitmask that encodes the following information:
110118
//
111-
// bit 0-5: index of the vanity in the sorted vanities list
112119
// bit 6: 0 if difficulty is 2, 1 if difficulty is 1
113120
// bit 7: 0 if seal length is 65, 1 if seal length is 85
114121
type bitMask struct {
@@ -119,14 +126,9 @@ func newBitMaskFromByte(b uint8) bitMask {
119126
return bitMask{b}
120127
}
121128

122-
func newBitMask(vanityIndex int, difficulty int, sealLen int) bitMask {
129+
func newBitMask(difficulty int, sealLen int) bitMask {
123130
b := uint8(0)
124131

125-
if vanityIndex >= maxVanityCount {
126-
log.Fatalf("Vanity index exceeds maximum: %d >= %d", vanityIndex, maxVanityCount)
127-
}
128-
b |= uint8(vanityIndex) & 0b00111111
129-
130132
if difficulty == 1 {
131133
b |= 1 << 6
132134
} else if difficulty != 2 {
@@ -142,10 +144,6 @@ func newBitMask(vanityIndex int, difficulty int, sealLen int) bitMask {
142144
return bitMask{b}
143145
}
144146

145-
func (b bitMask) vanityIndex() int {
146-
return int(b.b & 0b00111111)
147-
}
148-
149147
func (b bitMask) difficulty() int {
150148
val := (b.b >> 6) & 0x01
151149
if val == 0 {

0 commit comments

Comments
 (0)