Skip to content

Commit 1ddcd5c

Browse files
authored
Merge branch 'alpha' into feat/new_bridge_contracts
2 parents d385bd3 + 65e0b67 commit 1ddcd5c

File tree

37 files changed

+45097
-85232
lines changed

37 files changed

+45097
-85232
lines changed

.github/workflows/common.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
steps:
2727
- uses: actions-rs/toolchain@v1
2828
with:
29-
toolchain: nightly-2022-08-23
29+
toolchain: nightly-2022-12-10
3030
override: true
3131
components: rustfmt, clippy
3232
- name: Install Go

.github/workflows/coordinator.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
steps:
2727
- uses: actions-rs/toolchain@v1
2828
with:
29-
toolchain: nightly-2022-08-23
29+
toolchain: nightly-2022-12-10
3030
override: true
3131
components: rustfmt, clippy
3232
- name: Install Go

.github/workflows/roller.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
steps:
2727
- uses: actions-rs/toolchain@v1
2828
with:
29-
toolchain: nightly-2022-08-23
29+
toolchain: nightly-2022-12-10
3030
override: true
3131
components: rustfmt, clippy
3232
- name: Install Go
@@ -42,6 +42,8 @@ jobs:
4242
- name: Test
4343
run: |
4444
make roller
45+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./prover/lib
46+
export CHAIN_ID=534353
4547
go test -v ./...
4648
check:
4749
runs-on: ubuntu-latest

Jenkinsfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pipeline {
1313
environment {
1414
GO111MODULE = 'on'
1515
PATH="/home/ubuntu/.cargo/bin:$PATH"
16+
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:./coordinator/verifier/lib"
17+
CHAIN_ID='534353'
1618
// LOG_DOCKER = 'true'
1719
}
1820
stages {

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.PHONY: check update dev_docker clean
22

3+
ZKP_VERSION=release-1220
4+
35
help: ## Display this help message
46
@grep -h \
57
-E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
@@ -29,5 +31,15 @@ dev_docker: ## build docker images for development/testing usages
2931
docker build -t scroll_l1geth ./common/docker/l1geth/
3032
docker build -t scroll_l2geth ./common/docker/l2geth/
3133

34+
test_zkp: ## Test zkp prove and verify, roller/prover generates the proof and coordinator/verifier verifies it
35+
mkdir -p test_params
36+
wget https://circuit-release.s3.us-west-2.amazonaws.com/circuit-release/${ZKP_VERSION}/test_params/params19 -O ./test_params/params19
37+
wget https://circuit-release.s3.us-west-2.amazonaws.com/circuit-release/${ZKP_VERSION}/test_params/params26 -O ./test_params/params26
38+
wget https://circuit-release.s3.us-west-2.amazonaws.com/circuit-release/${ZKP_VERSION}/test_seed -O test_seed
39+
rm -rf ./roller/assets/test_params && mv test_params ./roller/assets/ && mv test_seed ./roller/assets/
40+
cd ./roller && make test-gpu-prover
41+
rm -rf ./coordinator/assets/test_params && mv ./roller/assets/test_params ./coordinator/assets/ && mv ./roller/assets/agg_proof ./coordinator/assets/
42+
cd ./coordinator && make test-gpu-verifier
43+
3244
clean: ## Empty out the bin folder
3345
@rm -rf build/bin

bridge/l2/backend.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ func New(ctx context.Context, cfg *config.L2Config, orm database.OrmFactory) (*B
2727
return nil, err
2828
}
2929

30+
// Note: initialize watcher before relayer to keep DB consistent.
31+
// Otherwise, there will be a race condition between watcher.initializeGenesis and relayer.ProcessPendingBatches.
32+
l2Watcher := NewL2WatcherClient(ctx, client, cfg.Confirmations, cfg.BatchProposerConfig, cfg.L2MessengerAddress, orm)
33+
3034
relayer, err := NewLayer2Relayer(ctx, orm, cfg.RelayerConfig)
3135
if err != nil {
3236
return nil, err
3337
}
3438

35-
l2Watcher := NewL2WatcherClient(ctx, client, cfg.Confirmations, cfg.BatchProposerConfig, cfg.L2MessengerAddress, orm)
36-
3739
return &Backend{
3840
cfg: cfg,
3941
l2Watcher: l2Watcher,

bridge/l2/batch_proposer.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ func (w *batchProposer) tryProposeBatch() {
5858

5959
if blocks[0].GasUsed > w.batchGasThreshold {
6060
log.Warn("gas overflow even for only 1 block", "height", blocks[0].Number, "gas", blocks[0].GasUsed)
61-
if err = w.createBatchForBlocks(blocks[:1]); err != nil {
61+
if _, err = w.createBatchForBlocks(blocks[:1]); err != nil {
6262
log.Error("failed to create batch", "number", blocks[0].Number, "err", err)
6363
}
6464
return
6565
}
6666

6767
if blocks[0].TxNum > w.batchTxNumThreshold {
6868
log.Warn("too many txs even for only 1 block", "height", blocks[0].Number, "tx_num", blocks[0].TxNum)
69-
if err = w.createBatchForBlocks(blocks[:1]); err != nil {
69+
if _, err = w.createBatchForBlocks(blocks[:1]); err != nil {
7070
log.Error("failed to create batch", "number", blocks[0].Number, "err", err)
7171
}
7272
return
@@ -93,15 +93,15 @@ func (w *batchProposer) tryProposeBatch() {
9393
return
9494
}
9595

96-
if err = w.createBatchForBlocks(blocks); err != nil {
96+
if _, err = w.createBatchForBlocks(blocks); err != nil {
9797
log.Error("failed to create batch", "from", blocks[0].Number, "to", blocks[len(blocks)-1].Number, "err", err)
9898
}
9999
}
100100

101-
func (w *batchProposer) createBatchForBlocks(blocks []*orm.BlockInfo) error {
101+
func (w *batchProposer) createBatchForBlocks(blocks []*orm.BlockInfo) (string, error) {
102102
dbTx, err := w.orm.Beginx()
103103
if err != nil {
104-
return err
104+
return "", err
105105
}
106106

107107
var dbTxErr error
@@ -128,13 +128,13 @@ func (w *batchProposer) createBatchForBlocks(blocks []*orm.BlockInfo) error {
128128

129129
batchID, dbTxErr = w.orm.NewBatchInDBTx(dbTx, startBlock, endBlock, startBlock.ParentHash, txNum, gasUsed)
130130
if dbTxErr != nil {
131-
return dbTxErr
131+
return "", dbTxErr
132132
}
133133

134134
if dbTxErr = w.orm.SetBatchIDForBlocksInDBTx(dbTx, blockIDs, batchID); dbTxErr != nil {
135-
return dbTxErr
135+
return "", dbTxErr
136136
}
137137

138138
dbTxErr = dbTx.Commit()
139-
return dbTxErr
139+
return batchID, dbTxErr
140140
}

bridge/l2/batch_proposer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func testBatchProposer(t *testing.T) {
4040
// Insert traces into db.
4141
assert.NoError(t, db.InsertBlockTraces([]*types.BlockTrace{trace2, trace3}))
4242

43-
id := utils.ComputeBatchID(trace3.Header.Hash(), trace2.Header.ParentHash, big.NewInt(1))
43+
id := utils.ComputeBatchID(trace3.Header.Hash(), trace2.Header.ParentHash, big.NewInt(0))
4444

4545
proposer := newBatchProposer(&config.BatchProposerConfig{
4646
ProofGenerationFreq: 1,

bridge/l2/watcher.go

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func NewL2WatcherClient(ctx context.Context, client *ethclient.Client, confirmat
6767
savedHeight = 0
6868
}
6969

70-
return &WatcherClient{
70+
w := WatcherClient{
7171
ctx: ctx,
7272
Client: client,
7373
orm: orm,
@@ -79,6 +79,75 @@ func NewL2WatcherClient(ctx context.Context, client *ethclient.Client, confirmat
7979
stopped: 0,
8080
batchProposer: newBatchProposer(bpCfg, orm),
8181
}
82+
83+
// Initialize genesis before we do anything else
84+
if err := w.initializeGenesis(); err != nil {
85+
panic(fmt.Sprintf("failed to initialize L2 genesis batch, err: %v", err))
86+
}
87+
88+
return &w
89+
}
90+
91+
func (w *WatcherClient) initializeGenesis() error {
92+
if count, err := w.orm.GetBatchCount(); err != nil {
93+
return fmt.Errorf("failed to get batch count: %v", err)
94+
} else if count > 0 {
95+
log.Info("genesis already imported")
96+
return nil
97+
}
98+
99+
genesis, err := w.HeaderByNumber(w.ctx, big.NewInt(0))
100+
if err != nil {
101+
return fmt.Errorf("failed to retrieve L2 genesis header: %v", err)
102+
}
103+
104+
// EIP1559 is disabled so the RPC won't return baseFeePerGas. However, l2geth
105+
// still uses BaseFee when calculating the block hash. If we keep it as <nil>
106+
// here the genesis hash will not match.
107+
genesis.BaseFee = big.NewInt(0)
108+
109+
log.Info("retrieved L2 genesis header", "hash", genesis.Hash().String())
110+
111+
trace := &types.BlockTrace{
112+
Coinbase: nil,
113+
Header: genesis,
114+
Transactions: []*types.TransactionData{},
115+
StorageTrace: nil,
116+
ExecutionResults: []*types.ExecutionResult{},
117+
MPTWitness: nil,
118+
}
119+
120+
if err := w.orm.InsertBlockTraces([]*types.BlockTrace{trace}); err != nil {
121+
return fmt.Errorf("failed to insert block traces: %v", err)
122+
}
123+
124+
blocks, err := w.orm.GetUnbatchedBlocks(map[string]interface{}{})
125+
if err != nil {
126+
return err
127+
}
128+
129+
if len(blocks) != 1 {
130+
return fmt.Errorf("unexpected number of unbatched blocks in db, expected: 1, actual: %v", len(blocks))
131+
}
132+
133+
batchID, err := w.batchProposer.createBatchForBlocks(blocks)
134+
if err != nil {
135+
return fmt.Errorf("failed to create batch: %v", err)
136+
}
137+
138+
err = w.orm.UpdateProvingStatus(batchID, orm.ProvingTaskProved)
139+
if err != nil {
140+
return fmt.Errorf("failed to update genesis batch proving status: %v", err)
141+
}
142+
143+
err = w.orm.UpdateRollupStatus(w.ctx, batchID, orm.RollupFinalized)
144+
if err != nil {
145+
return fmt.Errorf("failed to update genesis batch rollup status: %v", err)
146+
}
147+
148+
log.Info("successfully imported genesis batch")
149+
150+
return nil
82151
}
83152

84153
// Start the Listening process

build/dockerfiles/coordinator.Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build libzkp dependency
2-
FROM scrolltech/go-rust-builder:go-1.18-rust-nightly-2022-08-23 as chef
2+
FROM scrolltech/go-rust-builder:go-1.18-rust-nightly-2022-12-10 as chef
33
WORKDIR app
44

55
FROM chef as planner
@@ -13,10 +13,11 @@ RUN cargo chef cook --release --recipe-path recipe.json
1313

1414
COPY ./common/libzkp/impl .
1515
RUN cargo build --release
16+
RUN find ./ | grep libzktrie.so | xargs -i cp {} /app/target/release/
1617

1718

1819
# Download Go dependencies
19-
FROM scrolltech/go-rust-builder:go-1.18-rust-nightly-2022-08-23 as base
20+
FROM scrolltech/go-rust-builder:go-1.18-rust-nightly-2022-12-10 as base
2021
WORKDIR /src
2122
COPY go.work* ./
2223
COPY ./bridge/go.* ./bridge/
@@ -32,12 +33,14 @@ RUN go mod download -x
3233
FROM base as builder
3334
COPY . .
3435
RUN cp -r ./common/libzkp/interface ./coordinator/verifier/lib
35-
COPY --from=zkp-builder /app/target/release/libzkp.so ./coordinator/verifier/lib/
36+
COPY --from=zkp-builder /app/target/release/libzkp.a ./coordinator/verifier/lib/
37+
COPY --from=zkp-builder /app/target/release/libzktrie.so ./coordinator/verifier/lib/
3638
RUN cd ./coordinator && go build -v -p 4 -o /bin/coordinator ./cmd && mv verifier/lib /bin/
3739

3840
# Pull coordinator into a second stage deploy alpine container
3941
FROM ubuntu:20.04
40-
42+
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/src/coordinator/verifier/lib
43+
# ENV CHAIN_ID=534353
4144
RUN mkdir -p /src/coordinator/verifier/lib
4245
COPY --from=builder /bin/lib /src/coordinator/verifier/lib
4346
COPY --from=builder /bin/coordinator /bin/

0 commit comments

Comments
 (0)