Skip to content

Commit fb4ee00

Browse files
Prover: assignment serialization for the limitless prover (#557)
* feat(encode): implements an codex for column assignment * debug(col): add tests and debug the column assignment * experiment(encoding): adds a target to encode and decode zkevm assignment and benchmark * add lz4 compression library * add assignment serialization with compression * assign and encode in chunks instead of a file * calculate correct ser size * add num chunks variable * Revert "calculate correct ser size" This reverts commit 8ae74c6. * calculate and print the exact size of ser * add error handling for file write * add deserialization * refactor code * add compressChunks * refactor deserialize assignment * add hashWAssignment to check the hash of input and output * refactor SerializeAssignment * use logrus * remove cbor data size info * clean up logs * clean up logs for serialization * measure time taken for serialization * update logs * fix logs * set numChunks to the number of cores * skip profiling * add compression ratio * add a unit test --------- Co-authored-by: AlexandreBelling <alexandrebelling8@gmail.com>
1 parent 0568cf3 commit fb4ee00

File tree

10 files changed

+637
-2
lines changed

10 files changed

+637
-2
lines changed

prover/backend/execution/prove.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
package execution
22

33
import (
4+
"fmt"
5+
"math/rand/v2"
6+
"os"
7+
"runtime"
8+
"strconv"
9+
"time"
10+
411
"github.com/consensys/gnark-crypto/ecc"
512
"github.com/consensys/linea-monorepo/prover/circuits"
613
"github.com/consensys/linea-monorepo/prover/circuits/dummy"
714
"github.com/consensys/linea-monorepo/prover/circuits/execution"
815
"github.com/consensys/linea-monorepo/prover/config"
16+
"github.com/consensys/linea-monorepo/prover/protocol/serialization"
917
public_input "github.com/consensys/linea-monorepo/prover/public-input"
1018
"github.com/consensys/linea-monorepo/prover/utils"
1119
"github.com/consensys/linea-monorepo/prover/utils/profiling"
@@ -179,6 +187,31 @@ func mustProveAndPass(
179187
logrus.Infof("Prover checks passed")
180188
return "", ""
181189

190+
case config.ProverModeEncodeOnly:
191+
192+
profiling.ProfileTrace("encode-decode-no-circuit", true, false, func() {
193+
filepath := "/tmp/wizard-assignment/blob-" + strconv.Itoa(rand.Int()) + ".bin"
194+
195+
encodeOnlyZkEvm := zkevm.EncodeOnlyZkEvm(traces)
196+
numChunks := runtime.GOMAXPROCS(0)
197+
198+
// Serialize the assignment
199+
encodingDuration := time.Now()
200+
encodeOnlyZkEvm.AssignAndEncodeInChunks(filepath, w.ZkEVM, numChunks)
201+
202+
// Deserialize the assignment
203+
decodingDuration := time.Now()
204+
_, errDec := serialization.DeserializeAssignment(filepath, numChunks)
205+
if errDec != nil {
206+
panic(fmt.Sprintf("Error during deserialization: %v", errDec))
207+
}
208+
fmt.Printf("[Encoding Summary] took %v sec to encode an assignmente and write it into the files \n", time.Since(encodingDuration).Seconds())
209+
fmt.Printf("[Decoding Summary] took %v sec to read the files and decode it into an assignment\n", time.Since(decodingDuration).Seconds())
210+
})
211+
212+
os.Exit(0)
213+
return "", ""
214+
182215
default:
183216
panic("not implemented")
184217
}

prover/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ type Execution struct {
203203
WithRequestDir `mapstructure:",squash"`
204204

205205
// ProverMode stores the kind of prover to use.
206-
ProverMode ProverMode `mapstructure:"prover_mode" validate:"required,oneof=dev partial full proofless bench check-only"`
206+
ProverMode ProverMode `mapstructure:"prover_mode" validate:"required,oneof=dev partial full proofless bench check-only encode-only"`
207207

208208
// CanRunFullLarge indicates whether the prover is running on a large machine (and can run full large traces).
209209
CanRunFullLarge bool `mapstructure:"can_run_full_large"`

prover/config/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ const (
2626
// in a context where it is simpler to not have to deal with the setup.
2727
ProverModeBench ProverMode = "bench"
2828
// ProverModeCheckOnly is used to test the constraints of the whole system
29-
ProverModeCheckOnly ProverMode = "check-only"
29+
ProverModeCheckOnly ProverMode = "check-only"
30+
ProverModeEncodeOnly ProverMode = "encode-only"
3031
)

prover/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ require (
7676
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
7777
github.com/olekukonko/tablewriter v0.0.5 // indirect
7878
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
79+
github.com/pierrec/lz4/v4 v4.1.21 // indirect
7980
github.com/prometheus/client_model v0.6.1 // indirect
8081
github.com/prometheus/common v0.55.0 // indirect
8182
github.com/prometheus/procfs v0.15.1 // indirect

prover/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FI
369369
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
370370
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
371371
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
372+
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
373+
github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
372374
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
373375
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
374376
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=

prover/maths/common/smartvectors/windowed.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ func (p *PaddedCircularWindow) Len() int {
4747
return p.totLen
4848
}
4949

50+
// Offset returns the offset of the PCW
51+
func (p *PaddedCircularWindow) Offset() int {
52+
return p.offset
53+
}
54+
55+
// Windows returns the length of the window of the PCQ
56+
func (p *PaddedCircularWindow) Window() []field.Element {
57+
return p.window
58+
}
59+
60+
// PaddingVal returns the value used for padding the window
61+
func (p *PaddedCircularWindow) PaddingVal() field.Element {
62+
return p.paddingVal
63+
}
64+
5065
// Returns a queries position
5166
func (p *PaddedCircularWindow) GetBase(n int) (field.Element, error) {
5267
// Check if the queried index is in the window

0 commit comments

Comments
 (0)