Skip to content

Commit d62ad82

Browse files
authored
Blobstream integration (#8)
* feat(celestiada): add DAVerifier type * feat: add DaVerifier logic * chore: forge init * forge install: forge-std v1.8.2 * forge install: blobstream-contracts v4.1.0 * add BlobstreamVerifier contracts - add /celestia/verify/:txHash endpoint * deploy sepolia verifier contract and use public rpc * add contribution
1 parent 1624510 commit d62ad82

File tree

18 files changed

+4033
-50
lines changed

18 files changed

+4033
-50
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "celestiada/verify/contracts/lib/forge-std"]
2+
path = celestiada/verify/contracts/lib/forge-std
3+
url = https://github.com/foundry-rs/forge-std
4+
[submodule "celestiada/verify/contracts/lib/blobstream-contracts"]
5+
path = celestiada/verify/contracts/lib/blobstream-contracts
6+
url = https://github.com/celestiaorg/blobstream-contracts

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,6 @@ cp .env.example .env
7676

7777
## Built with
7878
- `go-da` and `celestia-da` libraries from [Rollkit](https://github.com/rollkit/go-da)
79+
- `blobstreamx-example` repo from [CryptoKass](https://github.com/CryptoKass/blobstreamx-example)
7980

8081

celestiada/verify/bindings/BlobstreamVerifier/BlobstreamVerifier.go

Lines changed: 300 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

celestiada/verify/bindings/BlobstreamX/BlobstreamX.go

Lines changed: 3028 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

celestiada/verify/commitment.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package verify
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/stackrlabs/go-daash/celestiada/verify/bindings/blobstreamx"
8+
9+
"github.com/ethereum/go-ethereum/accounts/abi/bind"
10+
"github.com/ethereum/go-ethereum/common"
11+
"github.com/ethereum/go-ethereum/ethclient"
12+
)
13+
14+
const maxFilterRange = uint64(10_000)
15+
16+
// GetDataCommitment returns the data commitment event matching the given height
17+
// within the last `blocks` blocks.
18+
// Example usage:
19+
//
20+
// dataCommitment, err := GetDataCommitment(eth, 10000, 90_000 )
21+
//
22+
// Please note this method will make atleast blocks/maxFilterRange calls to the
23+
// Ethereum node
24+
func GetDataCommitment(eth *ethclient.Client, height int64, blocks uint64, blobstreamxContract common.Address) (*blobstreamx.BlobstreamXDataCommitmentStored, error) {
25+
ctx := context.Background()
26+
27+
contract, err := blobstreamx.NewBlobstreamX(blobstreamxContract, eth)
28+
if err != nil {
29+
return nil, fmt.Errorf("failed to instantiate contract: %w", err)
30+
}
31+
32+
head, err := eth.BlockNumber(ctx)
33+
if err != nil {
34+
return nil, fmt.Errorf("failed to get block number: %w", err)
35+
}
36+
37+
if uint64(head) < blocks {
38+
blocks = uint64(head)
39+
}
40+
41+
fmt.Printf("Scanning from Head block: %d Block Range: %d\n", head, blocks)
42+
43+
// Scan backwards
44+
// Scan in chunks of `maxFilterRange` blocks
45+
// Stop when we reach `head - scanRange`
46+
for end := uint64(head); end > uint64(head)-blocks; end -= maxFilterRange {
47+
start := end - maxFilterRange
48+
if start < uint64(head)-blocks {
49+
start = uint64(head) - blocks
50+
}
51+
52+
dataCommitment, err := findMatchingDataCommitment(contract, start, end, height)
53+
if err != nil {
54+
return nil, fmt.Errorf("failed to find matching data commitment: %w", err)
55+
}
56+
if dataCommitment != nil {
57+
return dataCommitment, nil
58+
}
59+
}
60+
61+
return nil, fmt.Errorf("no matching data commitment found")
62+
}
63+
64+
func findMatchingDataCommitment(contract *blobstreamx.BlobstreamX, start uint64, end uint64, height int64) (*blobstreamx.BlobstreamXDataCommitmentStored, error) {
65+
// fmt.Printf("Scanning blocks %d to %d\n", start, end)
66+
67+
// Filter events
68+
events, err := contract.FilterDataCommitmentStored(&bind.FilterOpts{
69+
Context: context.Background(),
70+
Start: start,
71+
End: &end,
72+
}, nil, nil, nil)
73+
if err != nil {
74+
return nil, fmt.Errorf("failed to filter events: %w", err)
75+
}
76+
defer events.Close()
77+
78+
// loop through events and return the first matching event
79+
for events.Next() {
80+
e := events.Event
81+
if int64(e.StartBlock) <= height && height < int64(e.EndBlock) {
82+
return e, nil
83+
}
84+
}
85+
86+
return nil, nil
87+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: test
2+
3+
on: workflow_dispatch
4+
5+
env:
6+
FOUNDRY_PROFILE: ci
7+
8+
jobs:
9+
check:
10+
strategy:
11+
fail-fast: true
12+
13+
name: Foundry project
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
submodules: recursive
19+
20+
- name: Install Foundry
21+
uses: foundry-rs/foundry-toolchain@v1
22+
with:
23+
version: nightly
24+
25+
- name: Run Forge build
26+
run: |
27+
forge --version
28+
forge build --sizes
29+
id: build
30+
31+
- name: Run Forge tests
32+
run: |
33+
forge test -vvv
34+
id: test
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Compiler files
2+
cache/
3+
out/
4+
5+
# Ignores development broadcast logs
6+
!/broadcast
7+
/broadcast/*/31337/
8+
/broadcast/**/dry-run/
9+
10+
# Docs
11+
docs/
12+
13+
# Dotenv file
14+
.env
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## Foundry
2+
3+
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**
4+
5+
Foundry consists of:
6+
7+
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
8+
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
9+
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
10+
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.
11+
12+
## Documentation
13+
14+
https://book.getfoundry.sh/
15+
16+
## Usage
17+
18+
### Build
19+
20+
```shell
21+
$ forge build
22+
```
23+
24+
### Test
25+
26+
```shell
27+
$ forge test
28+
```
29+
30+
### Format
31+
32+
```shell
33+
$ forge fmt
34+
```
35+
36+
### Gas Snapshots
37+
38+
```shell
39+
$ forge snapshot
40+
```
41+
42+
### Anvil
43+
44+
```shell
45+
$ anvil
46+
```
47+
48+
### Deploy
49+
50+
```shell
51+
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
52+
```
53+
54+
### Cast
55+
56+
```shell
57+
$ cast <subcommand>
58+
```
59+
60+
### Help
61+
62+
```shell
63+
$ forge --help
64+
$ anvil --help
65+
$ cast --help
66+
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[profile.default]
2+
src = "src"
3+
out = "out"
4+
libs = ["lib"]
5+
6+
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
Submodule blobstream-contracts added at cee4724

0 commit comments

Comments
 (0)