Skip to content

Commit 95e8aa0

Browse files
authored
Merge pull request #2346 from CortexFoundation/dev
add ComputeCells functionality
2 parents 3aea23c + fa08789 commit 95e8aa0

44 files changed

Lines changed: 16161 additions & 7 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/devp2p/all-nodes.json

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"0d70310b22266a9f07ffeec5dde9005dc49d4b118ab626db7d22de6deb4b8a15": {
3+
"seq": 1687909479048,
4+
"record": "enr:-J64QDkN6FAicxxGJGFSY5eAj9LlH1tQJ8z55lxe0_JMIcP8bMvFziuLtyEIK_rLvZ6O1Pu9aj0GE6osZEkuMG1WC0WGAYj_PrKIhGN0eGPHxoR1STAggIJpZIJ2NIJpcIQ2-kMUiXNlY3AyNTZrMaED2P6EeWi2jABOn1RyjoZv1LAWNzimk1154Fb7lrAX3YeDdGNwgp3Ug3VkcIKd1A",
5+
"score": 1,
6+
"firstResponse": "2023-09-04T16:10:07Z",
7+
"lastResponse": "2023-09-04T16:10:07Z",
8+
"lastCheck": "2023-09-04T16:10:07Z"
9+
},
10+
"17b61ce235e502d93accff547f0a441657fed0d7c38edb68709bedfe234ef6b0": {
11+
"seq": 1663938086426,
12+
"record": "enr:-J64QOkHqiSccKzEGjAuo42rsfyA8NDJ3p5Hzi-tjCQXl9v2cVxirSc-iUlJyBDPJX7xLJ0EYHJRzG_uAERm2VCKwD6GAYNqcEYahGN0eGPHxoR1STAggIJpZIJ2NIJpcIQ0T5noiXNlY3AyNTZrMaED5uj_lRJMG9tbeZoGMNZi6Fk_173lYZUpWO_7WrycEcaDdGNwgp3Ug3VkcIKd1A",
13+
"score": 1,
14+
"firstResponse": "2023-09-04T16:09:08Z",
15+
"lastResponse": "2023-09-04T16:09:08Z",
16+
"lastCheck": "2023-09-04T16:09:08Z"
17+
},
18+
"28fd063ae85ff6a2697358624bea12e76c6de1872269efcb3c5f77b98feb25ae": {
19+
"seq": 1663746060166,
20+
"record": "enr:-J64QIA2vlREvlCj0BwEvnK-qwfGLQIB13U2DbImXVYW4f1SL470x--dRN0kzOT-H5SiU2IsN6YIK6fxqGFqW861yL6GAYNe_i-GhGN0eGPHxoR1STAggIJpZIJ2NIJpcISodyNviXNlY3AyNTZrMaECB53Hr-uNb09Y3praTnedKXGX8HcM0Wyl8oW-CZON-jGDdGNwgp3Rg3VkcIKd0Q",
21+
"score": 56,
22+
"firstResponse": "2023-08-31T20:19:24Z",
23+
"lastResponse": "2023-09-04T16:08:45Z",
24+
"lastCheck": "2023-09-04T16:08:45Z"
25+
},
26+
"3df7ffd1791a412f42fae0724f3031bcca4717c6b255825eab0a25b3d98e1c6a": {
27+
"seq": 1669107904462,
28+
"record": "enr:-J64QIrD7ufnp9PooYil0I3SX7xMaBtsX0M82N72N9nCFl8SRJjQw3y5NFJpu2n0fbRQ5vXrWH1DUs0q3p1Yij1runOGAYSelW_OhGN0eGPHxoR1STAggIJpZIJ2NIJpcIQPpWLniXNlY3AyNTZrMaECgNrPJ667w9xt0VcXL3FSYiXKAEMvhs0OtUq_94YguGCDdGNwgp3Ug3VkcIKd1A",
29+
"score": 1,
30+
"firstResponse": "2023-09-04T16:09:21Z",
31+
"lastResponse": "2023-09-04T16:09:21Z",
32+
"lastCheck": "2023-09-04T16:09:21Z"
33+
},
34+
"5611a71e8fe03466cc481e89300bfe26997a114eff38d05a21ca90faf43e5efb": {
35+
"seq": 1666071650654,
36+
"record": "enr:-J64QKzobYa6E9XwI-GyQnyxP5kizhXhDyvw009Q-itcxkKFG8uyC2fKxIGUaQ8QG1T3GeyKJ_vvMHfXBLW2u6TBdjiGAYPpm-FehGN0eGPHxoR1STAggIJpZIJ2NIJpcIQnaquUiXNlY3AyNTZrMaED2sGZaji3kxV0mghyisKFSBYBAr8LhXc2hpLQMdRanaaDdGNwgp3Ug3VkcIKd1A",
37+
"score": 3209,
38+
"firstResponse": "2022-11-16T06:29:44Z",
39+
"lastResponse": "2023-09-04T16:08:47Z",
40+
"lastCheck": "2023-09-04T16:08:47Z"
41+
},
42+
"585b1abb2395950103d95e9190d7b68e94526cf999ceb7fc437dad8cdde8f267": {
43+
"seq": 1673976666539,
44+
"record": "enr:-J64QFi4wwEoeGp0wWorG_BD0T9XBGKkWthYr-Q8jEHLS6uhO8lXjuaKH6i46gTFbsMtq6OlVbM3S2t8fLYzHrrzjcKGAYXAyNmrhGN0eGPHxoR1STAggIJpZIJ2NIJpcISodwhniXNlY3AyNTZrMaED-TKUfG5Yn3yUTp8fitvk_aE1uS0k5voPSpSLIbVPvcCDdGNwgp3Rg3VkcIKd0Q",
45+
"score": 83,
46+
"firstResponse": "2023-07-31T18:37:42Z",
47+
"lastResponse": "2023-09-04T16:08:50Z",
48+
"lastCheck": "2023-09-04T16:08:50Z"
49+
},
50+
"681ad041cc186dee570e98a3578a5d9169540f348e5347704b87c57396fc3178": {
51+
"seq": 1693843722516,
52+
"record": "enr:-Iq4QC-to08uhYLSJkNsYZQIffQfUtR4Aogqb0Z8i09R2cciQzJ-AKpPS_cvRduW7s-jd3YW0Df8jmUe_osQYtI0ZSGGAYpg9BEUgmlkgnY0gmlwhC9bkyWJc2VjcDI1NmsxoQKFTpfV6M3335w39RKKQ0KgwleX0nJ1o5xt-ledbuRmnoN1ZHCCpYg",
53+
"score": 1,
54+
"firstResponse": "2023-09-04T16:09:47Z",
55+
"lastResponse": "2023-09-04T16:09:47Z",
56+
"lastCheck": "2023-09-04T16:09:47Z"
57+
},
58+
"802942cadf0fab27e908bb3b47794a8b30de809e86602d176d600551b5aa4585": {
59+
"seq": 1693775821254,
60+
"record": "enr:-Iq4QK_lfPJHFgHxdeAOAZJv3SEthv68gbooYfotIHX3cNA0Kmm_nrlrC4ReJKUSvq9fRsuV_z9Etdbvdt5yNbE8IA2GAYpc5_nGgmlkgnY0gmlwhIvEIMCJc2VjcDI1NmsxoQN5KiQXYeaZXfpm6A-Xi8_AkKu9NuB0EOTbl-pMijvR_oN1ZHCCuHY",
61+
"score": 1,
62+
"firstResponse": "2023-09-03T21:30:35Z",
63+
"lastResponse": "2023-09-03T21:40:35Z",
64+
"lastCheck": "2023-09-04T16:08:52Z"
65+
},
66+
"810ddfc582dfb2da8c2af8497df13036b4fc91352ce3600854b3fbdc77afc644": {
67+
"seq": 1678519680353,
68+
"record": "enr:-J64QC5Ews5t7nSXBoZPm_t96eONYkwizDoEz1ZQRpKJjCBEBLIDCpBwHAoQHLjdoEERa8VRQC-DrySP6TpM5L4fenuGAYbPkb1hhGN0eGPHxoR1STAggIJpZIJ2NIJpcIQth-eGiXNlY3AyNTZrMaEDyHMt4YHuNYHfst8TypewYrhAqwNUCfyvS0RL3kT78amDdGNwgkuCg3VkcIJLgg",
69+
"score": 1,
70+
"firstResponse": "2023-09-04T16:10:36Z",
71+
"lastResponse": "2023-09-04T16:10:36Z",
72+
"lastCheck": "2023-09-04T16:10:36Z"
73+
},
74+
"a34e58fb385c2cdb968da03b31aee6e2d10fbddef88785e0a9517621294f00e5": {
75+
"seq": 1670573564045,
76+
"record": "enr:-J64QLvn8BTYKQ95OTqh8FZpiPaUL_tktIvLop7O8hPA0BvYGpJHU6VE9Qn8K8olmBXc1bHeJLZm9uU3QOqHdww-_MiGAYT18aCNhGN0eGPHxoR1STAggIJpZIJ2NIJpcISYWSWqiXNlY3AyNTZrMaED8dDYTljRfxGYfKh1qnvvhoXV1-f5nR15xAyYdsh-8hiDdGNwgkuCg3VkcIJLgg",
77+
"score": 1,
78+
"firstResponse": "2023-09-04T16:11:29Z",
79+
"lastResponse": "2023-09-04T16:11:29Z",
80+
"lastCheck": "2023-09-04T16:11:29Z"
81+
},
82+
"c8097bd007f3951930dc1430482b458d6da907b308fc259359a1624ed4bc7edd": {
83+
"seq": 1682275788048,
84+
"record": "enr:-J64QGQN9zttLnIWzAYzMJyUCIm22ZU3O_3kkhtTpjAecxrKTjf3xIPBx4mVvK8GKEhj3VbUHPpdwloldvyF2KVlY8iGAYevc2UQhGN0eGPHxoR1STAggIJpZIJ2NIJpcISiE4u1iXNlY3AyNTZrMaEDv86GC2rQqV0qb6g-eK6nxzYRk10Rz_U0FmBpmQZ6jCeDdGNwgp3gg3VkcIKd4A",
85+
"score": 15,
86+
"firstResponse": "2023-08-27T03:37:23Z",
87+
"lastResponse": "2023-09-04T16:08:55Z",
88+
"lastCheck": "2023-09-04T16:08:55Z"
89+
},
90+
"d6c5b797a1e4c83c01aaca7c27d2431cd9be1841083fe40b19f8d97258744196": {
91+
"seq": 1669307652177,
92+
"record": "enr:-J64QD-zdKVxfjqdgM_8EHKY8gITlC41SdMyZPq0uqnuw9mvN53guhYkQ_p6rJD0L9oS1nyZ1FkEb5kAcFP-nRA4EoaGAYSqfVhRhGN0eGPHxoR1STAggIJpZIJ2NIJpcIRcJpaTiXNlY3AyNTZrMaECCG9SzWbuRFrVEwMHNG9NB6qXY43W4yWgV1T1YWODW6KDdGNwgkuCg3VkcIJLgg",
93+
"score": 1,
94+
"firstResponse": "2023-09-04T16:09:55Z",
95+
"lastResponse": "2023-09-04T16:09:55Z",
96+
"lastCheck": "2023-09-04T16:09:55Z"
97+
},
98+
"ea254a88945ee5a79fe978021fa84d01b3e46dc2f3aea4512a390176149ab4af": {
99+
"seq": 1680088140084,
100+
"record": "enr:-J64QOdwqoW1EWNpgVsdF1K_WmUHtubOhEQVSjnbT_41slP0FQU9_uVLGMn4weYFecNvetnVW1iUB22J_y2rVTv4PBSGAYctDok0hGN0eGPHxoR1STAggIJpZIJ2NIJpcIQbFU9MiXNlY3AyNTZrMaED7E7VEAwy-nrbczGLoZw6Fs_eT_vRldMpZT9vIe_jSMaDdGNwgp3Ug3VkcIKd1A",
101+
"score": 45,
102+
"firstResponse": "2023-03-30T10:38:33Z",
103+
"lastResponse": "2023-09-03T21:37:36Z",
104+
"lastCheck": "2023-09-04T16:09:00Z"
105+
},
106+
"f25b08f13d9a5b98d059942f9ef558b79de2951d3791ce3733632516781cf55f": {
107+
"seq": 1683013232427,
108+
"record": "enr:-J64QEx4U7mqzVlr27BkODfR-WqQlmGdNJjW9oLAGomXQtOIFMYm2R1m_ewcLaa3OIWtyOBZ6P2JlAgPdKC-LvKsQPKGAYfbZ-crhGN0eGPHxoR1STAggIJpZIJ2NIJpcISiE4u1iXNlY3AyNTZrMaEDKaP-B2bOL85XhpdsEZjCj77uqajHdW5rrMpPKvED7TuDdGNwgp3Wg3VkcIKd1g",
109+
"score": 10,
110+
"firstResponse": "2023-08-28T14:28:18Z",
111+
"lastResponse": "2023-09-04T16:09:02Z",
112+
"lastCheck": "2023-09-04T16:09:02Z"
113+
},
114+
"f64dbfe8f95aaf5b858187e4ce34a3e15a02bac7289e21985e246887f07eecfb": {
115+
"seq": 1672026912247,
116+
"record": "enr:-J64QIPY0f_kCr0ntYKknu3KMRRlnMfEPpc-1mpbwYOnYdSqHw0Ivdl52mZOs95zZ6hotkbhnpgRXs5_nagu8qgrKhuGAYVMkfX3hGN0eGPHxoR1STAggIJpZIJ2NIJpcIQ2qLpkiXNlY3AyNTZrMaEDAJmWiBIHY_06V-yWaNRxxy_E1SeYZcLXYhfnSuwuh8uDdGNwgp3Ug3VkcIKd1A",
117+
"score": 211,
118+
"firstResponse": "2023-09-01T00:17:22Z",
119+
"lastResponse": "2023-09-04T16:09:04Z",
120+
"lastCheck": "2023-09-04T16:09:04Z"
121+
},
122+
"f9f2278feb4c107786eecb2da0b53b421076b2bd688f23cfbe30ef16131e7bee": {
123+
"seq": 1663680545074,
124+
"record": "enr:-J64QCArmxqERiCxJaroPIg0whtXY95ZsPpthwResiaF6OFNIXfhOaUPDBzoALqgJRiK2oFsJNEVYeqk1OPK0LWjjayGAYNbFoEyhGN0eGPHxoR1STAggIJpZIJ2NIJpcIQ27t6BiXNlY3AyNTZrMaEDlT2Zh1P-k9snhLKppX9LmMf8kw0RfuAmf1KVn51NX62DdGNwgp3Ug3VkcIKd1A",
125+
"score": 1,
126+
"firstResponse": "2023-09-03T21:30:34Z",
127+
"lastResponse": "2023-09-03T21:40:50Z",
128+
"lastCheck": "2023-09-04T16:09:03Z"
129+
}
130+
}

