Files
linea-monorepo/prover/lib/compressor/blob/blob.go
AlexandreBelling c511121317 Prover: couple of fixes betav1 (#377)
* fix(execution): a few fixes in the wizard verifier

* feat(dict): pass the dict path from config

* fix: makeBw6Proof returns circuitID instead of -1

* fix(circuitID): make bw6Proof returns the circuitID

* fix(config-testing)

* feat(config): sepolia-full uses full aggregation

* style(naming): renaming the rolling hash fields and documenting the checks in pi-interconnection

* feat: flag for target number of constraints

* fix refactoring oversight

---------

Co-authored-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
2024-12-10 15:55:20 +01:00

67 lines
1.9 KiB
Go

package blob
import (
"bytes"
"errors"
"os"
"github.com/consensys/linea-monorepo/prover/lib/compressor/blob/dictionary"
"github.com/consensys/linea-monorepo/prover/lib/compressor/blob/encode"
v0 "github.com/consensys/linea-monorepo/prover/lib/compressor/blob/v0"
v1 "github.com/consensys/linea-monorepo/prover/lib/compressor/blob/v1"
"github.com/ethereum/go-ethereum/rlp"
)
func GetVersion(blob []byte) uint16 {
if len(blob) < 3 {
return 0
}
if blob[0] == 0x3f && blob[1] == 0xff && blob[2]&0xc0 == 0xc0 {
return 1
}
return 0
}
func GetDict(dictPath string) ([]byte, error) {
return os.ReadFile(dictPath)
}
// DecompressBlob takes in a Linea blob and outputs an RLP encoded list of RLP encoded blocks.
// Due to information loss during pre-compression encoding, two pieces of information are represented "hackily":
// The block hash is in the ParentHash field.
// The transaction from address is in the signature.R field.
func DecompressBlob(blob []byte, dictStore dictionary.Store) ([]byte, error) {
vsn := GetVersion(blob)
var (
blockDecoder func(*bytes.Reader) (encode.DecodedBlockData, error)
blocks [][]byte
err error
)
switch vsn {
case 0:
_, _, blocks, err = v0.DecompressBlob(blob, dictStore)
blockDecoder = v0.DecodeBlockFromUncompressed
case 1:
_, _, blocks, err = v1.DecompressBlob(blob, dictStore)
blockDecoder = v1.DecodeBlockFromUncompressed
default:
return nil, errors.New("unrecognized blob version")
}
if err != nil {
return nil, err
}
blocksSerialized := make([][]byte, len(blocks))
var decodedBlock encode.DecodedBlockData
for i, block := range blocks {
if decodedBlock, err = blockDecoder(bytes.NewReader(block)); err != nil {
return nil, err
}
if blocksSerialized[i], err = rlp.EncodeToBytes(decodedBlock.ToStd()); err != nil {
return nil, err
}
}
return rlp.EncodeToBytes(blocksSerialized)
}