-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
65 lines (55 loc) · 1.93 KB
/
main.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
package main
import (
"blobstreamx-example/client"
shareloader "blobstreamx-example/contracts/ShareLoader.sol"
"fmt"
"os"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/tendermint/tendermint/rpc/client/http"
)
func main() {
// step 0. get eth-rpc and trpc endpoint
ethEndpoint := "https://arbitrum-sepolia-rpc.publicnode.com"
trpcEndpoint := "https://celestia-mocha-rpc.publicnode.com:443"
// See contract here: https://sepolia.arbiscan.io/contract/0xf2787995D9eb43b57eAdB361227Ddf4FEC99b5Df
// This is the address of the ShareLoader contract
// The contract wraps the DAVerifier.verifySharesToDataRootTupleRoot method
shareloaderAddress := common.HexToAddress("0xf2787995D9eb43b57eAdB361227Ddf4FEC99b5Df")
// step 1: connect to eth and trpc endpoints
eth, err := ethclient.Dial(ethEndpoint)
if err != nil {
panic(fmt.Errorf("failed to connect to the Ethereum node: %w", err))
}
trpc, err := http.New(trpcEndpoint, "/websocket")
if err != nil {
panic(fmt.Errorf("failed to connect to the Tendermint RPC: %w", err))
}
fmt.Println("Successfully connected to the Ethereum node and Tendermint RPC")
// step 2: generate share proof
sp := &client.SharePointer{
Height: 1490181,
Start: 1,
End: 14,
}
proof, root, err := client.GetShareProof(eth, trpc, sp)
if err != nil {
panic(fmt.Errorf("failed to get share proof: %w", err))
}
fmt.Println("Successfully generated share proof")
// step 3: verify the share proof
loader, err := shareloader.NewShareloader(shareloaderAddress, eth)
if err != nil {
panic(fmt.Errorf("failed to instantiate shareloader contract: %w", err))
}
valid, errCodes, err := loader.VerifyShares(nil, *proof, root)
if err != nil {
panic(fmt.Errorf("failed to verify share proof: %w", err))
}
// step 4: print the result
if !valid {
fmt.Println("Proof is invalid", "Error codes:", errCodes)
os.Exit(1)
}
fmt.Println("Proof is valid")
}