cmd/utils/flags.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,10 +1718,15 @@ func SetCortexConfig(ctx *cli.Context, stack *node.Node, cfg *ctxc.Config) {
17181718
if ctx.String(CryptoKZGFlag.Name) != "gokzg" && ctx.String(CryptoKZGFlag.Name) != "ckzg" {
17191719
Fatalf("--%s flag must be 'gokzg' or 'ckzg'", CryptoKZGFlag.Name)
17201720
}
1721-
log.Info("Initializing the KZG library", "backend", ctx.String(CryptoKZGFlag.Name))
1722-
if err := kzg4844.UseCKZG(ctx.String(CryptoKZGFlag.Name) == "ckzg"); err != nil {
1723-
Fatalf("Failed to set KZG library implementation to %s: %v", ctx.String(CryptoKZGFlag.Name), err)
1724-
}
1721+
// The initialization of the KZG library can take up to 2 seconds
1722+
// We start this here in parallel, so it should be available
1723+
// once we start executing blocks. It's threadsafe.
1724+
go func() {
1725+
log.Info("Initializing the KZG library", "backend", ctx.String(CryptoKZGFlag.Name))
1726+
if err := kzg4844.UseCKZG(ctx.String(CryptoKZGFlag.Name) == "ckzg"); err != nil {
1727+
Fatalf("Failed to set KZG library implementation to %s: %v", ctx.String(CryptoKZGFlag.Name), err)
1728+
}
1729+
}()
17251730
}
17261731

