Skip to content

Commit 7033ed4

Browse files
committed
Merge branch 'gnosis' into main-gnosis-merge
2 parents 25c816f + c9f1b23 commit 7033ed4

File tree

176 files changed

+10790
-2101
lines changed

Some content is hidden

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

176 files changed

+10790
-2101
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repos:
1313
require_serial: true
1414

1515
- repo: https://github.com/pre-commit/pre-commit-hooks
16-
rev: v4.4.0
16+
rev: v4.5.0
1717
hooks:
1818
- id: check-added-large-files
1919
args: ["--maxkb=1000"]
@@ -33,7 +33,7 @@ repos:
3333
- id: trailing-whitespace
3434

3535
- repo: https://github.com/pre-commit/mirrors-prettier
36-
rev: v3.0.1
36+
rev: v3.1.0
3737
hooks:
3838
- id: prettier
3939
additional_dependencies:
@@ -59,12 +59,12 @@ repos:
5959
]
6060

6161
- repo: https://github.com/pre-commit/mirrors-eslint
62-
rev: "v8.4.1"
62+
rev: "v8.56.0"
6363
hooks:
6464
- id: eslint
6565

6666
- repo: https://github.com/shutter-network/pre-commit-go-hooks
67-
rev: "7a66f5523b34139615a0c95f2b8a441dbc1778dc"
67+
rev: "53239641ec106cda9a7acf9150c98be8d5ffa1ec"
6868
hooks:
6969
- id: shfmt
7070
args: ["-i", "4"]

.tool-versions

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ babashka 1.3.182
22
binaryen 114
33
circleci 0.1.28811
44
clojure 1.11.1.1386
5-
golang 1.21.3
5+
golang 1.21.4
66
golangci-lint 1.55.2
77
java temurin-17.0.5+8
88
nodejs 18.17.0
99
postgres 14.2
10-
pre-commit 3.3.3
10+
pre-commit 3.6.0
1111
protoc 22.3
1212
shfmt 3.7.0
1313
solidity 0.8.9

docker/build-src/optimism/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM golang:1.21 as builder
2+
ENV GOMODCACHE=/root/.cache/mod
3+
4+
# Fetch go modules separately to improve cache usage
5+
RUN mkdir /gomod
6+
COPY /rolling-shutter/go.* /gomod/
7+
WORKDIR /gomod
8+
RUN --mount=type=cache,target=/root/.cache go mod download
9+
10+
# Build binary
11+
COPY / /src
12+
WORKDIR /src/rolling-shutter
13+
14+
15+
RUN go env
16+
RUN --mount=type=cache,target=/root/.cache CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOFLAGS=-v make build
17+
18+
FROM scratch as runner
19+
20+
COPY --from=builder /src/rolling-shutter/bin/rolling-shutter /rolling-shutter
21+
22+
# Use 'uclibc' flavor to avoid https://github.com/docker-library/busybox/issues/155#issuecomment-1344375664
23+
RUN --mount=from=busybox:uclibc,src=/bin,dst=/bin mkdir -p /etc/ssl
24+
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
25+
26+
ENTRYPOINT ["/rolling-shutter"]

rolling-shutter/app/app.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ func (ShutterApp) decodeTx(tx []byte) (signer common.Address, msg *shmsg.Message
306306
}
307307

308308
msg, err = shmsg.GetMessage(signedMsg)
309-
310309
if err != nil {
311310
return
312311
}

rolling-shutter/app/messages.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"math/big"
55

66
"github.com/ethereum/go-ethereum/common"
7-
bn256 "github.com/ethereum/go-ethereum/crypto/bn256/cloudflare"
7+
"github.com/ethereum/go-ethereum/crypto/bls12381"
88
"github.com/pkg/errors"
99

