/
mock_proof_fetcher.go
67 lines (52 loc) · 1.17 KB
/
mock_proof_fetcher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package e2eutils
import (
"context"
"math/big"
"os"
"path/filepath"
"github.com/ethereum/go-ethereum/log"
"golang.org/x/sync/errgroup"
chal "github.com/kroma-network/kroma/kroma-validator/challenge"
)
type Fetcher struct {
l log.Logger
mockPath string
}
func NewFetcher(logger log.Logger, path string) *Fetcher {
return &Fetcher{
l: logger,
mockPath: path,
}
}
func read(path string) ([]byte, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
return data, nil
}
func (f *Fetcher) FetchProofAndPair(_ context.Context, _ string) (*chal.ProofAndPair, error) {
decoded := make([][]*big.Int, 2)
files := []string{"verify_circuit_proof.data", "verify_circuit_final_pair.data"}
g, _ := errgroup.WithContext(context.Background())
for i := 0; i < len(files); i++ {
filePath := filepath.Join(f.mockPath, files[i])
i := i
g.Go(func() error {
data, err := read(filePath)
if err != nil {
return err
}
decoded[i] = chal.Decode(data)
return nil
})
}
if err := g.Wait(); err != nil {
return nil, err
}
result := &chal.ProofAndPair{
Proof: decoded[0],
Pair: decoded[1],
}
return result, nil
}