17271732
// setDNSDiscoveryDefaults configures DNS discovery with the given URL if

crypto/kzg4844/kzg4844.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ func VerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error {
149149
return gokzgVerifyBlobProof(blob, commitment, proof)
150150
}
151151

152+
// ComputeCellProofs returns the KZG cell proofs that are used to verify the blob against
153+
// the commitment.
154+
//
155+
// This method does not verify that the commitment is correct with respect to blob.
156+
func ComputeCellProofs(blob *Blob) ([]Proof, error) {
157+
if useCKZG.Load() {
158+
return ckzgComputeCellProofs(blob)
159+
}
160+
return gokzgComputeCellProofs(blob)
161+
}
162+
152163
// CalcBlobHashV1 calculates the 'versioned blob hash' of a commitment.
153164
// The given hasher must be a sha256 hash instance, otherwise the result will be invalid!
154165
func CalcBlobHashV1(hasher hash.Hash, commit *Commitment) (vh [32]byte) {

crypto/kzg4844/kzg4844_ckzg_cgo.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,21 @@ func ckzgInit() {
4747
if err = gokzg4844.CheckTrustedSetupIsWellFormed(params); err != nil {
4848
panic(err)
4949
}
50-
g1s := make([]byte, len(params.SetupG1Lagrange)*(len(params.SetupG1Lagrange[0])-2)/2)
50+
g1Lag := make([]byte, len(params.SetupG1Lagrange)*(len(params.SetupG1Lagrange[0])-2)/2)
5151
for i, g1 := range params.SetupG1Lagrange {
52+
copy(g1Lag[i*(len(g1)-2)/2:], hexutil.MustDecode(g1))
53+
}
54+
g1s := make([]byte, len(params.SetupG1Monomial)*(len(params.SetupG1Monomial[0])-2)/2)
55+
for i, g1 := range params.SetupG1Monomial {
5256
copy(g1s[i*(len(g1)-2)/2:], hexutil.MustDecode(g1))
5357
}
5458
g2s := make([]byte, len(params.SetupG2)*(len(params.SetupG2[0])-2)/2)
5559
for i, g2 := range params.SetupG2 {
5660
copy(g2s[i*(len(g2)-2)/2:], hexutil.MustDecode(g2))
5761
}
58-
if err = ckzg4844.LoadTrustedSetup(g1s, g2s); err != nil {
62+
// The last parameter determines the multiplication table, see https://notes.ethereum.org/@jtraglia/windowed_multiplications
63+
// I think 6 is an decent compromise between size and speed
64+
if err = ckzg4844.LoadTrustedSetup(g1s, g1Lag, g2s, 6); err != nil {
5965
panic(err)
6066
}
6167
}
@@ -125,3 +131,21 @@ func ckzgVerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error {
125131
}
126132
return nil
127133
}
134+
135+
// ckzgComputeCellProofs returns the KZG cell proofs that are used to verify the blob against
136+
// the commitment.
137+
//
138+
// This method does not verify that the commitment is correct with respect to blob.
139+
func ckzgComputeCellProofs(blob *Blob) ([]Proof, error) {
140+
ckzgIniter.Do(ckzgInit)
141+
142+
_, proofs, err := ckzg4844.ComputeCellsAndKZGProofs((*ckzg4844.Blob)(blob))
143+
if err != nil {
144+
return []Proof{}, err
145+
}
146+
var p []Proof
147+
for _, proof := range proofs {
148+
p = append(p, (Proof)(proof))
149+
}
150+
return p, nil
151+
}

crypto/kzg4844/kzg4844_ckzg_nocgo.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,11 @@ func ckzgComputeBlobProof(blob *Blob, commitment Commitment) (Proof, error) {
6060
func ckzgVerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error {
6161
panic("unsupported platform")
6262
}
63+
64+
// ckzgComputeCellProofs returns the KZG cell proofs that are used to verify the blob against
65+
// the commitment.
66+
//
67+
// This method does not verify that the commitment is correct with respect to blob.
68+
func ckzgComputeCellProofs(blob *Blob) ([]Proof, error) {
69+
panic("unsupported platform")
70+
}

crypto/kzg4844/kzg4844_gokzg.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"encoding/json"
2121
"sync"
2222

23-
gokzg4844 "github.com/crate-crypto/go-kzg-4844"
23+
gokzg4844 "github.com/crate-crypto/go-eth-kzg"
2424
)
2525

2626
// context is the crypto primitive pre-seeded with the trusted setup parameters.
@@ -96,3 +96,21 @@ func gokzgVerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error
9696

9797
return context.VerifyBlobKZGProof((*gokzg4844.Blob)(blob), (gokzg4844.KZGCommitment)(commitment), (gokzg4844.KZGProof)(proof))
9898
}
99+
100+
// gokzgComputeCellProofs returns the KZG cell proofs that are used to verify the blob against
101+
// the commitment.
102+
//
103+
// This method does not verify that the commitment is correct with respect to blob.
104+
func gokzgComputeCellProofs(blob *Blob) ([]Proof, error) {
105+
gokzgIniter.Do(gokzgInit)
106+
107+
_, proofs, err := context.ComputeCellsAndKZGProofs((*gokzg4844.Blob)(blob), 0)
108+
if err != nil {
109+
return []Proof{}, err
110+
}
111+
var p []Proof
112+
for _, proof := range proofs {
113+
p = append(p, (Proof)(proof))
114+
}
115+
return p, nil
116+
}

0 commit comments

Comments
 (0)