Skip to content

Commit

Permalink
List of signers for data item
Browse files Browse the repository at this point in the history
  • Loading branch information
szynwelski committed Jan 12, 2024
1 parent d328a1f commit 8491899
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 16 deletions.
7 changes: 5 additions & 2 deletions x/sequencer/ante/tx_interaction_l2_fee_verify.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ante

import (
"bytes"

"cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -28,9 +30,10 @@ func verifyFee(tx sdk.Tx, dataItem *types.MsgDataItem) error {
}
}

if len(feeTx.FeePayer()) > 0 {
feePayer := feeTx.FeePayer()
if len(feeTx.FeePayer()) > 0 && !bytes.Equal(feePayer, dataItem.GetSenderAddress().Bytes()) {
return errors.Wrapf(types.ErrNotEmptyFeePayer,
"transaction with data item cannot have fee payer: %s", feeTx.FeePayer())
"transaction with data item cannot have fee payer: %s", feePayer)
}

if len(feeTx.FeeGranter()) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion x/sequencer/ante/tx_interaction_l2_signature_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func verifySignaturesAndNonce(ctx sdk.Context, ak *authkeeper.AccountKeeper, tx
}

sig := sigs[0]
signer := dataItem.GetCreator()
signer := dataItem.GetSenderAddress()

if !ctx.IsReCheckTx() { // the signature does not need to be rechecked
if err := verifySingleSignature(sig, signer, dataItem); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions x/sequencer/ante/tx_interaction_l2_signature_verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func appAndCtx(t *testing.T) (*simapp.SimApp, sdk.Context) {
}

func addCreatorAccount(t *testing.T, app *simapp.SimApp, ctx sdk.Context, dataItem types.MsgDataItem) authtypes.AccountI {
acc := app.AccountKeeper.NewAccountWithAddress(ctx, dataItem.GetCreator())
acc := app.AccountKeeper.NewAccountWithAddress(ctx, dataItem.GetSenderAddress())

err := acc.SetSequence(5)
require.NoError(t, err)
Expand All @@ -53,7 +53,7 @@ var singleSignatureData = &signing.SingleSignatureData{
}

func createNonceTag(nonce int) bundlr.Tag {
return bundlr.Tag{Name: "Sequencer-Nonce", Value: strconv.Itoa(nonce)}
return bundlr.Tag{Name: "Sequencer-Nonce", Value: strconv.Itoa(nonce)}
}

func createEmptyArweaveSignature(dataItem types.MsgDataItem, sequence uint64) signing.SignatureV2 {
Expand Down
4 changes: 2 additions & 2 deletions x/sequencer/ante/tx_interaction_l2_verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestGetDataItemMsgTooManyDataItems(t *testing.T) {

func TestGetDataItemMsgDataItemBeforeMsg(t *testing.T) {
dataItem := test.ArweaveL2Interaction(t)
msg := testdata.NewTestMsg(dataItem.GetCreator())
msg := testdata.NewTestMsg(dataItem.GetSenderAddress())
tx := test.CreateTxWithMsgs(t, &dataItem, msg)

result, err := GetL2Interaction(tx)
Expand All @@ -53,7 +53,7 @@ func TestGetDataItemMsgDataItemBeforeMsg(t *testing.T) {

func TestGetDataItemMsgDataItemAfterMsg(t *testing.T) {
dataItem := test.ArweaveL2Interaction(t)
msg := testdata.NewTestMsg(dataItem.GetCreator())
msg := testdata.NewTestMsg(dataItem.GetSenderAddress())
tx := test.CreateTxWithMsgs(t, msg, &dataItem)

result, err := GetL2Interaction(tx)
Expand Down
3 changes: 3 additions & 0 deletions x/sequencer/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import (
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"

cryptocodec "github.com/warp-contracts/sequencer/crypto/codec"
// this line is used by starport scaffolding # 1
)

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
cryptocodec.RegisterInterfaces(registry)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgDataItem{},
)
Expand Down
7 changes: 4 additions & 3 deletions x/sequencer/types/message_arweave_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package types

import (
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"

"cosmossdk.io/errors"
"cosmossdk.io/x/tx/signing"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/warp-contracts/sequencer/api/sequencer/sequencer"
)

var _ sdk.Msg = &MsgArweaveBlock{}
Expand All @@ -33,9 +34,9 @@ func (msg *MsgArweaveBlock) ValidateBasic() error {

func ProvideMsgArweaveBlockGetSingers() signing.CustomGetSigner {
return signing.CustomGetSigner{
MsgType: protoreflect.FullName("sequencer.sequencer.MsgArweaveBlock"),
MsgType: proto.MessageName(&sequencer.MsgArweaveBlock{}),
Fn: func(msg proto.Message) ([][]byte, error) {
return [][]byte{{0x0}}, nil
return [][]byte{{}}, nil
},
}
}
26 changes: 20 additions & 6 deletions x/sequencer/types/message_data_item.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package types

import (
"fmt"
"strconv"

"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"

"cosmossdk.io/errors"
"cosmossdk.io/x/tx/signing"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/warp-contracts/sequencer/api/sequencer/sequencer"
"github.com/warp-contracts/sequencer/crypto/keys/arweave"
"github.com/warp-contracts/sequencer/crypto/keys/ethereum"

Expand All @@ -22,7 +22,7 @@ import (

var _ sdk.Msg = &MsgDataItem{}

func (msg *MsgDataItem) GetCreator() sdk.AccAddress {
func (msg *MsgDataItem) GetSenderAddress() sdk.AccAddress {
pubKey, err := msg.GetPublicKey()
if err != nil {
panic(err)
Expand Down Expand Up @@ -90,15 +90,29 @@ func (msg *MsgDataItem) GetInfo() DataItemInfo {
return DataItemInfo{
DataItemId: msg.DataItem.Id.Base64(),
Nonce: nonce,
Sender: msg.GetCreator().String(),
Sender: msg.GetSenderAddress().String(),
}
}

func ProvideMsgDataItemGetSingers() signing.CustomGetSigner {
return signing.CustomGetSigner{
MsgType: protoreflect.FullName("sequencer.sequencer.MsgDataItem"),
MsgType: proto.MessageName(&sequencer.MsgDataItem{}),
Fn: func(msg proto.Message) ([][]byte, error) {
return [][]byte{{0x0}}, nil
msgDataItem, ok := msg.(*sequencer.MsgDataItem)
if !ok {
return nil, fmt.Errorf("Invalid message type: %T", msg)
}

bundleItem := new(bundlr.BundleItem)
err := bundleItem.Unmarshal(msgDataItem.DataItem)
if err != nil {
return nil, err
}
pubKey, err := GetPublicKey(bundleItem.SignatureType, bundleItem.Owner)
if err != nil {
return nil, err
}
return [][]byte{pubKey.Address()}, nil
},
}
}

0 comments on commit 8491899

Please sign in to comment.