diff --git a/cmd/datool/datool.go b/cmd/datool/datool.go index 3f64a990ca..22d0d4e753 100644 --- a/cmd/datool/datool.go +++ b/cmd/datool/datool.go @@ -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" { @@ -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, @@ -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 @@ -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") } @@ -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 } diff --git a/das/dasRpcClient.go b/das/dasRpcClient.go index 5fca1e449f..324686f44b 100644 --- a/das/dasRpcClient.go +++ b/das/dasRpcClient.go @@ -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 diff --git a/das/extra_signature_checker_test.go b/das/extra_signature_checker_test.go index 2fcfac167d..9fdf86cdf5 100644 --- a/das/extra_signature_checker_test.go +++ b/das/extra_signature_checker_test.go @@ -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) } diff --git a/das/factory.go b/das/factory.go index ad4a771708..018129e673 100644 --- a/das/factory.go +++ b/das/factory.go @@ -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 { diff --git a/das/rpc_aggregator.go b/das/rpc_aggregator.go index 490116a89a..7345191e0d 100644 --- a/das/rpc_aggregator.go +++ b/das/rpc_aggregator.go @@ -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" @@ -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 { @@ -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 } diff --git a/das/rpc_test.go b/das/rpc_test.go index 40edfd8332..2a9c9d93ca 100644 --- a/das/rpc_test.go +++ b/das/rpc_test.go @@ -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)) diff --git a/das/store_signing.go b/das/store_signing.go index 88c7c5bfaa..eac25e48b0 100644 --- a/das/store_signing.go +++ b/das/store_signing.go @@ -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" ) @@ -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 -}