Skip to content

Commit

Permalink
Remove StoreSigningDAS from DAWriter chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-Wilson committed May 23, 2024
1 parent 1b6554f commit 57f583b
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 86 deletions.
31 changes: 11 additions & 20 deletions cmd/datool/datool.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,7 @@ func startClientStore(args []string) error {
return err
}

client, err := das.NewDASRPCClient(config.URL)
if err != nil {
return err
}

var dasClient das.DataAvailabilityServiceWriter = client
var signer signature.DataSignerFunc
if config.SigningKey != "" {
var privateKey *ecdsa.PrivateKey
if config.SigningKey[:2] == "0x" {
Expand All @@ -140,12 +135,7 @@ func startClientStore(args []string) error {
return err
}
}
signer := signature.DataSignerFromPrivateKey(privateKey)

dasClient, err = das.NewStoreSigningDAS(dasClient, signer)
if err != nil {
return err
}
signer = signature.DataSignerFromPrivateKey(privateKey)
} else if config.SigningWallet != "" {
walletConf := &genericconf.WalletConfig{
Pathname: config.SigningWallet,
Expand All @@ -154,16 +144,17 @@ func startClientStore(args []string) error {
Account: "",
OnlyCreateKey: false,
}
_, signer, err := util.OpenWallet("datool", walletConf, nil)
if err != nil {
return err
}
dasClient, err = das.NewStoreSigningDAS(dasClient, signer)
_, signer, err = util.OpenWallet("datool", walletConf, nil)
if err != nil {
return err
}
}

client, err := das.NewDASRPCClient(config.URL, signer)
if err != nil {
return err
}

ctx := context.Background()
var cert *daprovider.DataAvailabilityCertificate

Expand All @@ -173,9 +164,9 @@ func startClientStore(args []string) error {
if err != nil {
return err
}
cert, err = dasClient.Store(ctx, message, uint64(time.Now().Add(config.DASRetentionPeriod).Unix()), []byte{})
cert, err = client.Store(ctx, message, uint64(time.Now().Add(config.DASRetentionPeriod).Unix()), []byte{})
} else if len(config.Message) > 0 {
cert, err = dasClient.Store(ctx, []byte(config.Message), uint64(time.Now().Add(config.DASRetentionPeriod).Unix()), []byte{})
cert, err = client.Store(ctx, []byte(config.Message), uint64(time.Now().Add(config.DASRetentionPeriod).Unix()), []byte{})
} else {
return errors.New("--message or --random-message-size must be specified")
}
Expand Down Expand Up @@ -361,7 +352,7 @@ func dumpKeyset(args []string) error {
return err
}

services, err := das.ParseServices(config.Keyset)
services, err := das.ParseServices(config.Keyset, nil)
if err != nil {
return err
}
Expand Down
39 changes: 33 additions & 6 deletions das/dasRpcClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,53 @@ import (
"github.com/offchainlabs/nitro/arbstate/daprovider"
"github.com/offchainlabs/nitro/blsSignatures"
"github.com/offchainlabs/nitro/util/pretty"
"github.com/offchainlabs/nitro/util/signature"
)

type DASRPCClient struct { // implements DataAvailabilityService
clnt *rpc.Client
url string
clnt *rpc.Client
url string
signer signature.DataSignerFunc
}

func NewDASRPCClient(target string) (*DASRPCClient, error) {
func nilSigner(_ []byte) ([]byte, error) {
return []byte{}, nil
}

func NewDASRPCClient(target string, signer signature.DataSignerFunc) (*DASRPCClient, error) {
clnt, err := rpc.Dial(target)
if err != nil {
return nil, err
}
if signer == nil {
signer = nilSigner
}
return &DASRPCClient{
clnt: clnt,
url: target,
clnt: clnt,
url: target,
signer: signer,
}, nil
}

func (c *DASRPCClient) Store(ctx context.Context, message []byte, timeout uint64, reqSig []byte) (*daprovider.DataAvailabilityCertificate, error) {
log.Trace("das.DASRPCClient.Store(...)", "message", pretty.FirstFewBytes(message), "timeout", time.Unix(int64(timeout), 0), "sig", pretty.FirstFewBytes(reqSig), "this", *c)
/*
var ret StartChunkedStoreResult
if err := c.clnt.CallContext(ctx, &ret, "das_startChunkedStore", hexutil.Bytes(message), hexutil.Uint64(timeout), hexutil.Bytes(reqSig)); err != nil {
}
*/

return c.legacyStore(ctx, message, timeout)

}

func (c *DASRPCClient) legacyStore(ctx context.Context, message []byte, timeout uint64) (*daprovider.DataAvailabilityCertificate, error) {
log.Trace("das.DASRPCClient.Store(...)", "message", pretty.FirstFewBytes(message), "timeout", time.Unix(int64(timeout), 0), "this", *c)

reqSig, err := applyDasSigner(c.signer, message, timeout)
if err != nil {
return nil, err
}

var ret StoreResult
if err := c.clnt.CallContext(ctx, &ret, "das_store", hexutil.Bytes(message), hexutil.Uint64(timeout), hexutil.Bytes(reqSig)); err != nil {
return nil, err
Expand Down
8 changes: 5 additions & 3 deletions das/extra_signature_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ func TestExtraSignatureCheck(t *testing.T) {
signer := signature.DataSignerFromPrivateKey(privateKey)

var da DataAvailabilityServiceWriter = &StubSignatureCheckDAS{keyDir}
da, err = NewStoreSigningDAS(da, signer)
Require(t, err)

_, err = da.Store(context.Background(), []byte("Hello world"), 1234, []byte{})
msg := []byte("Hello world")
timeout := uint64(1234)
sig, err := applyDasSigner(signer, msg, timeout)
Require(t, err)
_, err = da.Store(context.Background(), msg, timeout, sig)
Require(t, err)
}

Expand Down
9 changes: 1 addition & 8 deletions das/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,10 @@ func CreateBatchPosterDAS(
// Done checking config requirements

var daWriter DataAvailabilityServiceWriter
daWriter, err := NewRPCAggregator(ctx, *config)
daWriter, err := NewRPCAggregator(ctx, *config, dataSigner)
if err != nil {
return nil, nil, nil, err
}
if dataSigner != nil {
// In some tests the batch poster does not sign Store requests
daWriter, err = NewStoreSigningDAS(daWriter, dataSigner)
if err != nil {
return nil, nil, nil, err
}
}

restAgg, err := NewRestfulClientAggregator(ctx, &config.RestAggregator)
if err != nil {
Expand Down
17 changes: 9 additions & 8 deletions das/rpc_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/offchainlabs/nitro/blsSignatures"
"github.com/offchainlabs/nitro/solgen/go/bridgegen"
"github.com/offchainlabs/nitro/util/metricsutil"
"github.com/offchainlabs/nitro/util/signature"

"github.com/ethereum/go-ethereum/common"
"github.com/offchainlabs/nitro/arbutil"
Expand All @@ -27,31 +28,31 @@ type BackendConfig struct {
SignerMask uint64 `json:"signermask"`
}

func NewRPCAggregator(ctx context.Context, config DataAvailabilityConfig) (*Aggregator, error) {
services, err := ParseServices(config.RPCAggregator)
func NewRPCAggregator(ctx context.Context, config DataAvailabilityConfig, signer signature.DataSignerFunc) (*Aggregator, error) {
services, err := ParseServices(config.RPCAggregator, signer)
if err != nil {
return nil, err
}
return NewAggregator(ctx, config, services)
}

func NewRPCAggregatorWithL1Info(config DataAvailabilityConfig, l1client arbutil.L1Interface, seqInboxAddress common.Address) (*Aggregator, error) {
services, err := ParseServices(config.RPCAggregator)
func NewRPCAggregatorWithL1Info(config DataAvailabilityConfig, l1client arbutil.L1Interface, seqInboxAddress common.Address, signer signature.DataSignerFunc) (*Aggregator, error) {
services, err := ParseServices(config.RPCAggregator, signer)
if err != nil {
return nil, err
}
return NewAggregatorWithL1Info(config, services, l1client, seqInboxAddress)
}

func NewRPCAggregatorWithSeqInboxCaller(config DataAvailabilityConfig, seqInboxCaller *bridgegen.SequencerInboxCaller) (*Aggregator, error) {
services, err := ParseServices(config.RPCAggregator)
func NewRPCAggregatorWithSeqInboxCaller(config DataAvailabilityConfig, seqInboxCaller *bridgegen.SequencerInboxCaller, signer signature.DataSignerFunc) (*Aggregator, error) {
services, err := ParseServices(config.RPCAggregator, signer)
if err != nil {
return nil, err
}
return NewAggregatorWithSeqInboxCaller(config, services, seqInboxCaller)
}

func ParseServices(config AggregatorConfig) ([]ServiceDetails, error) {
func ParseServices(config AggregatorConfig, signer signature.DataSignerFunc) ([]ServiceDetails, error) {
var cs []BackendConfig
err := json.Unmarshal([]byte(config.Backends), &cs)
if err != nil {
Expand All @@ -67,7 +68,7 @@ func ParseServices(config AggregatorConfig) ([]ServiceDetails, error) {
}
metricName := metricsutil.CanonicalizeMetricName(url.Hostname())

service, err := NewDASRPCClient(b.URL)
service, err := NewDASRPCClient(b.URL, signer)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion das/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestRPC(t *testing.T) {
},
RequestTimeout: 5 * time.Second,
}
rpcAgg, err := NewRPCAggregatorWithSeqInboxCaller(aggConf, nil)
rpcAgg, err := NewRPCAggregatorWithSeqInboxCaller(aggConf, nil, nil)
testhelpers.RequireImpl(t, err)

msg := testhelpers.RandomizeSlice(make([]byte, 100))
Expand Down
40 changes: 0 additions & 40 deletions das/store_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@
package das

import (
"context"
"encoding/binary"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"

"github.com/offchainlabs/nitro/arbstate/daprovider"
"github.com/offchainlabs/nitro/das/dastree"
"github.com/offchainlabs/nitro/util/pretty"
"github.com/offchainlabs/nitro/util/signature"
)

Expand All @@ -41,38 +36,3 @@ func dasStoreHash(data []byte, extraFields ...uint64) []byte {

return dastree.HashBytes(uniquifyingPrefix, buf, data)
}

type StoreSigningDAS struct {
DataAvailabilityServiceWriter
signer signature.DataSignerFunc
addr common.Address
}

func NewStoreSigningDAS(inner DataAvailabilityServiceWriter, signer signature.DataSignerFunc) (DataAvailabilityServiceWriter, error) {
sig, err := applyDasSigner(signer, []byte{}, 0)
if err != nil {
return nil, err
}
addr, err := DasRecoverSigner([]byte{}, sig, 0)
if err != nil {
return nil, err
}
return &StoreSigningDAS{inner, signer, addr}, nil
}

func (s *StoreSigningDAS) Store(ctx context.Context, message []byte, timeout uint64, sig []byte) (*daprovider.DataAvailabilityCertificate, error) {
log.Trace("das.StoreSigningDAS.Store(...)", "message", pretty.FirstFewBytes(message), "timeout", time.Unix(int64(timeout), 0), "sig", pretty.FirstFewBytes(sig), "this", s)
mySig, err := applyDasSigner(s.signer, message, timeout)
if err != nil {
return nil, err
}
return s.DataAvailabilityServiceWriter.Store(ctx, message, timeout, mySig)
}

func (s *StoreSigningDAS) String() string {
return "StoreSigningDAS (" + s.SignerAddress().Hex() + " ," + s.DataAvailabilityServiceWriter.String() + ")"
}

func (s *StoreSigningDAS) SignerAddress() common.Address {
return s.addr
}

0 comments on commit 57f583b

Please sign in to comment.