MCPcopy Create free account
hub / github.com/ethstorage/es-node / Encode

Function Encode

ethstorage/encoder/encoder.go:18–56  ·  view source on GitHub ↗
(hash common.Hash, size int)

Source from the content-addressed store, hash-verified

16)
17
18func Encode(hash common.Hash, size int) ([]byte, error) {
19 if size%64 != 0 {
20 return nil, errors.New("size must be a multiple of 64")
21 }
22
23 initialState := big.NewInt(0)
24
25 k := big.NewInt(0).SetBytes(hash.Bytes())
26
27 // TODO: simple hash to point mapping
28 k.Mod(k, constants.Q)
29
30 elements := make([]*ff.Element, 0)
31 for i := 0; i < size/64; i++ {
32 k1 := new(big.Int).Add(k, big.NewInt(int64(i)))
33 k2 := new(big.Int).Add(k, big.NewInt(int64(i+1)))
34 hs, _ := poseidon.HashState(initialState, []*big.Int{k1, k2})
35 elements = append(elements, hs[0], hs[1])
36 }
37
38 pol := make([]fr.Element, len(elements))
39 for i := 0; i < len(elements); i++ {
40 bs := elements[i].Bytes()
41 pol[i].SetBytes(bs[:])
42 }
43
44 domainWithPrecompute := fft.NewDomain(uint64(len(elements)))
45 domainWithPrecompute.FFT(pol, fft.DIF)
46
47 fft.BitReverse(pol)
48
49 returnData := make([]byte, 0)
50 for _, e := range pol {
51 bs := e.Bytes()
52 returnData = append(returnData, bs[:]...)
53 }
54
55 return returnData, nil
56}

Callers 3

GenerateMaskFunction · 0.92
encodeChunkFunction · 0.92
decodeChunkFunction · 0.92

Calls

no outgoing calls

Tested by 1

GenerateMaskFunction · 0.74