1010
"github.com/shutter-network/shutter/shlib/shcrypto"
@@ -54,14 +54,17 @@ func ParsePolyEvalMsg(msg *shmsg.PolyEval, sender common.Address) (*PolyEval, er
5454

5555
// ParsePolyCommitmentMsg converts a shmsg.PolyCommitmentMsg to an app.PolyCommitmentMsg.
5656
func ParsePolyCommitmentMsg(msg *shmsg.PolyCommitment, sender common.Address) (*PolyCommitment, error) {
57+
g2 := bls12381.NewG2()
5758
gammas := shcrypto.Gammas{}
5859
for _, g := range msg.Gammas {
59-
g2 := new(bn256.G2)
60-
_, err := g2.Unmarshal(g)
60+
p, err := g2.FromBytes(g)
6161
if err != nil {
6262
return nil, err
6363
}
64-
gammas = append(gammas, g2)
64+
if !g2.IsOnCurve(p) {
65+
return nil, errors.Errorf("invalid gamma value %x", g)
66+
}
67+
gammas = append(gammas, p)
6568
}
6669
return &PolyCommitment{
6770
Sender: sender,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package chainobserver
2+
3+
import (
4+
"context"
5+
6+
"github.com/ethereum/go-ethereum/accounts/abi/bind"
7+
"github.com/ethereum/go-ethereum/common"
8+
"github.com/pkg/errors"
9+
10+
"github.com/shutter-network/rolling-shutter/rolling-shutter/contract"
11+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/retry"
12+
)
13+
14+
func RetryGetAddrs(ctx context.Context, addrsSeq *contract.AddrsSeq, n uint64) ([]common.Address, error) {
15+
callOpts := &bind.CallOpts{
16+
Pending: false,
17+
// We call for the current height instead of the height at which the event was emitted,
18+
// because the sets cannot change retroactively and we won't need an archive node.
19+
BlockNumber: nil,
20+
Context: ctx,
21+
}
22+
addrs, err := retry.FunctionCall(ctx, func(_ context.Context) ([]common.Address, error) {
23+
return addrsSeq.GetAddrs(callOpts, n)
24+
})
25+
if err != nil {
26+
return []common.Address{}, errors.Wrapf(err, "failed to query address set from contract")
27+
}
28+
return addrs, nil
29+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package database
2+
3+
import (
4+
"context"
5+
"math"
6+
7+
"github.com/jackc/pgx/v4"
8+
"github.com/pkg/errors"
9+
"github.com/rs/zerolog/log"
10+
11+
"github.com/shutter-network/rolling-shutter/rolling-shutter/chainobserver"
12+
"github.com/shutter-network/rolling-shutter/rolling-shutter/contract"
13+
"github.com/shutter-network/rolling-shutter/rolling-shutter/shdb"
14+
)
15+
16+
type Handler struct {
17+
CollatorContract *contract.AddrsSeq
18+
}
19+
20+
func (h *Handler) PutDB(
21+
ctx context.Context, tx pgx.Tx, event contract.CollatorConfigsListNewConfig,
22+
) error {
23+
addrs, err := chainobserver.RetryGetAddrs(ctx, h.CollatorContract, event.CollatorSetIndex)
24+
if err != nil {
25+
return err
26+
}
27+
log.Info().
28+
Uint64("block-number", event.Raw.BlockNumber).
29+
Uint64("collator-config-index", event.CollatorConfigIndex).
30+
Uint64("activation-block-number", event.ActivationBlockNumber).
31+
Msg("handling NewConfig event from collator config contract")
32+
if event.ActivationBlockNumber > math.MaxInt64 {
33+
return errors.Errorf(
34+
"activation block number %d from config contract would overflow int64",
35+
event.ActivationBlockNumber,
36+
)
37+
}
38+
if len(addrs) > 1 {
39+
return errors.Errorf("got multiple collators from collator addrs set contract: %s", addrs)
40+
} else if len(addrs) == 1 {
41+
db := New(tx)
42+
err := db.InsertChainCollator(ctx, InsertChainCollatorParams{
43+
ActivationBlockNumber: int64(event.ActivationBlockNumber),
44+
Collator: shdb.EncodeAddress(addrs[0]),
45+
})
46+
if err != nil {
47+
return errors.Wrapf(err, "failed to insert collator into db")
48+
}
49+
}
50+
return nil
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package database
2+
3+
import (
4+
"github.com/ethereum/go-ethereum/common"
5+
"github.com/pkg/errors"
6+
7+
"github.com/shutter-network/rolling-shutter/rolling-shutter/shdb"
8+
)
9+
10+
// GetIndex returns the index of the given address in the KeyperSet.
11+
func (s *KeyperSet) GetIndex(address common.Address) (uint64, error) {
12+
encodedAddress := shdb.EncodeAddress(address)
13+
for i, m := range s.Keypers {
14+
if m == encodedAddress {
15+
return uint64(i), nil
16+
}
17+
}
18+
return 0, errors.Errorf("keyper %s not found", address.String())
19+
}
20+
21+
// Contains checks if the given address is present in the KeyperSet.
22+
// It returns true if the address is found, otherwise false.
23+
func (s *KeyperSet) Contains(address common.Address) bool {
24+
encodedAddress := shdb.EncodeAddress(address)
25+
for _, m := range s.Keypers {
26+
if m == encodedAddress {
27+
return true
28+
}
29+
}
30+
return false
31+
}
32+
33+
// GetSubset returns a subset of addresses from the KeyperSet based on the given indices.
34+
// The return value is ordered according to the order of the given indices. If indices contains
35+
// duplicates, the return value will do so as well. If at least one of the given indices is out of
36+
// range, an error is returned.
37+
func (s *KeyperSet) GetSubset(indices []uint64) ([]common.Address, error) {
38+
subset := []common.Address{}
39+
for _, i := range indices {
40+
if i >= uint64(len(s.Keypers)) {
41+
return nil, errors.Errorf("keyper index %d out of range (size %d)", i, len(s.Keypers))
42+
}
43+
addressStr := s.Keypers[i]
44+
address, err := shdb.DecodeAddress(addressStr)
45+
if err != nil {
46+
return nil, err
47+
}
48+
subset = append(subset, address)
49+
}
50+
return subset, nil
51+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package database
2+
3+
import (
4+
"testing"
5+
6+
"github.com/ethereum/go-ethereum/common"
7+
"gotest.tools/v3/assert"
8+
9+
"github.com/shutter-network/rolling-shutter/rolling-shutter/shdb"
10+
)
11+
12+
func makeTestKeyperSet() KeyperSet {
13+
return KeyperSet{
14+
KeyperConfigIndex: 0,
15+
ActivationBlockNumber: 0,
16+
Keypers: []string{
17+
shdb.EncodeAddress(common.HexToAddress("0x0000000000000000000000000000000000000000")),
18+
shdb.EncodeAddress(common.HexToAddress("0x5555555555555555555555555555555555555555")),
19+
shdb.EncodeAddress(common.HexToAddress("0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa")),
20+
},
21+
Threshold: 2,
22+
}
23+
}
24+
25+
func TestKeyperSetGetIndex(t *testing.T) {
26+
keyperSet := makeTestKeyperSet()
27+
addresses, err := shdb.DecodeAddresses(keyperSet.Keypers)
28+
assert.NilError(t, err)
29+
30+
for i, address := range addresses {
31+
index, err := keyperSet.GetIndex(address)
32+
assert.NilError(t, err)
33+
assert.Equal(t, uint64(i), index)
34+
}
35+
_, err = keyperSet.GetIndex(common.HexToAddress("0xffffffffffffffffffffffffffffffffffffffff"))
36+
assert.ErrorContains(t, err, "keyper 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF not found")
37+
}
38+
39+
func TestKeyperSetContains(t *testing.T) {
40+
keyperSet := makeTestKeyperSet()
41+
addresses, err := shdb.DecodeAddresses(keyperSet.Keypers)
42+
assert.NilError(t, err)
43+
44+
for _, address := range addresses {
45+
assert.Assert(t, keyperSet.Contains(address))
46+
}
47+
assert.Assert(t, !keyperSet.Contains(common.HexToAddress("0xffffffffffffffffffffffffffffffffffffffff")))
48+
}
49+
50+
func TestKeyperSetSubset(t *testing.T) {
51+
keyperSet := makeTestKeyperSet()
52+
testCases := []struct {
53+
indices []uint64
54+
valid bool
55+
}{
56+
{indices: []uint64{0, 1, 2}, valid: true},
57+
{indices: []uint64{}, valid: true},
58+
{indices: []uint64{1, 0}, valid: true},
59+
{indices: []uint64{0, 0}, valid: true},
60+
{indices: []uint64{0, 0, 0, 0}, valid: true},
61+
{indices: []uint64{3}, valid: false},
62+
}
63+
64+
for _, tc := range testCases {
65+
subset, err := keyperSet.GetSubset(tc.indices)
66+
if tc.valid {
67+
assert.Assert(t, len(subset) == len(tc.indices))
68+
for _, i := range tc.indices {
69+
assert.Assert(t, shdb.EncodeAddress(subset[i]) == keyperSet.Keypers[tc.indices[i]])
70+
}
71+
} else {
72+
assert.Assert(t, err != nil)
73+
}
74+
}
75+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package database
2+
3+
import (
4+
"context"
5+
"math"
6+
7+
"github.com/jackc/pgx/v4"
8+
"github.com/pkg/errors"
9+
"github.com/rs/zerolog/log"
10+
11+
"github.com/shutter-network/rolling-shutter/rolling-shutter/chainobserver"
12+
"github.com/shutter-network/rolling-shutter/rolling-shutter/contract"
13+
"github.com/shutter-network/rolling-shutter/rolling-shutter/shdb"
14+
)
15+
16+
type Handler struct {
17+
KeyperContract *contract.AddrsSeq
18+
}
19+
20+
func (h *Handler) PutDB(
21+
ctx context.Context, tx pgx.Tx, event contract.KeypersConfigsListNewConfig,
22+
) error {
23+
addrs, err := chainobserver.RetryGetAddrs(ctx, h.KeyperContract, event.KeyperSetIndex)
24+
if err != nil {
25+
return err
26+
}
27+
log.Info().
28+
Uint64("block-number", event.Raw.BlockNumber).
29+
Uint64("keyper-config-index", event.KeyperConfigIndex).
30+
Uint64("activation-block-number", event.ActivationBlockNumber).
31+
Msg("handling NewConfig event from keypers config contract")
32+
33+
if event.ActivationBlockNumber > math.MaxInt64 {
34+
return errors.Errorf(
35+
"activation block number %d from config contract would overflow int64",
36+
event.ActivationBlockNumber)
37+
}
38+
db := New(tx)
39+
err = db.InsertKeyperSet(ctx, InsertKeyperSetParams{
40+
KeyperConfigIndex: int64(event.KeyperConfigIndex),
41+
ActivationBlockNumber: int64(event.ActivationBlockNumber),
42+
Keypers: shdb.EncodeAddresses(addrs),
43+
Threshold: int32(event.Threshold),
44+
})
45+
if err != nil {
46+
return errors.Wrapf(err, "failed to insert keyper set into db")
47+
}
48+
return nil
49+
}

0 commit comments

Comments
 (0)