From 9b6e61ee4ad2d31de2d358251fcc106d368ffae6 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Tue, 26 Sep 2023 19:27:14 -0700 Subject: [PATCH 01/27] Adds a preconfirmation protocol package - with bid recieve and publish. --- pkg/preconfirmation/preconfirmation.go | 147 +++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 pkg/preconfirmation/preconfirmation.go diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go new file mode 100644 index 00000000..906d51c7 --- /dev/null +++ b/pkg/preconfirmation/preconfirmation.go @@ -0,0 +1,147 @@ +package preconfirmation + +import ( + "context" + "crypto/ecdsa" + "math/big" + + "github.com/ethereum/go-ethereum/common" + "github.com/primevprotocol/mev-commit/pkg/p2p" + "github.com/primevprotocol/mev-commit/pkg/p2p/msgpack" + "github.com/primevprotocol/mev-commit/pkg/topology" + "golang.org/x/sync/semaphore" +) + +const ( + ProtocolName = "preconfirmation" + ProtocolVersion = "1.0.0" +) + +type P2PService interface { + p2p.Streamer + p2p.Addressbook + Connect(context.Context, []byte) (p2p.Peer, error) +} + +type Preconfirmation struct { + topo topology.Topology + streamer P2PService + sem *semaphore.Weighted + quit chan struct{} +} + +func New(topo topology.Topology, streamer P2PService) *Preconfirmation { + return &Preconfirmation{ + topo: topo, + streamer: streamer, + } +} + +func (p *Preconfirmation) Protocol() p2p.ProtocolSpec { + return p2p.ProtocolSpec{ + Name: ProtocolName, + Version: ProtocolVersion, + StreamSpecs: []p2p.StreamSpec{ + { + Name: "bid", + Handler: p.handleBid, + }, + // { // This is going to be a stream exclusively from the builder to the searcher + // Name: "commitment", + // Handler: p.handleCommitment, + // }, + }, + } +} + +type UnsignedPreConfBid struct { + TxnHash string `json:"txnHash"` + Bid *big.Int `json:"bid"` + Blocknumber *big.Int `json:"blocknumber"` + // UUID string `json:"uuid"` // Assuming string representation for byte16 +} + +type PreConfBid struct { // Adds blocknumber for pre-conf bid - Will need to manage how to reciever acts on a bid / TTL is the blocknumber + UnsignedPreConfBid + + BidHash []byte `json:"bidhash"` + Signature []byte `json:"signature"` +} + +type PreconfCommitment struct { + PreConfBid + + DataHash []byte `json:"data_hash"` + CommitmentSignature []byte `json:"commitment_signature"` +} + +// golang interface +type IPreconfBid interface { + GetTxnHash() string + GetBidAmt() *big.Int + VerifySearcherSignature() (common.Address, error) + BidOriginator() (common.Address, *ecdsa.PublicKey, error) +} + +func (p *Preconfirmation) verifyBid( + bid *PreConfBid, +) (common.Address, error) { + + ethAddress, err := bid.VerifySearcherSignature() + if err != nil { + return common.Address{}, err + } + + return ethAddress, nil +} + +// BroadcastBid sends the bid to the specified peer +func (p *Preconfirmation) BroadcastBid(ctx context.Context, peer p2p.Peer, bid *PreConfBid) error { + stream, err := p.streamer.NewStream(ctx, peer, ProtocolName, ProtocolVersion, "bid") + if err != nil { + return err + } + + _, w := msgpack.NewReaderWriter[PreConfBid, PreConfBid](stream) + if err := w.WriteMsg(ctx, bid); err != nil { + return err + } + + return nil +} + +// handlebid is the function that is called when a bid is received +func (p *Preconfirmation) handleBid( + ctx context.Context, + peer p2p.Peer, + stream p2p.Stream, +) error { + + r, _ := msgpack.NewReaderWriter[PreConfBid, PreConfBid](stream) + bid, err := r.ReadMsg(ctx) + if err != nil { + return err + } + + ethAddress, err := p.verifyBid(bid) + if err != nil { + return err + } + + /* TODO(@ckartik): Determine if the bid is to be acted on - e.g constructed into a pre-confimration */ + _ = ethAddress + // if recieved from searcher broadcast to builder peers + // elseif recieved from builder, don't broadcast + + // Query Focused on only selecting builder peers + builderPeers := p.topo.GetPeers(topology.Query{}) + for _, peer := range builderPeers { + // Send bid to peers + err := p.BroadcastBid(ctx, peer, bid) + if err != nil { + return err + } + } + + return nil +} From 43ce572c90c64067f5f70ebaa7af9c4cec1586fa Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Wed, 27 Sep 2023 09:41:39 -0700 Subject: [PATCH 02/27] Update naming of internal folder to a more fitting name. --- pkg/preconfirmation/preconfirmation.go | 6 +- pkg/structures/preconf/bid.go | 296 +++++++++++++++++++++++++ pkg/structures/preconf/bid_test.go | 66 ++++++ 3 files changed, 366 insertions(+), 2 deletions(-) create mode 100644 pkg/structures/preconf/bid.go create mode 100644 pkg/structures/preconf/bid_test.go diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index 906d51c7..78557bc0 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -111,13 +111,15 @@ func (p *Preconfirmation) BroadcastBid(ctx context.Context, peer p2p.Peer, bid * } // handlebid is the function that is called when a bid is received +// TODO(@ckartik): +// When you open a stream with a searcher - the other side of the stream has the handler func (p *Preconfirmation) handleBid( ctx context.Context, peer p2p.Peer, stream p2p.Stream, ) error { - - r, _ := msgpack.NewReaderWriter[PreConfBid, PreConfBid](stream) + // TODO(@ckartik): Change to reader only once availble + r, _ := msgpack.NewReaderWriter[preconf.PreConfBid, preconf.PreConfBid](stream) bid, err := r.ReadMsg(ctx) if err != nil { return err diff --git a/pkg/structures/preconf/bid.go b/pkg/structures/preconf/bid.go new file mode 100644 index 00000000..0f6d251d --- /dev/null +++ b/pkg/structures/preconf/bid.go @@ -0,0 +1,296 @@ +package preconf + +import ( + "bytes" + "crypto/ecdsa" + "encoding/hex" + "errors" + "math/big" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/signer/core/apitypes" +) + +var ( + ErrAlreadySignedBid = errors.New("already contains hash or signature") + ErrMissingHashSignature = errors.New("missing hash or signature") + ErrInvalidSignature = errors.New("signature is not valid") + ErrInvalidHash = errors.New("bidhash doesn't match bid payload") + ErrAlreadySignedCommitment = errors.New("commitment is already hashed or signed") +) + +type UnsignedPreConfBid struct { + TxnHash string `json:"txnHash"` + Bid *big.Int `json:"bid"` + Blocknumber *big.Int `json:"blocknumber"` + // UUID string `json:"uuid"` // Assuming string representation for byte16 +} + +// Most of the bid details can go to the data-availabilty layer if needed, and only have the hash+sig live on chian +// Preconf bid structure +// PreConfBid represents the bid data. +type PreConfBid struct { // Adds blocknumber for pre-conf bid - Will need to manage how to reciever acts on a bid / TTL is the blocknumber + UnsignedPreConfBid + + BidHash []byte `json:"bidhash"` // TODO(@ckaritk): name better + Signature []byte `json:"signature"` +} + +type PreconfCommitment struct { + PreConfBid + + DataHash []byte `json:"data_hash"` // TODO(@ckaritk): name better + CommitmentSignature []byte `json:"commitment_signature"` +} + +// golang interface +type IPreconfBid interface { + GetTxnHash() string + GetBidAmt() *big.Int + VerifySearcherSignature() (common.Address, error) + BidOriginator() (common.Address, *ecdsa.PublicKey, error) +} + +type IPreconfCommitment interface { + IPreconfBid // TODO Implement for underlying data-structure + VerifyBuilderSignature() (common.Address, error) + CommitmentOriginator() (common.Address, *ecdsa.PublicKey, error) +} + +type IPreconfCommitmentBuilder interface { + IPreconfCommitment + PublishCommitment() error +} + +type IPreconfBidSearcher interface { + IPreconfBid +} + +type IPreconfBidBuilder interface { + IPreconfBid + ConstructCommitment(*ecdsa.PrivateKey) (PreconfCommitment, error) // Verfiy Signature and than constrcut the commitment +} + +func (p PreconfCommitment) VerifyBuilderSignature() (common.Address, error) { + if p.DataHash == nil || p.CommitmentSignature == nil { + return common.Address{}, ErrMissingHashSignature + } + + internalPayload := constructCommitmentPayload(p.TxnHash, p.Bid, p.Blocknumber, p.BidHash, p.Signature) + + return eipVerify(internalPayload, p.DataHash, p.Signature) +} + +func eipVerify(internalPayload apitypes.TypedData, expectedhash []byte, signature []byte) (common.Address, error) { + payloadHash, _, err := apitypes.TypedDataAndHash(internalPayload) + if err != nil { + return common.Address{}, err + } + + if !bytes.Equal(payloadHash, expectedhash) { + return common.Address{}, ErrInvalidHash + } + + pubkey, err := crypto.SigToPub(payloadHash, signature) + if err != nil { + return common.Address{}, err + } + + if !crypto.VerifySignature(crypto.FromECDSAPub(pubkey), payloadHash, signature[:len(signature)-1]) { + return common.Address{}, ErrInvalidSignature + } + + return crypto.PubkeyToAddress(*pubkey), err +} + +func (p PreConfBid) BidOriginator() (common.Address, *ecdsa.PublicKey, error) { + _, err := p.VerifySearcherSignature() + if err != nil { + return common.Address{}, nil, err + } + + pubkey, err := crypto.SigToPub(p.BidHash, p.Signature) + if err != nil { + return common.Address{}, nil, err + } + + return crypto.PubkeyToAddress(*pubkey), pubkey, nil +} + +func (p PreconfCommitment) CommitmentOriginator() (common.Address, *ecdsa.PublicKey, error) { + _, err := p.VerifyBuilderSignature() + if err != nil { + return common.Address{}, nil, err + } + + pubkey, err := crypto.SigToPub(p.DataHash, p.CommitmentSignature) + if err != nil { + return common.Address{}, nil, err + } + + return crypto.PubkeyToAddress(*pubkey), pubkey, nil +} + +func (p PreConfBid) ConstructCommitment(privKey *ecdsa.PrivateKey) (PreconfCommitment, error) { + _, err := p.VerifySearcherSignature() + if err != nil { + return PreconfCommitment{}, err + } + commitment := PreconfCommitment{ + PreConfBid: p, + } + + err = commitment.constructHashAndSignature(privKey) + if err != nil { + return PreconfCommitment{}, err + } + + return commitment, nil +} + +// Adds bidHash and Signature to preconfbid +// Fails atomically +func (p *PreconfCommitment) constructHashAndSignature(privKey *ecdsa.PrivateKey) (err error) { + if p.DataHash != nil || p.CommitmentSignature != nil { + return ErrAlreadySignedCommitment + } + + eip712Payload := constructCommitmentPayload(p.TxnHash, p.Bid, p.Blocknumber, p.BidHash, p.Signature) + + dataHash, _, err := apitypes.TypedDataAndHash(eip712Payload) + if err != nil { + return err + } + sig, err := crypto.Sign(dataHash, privKey) + if err != nil { + return err + } + + p.DataHash = dataHash + p.CommitmentSignature = sig + + return nil +} + +// Returns a PreConfBid Object with an EIP712 signature of the payload +func ConstructSignedBid(bidamt *big.Int, txnhash string, blocknumber *big.Int, key *ecdsa.PrivateKey) (IPreconfBidSearcher, error) { + bid := &PreConfBid{ + UnsignedPreConfBid: UnsignedPreConfBid{ + Bid: bidamt, + TxnHash: txnhash, + Blocknumber: blocknumber, + }, + } + + err := bid.constructHashAndSignature(key) + if err != nil { + return nil, err + } + + return bid, nil +} + +// Verifies the bid +func (p PreConfBid) GetTxnHash() string { + return p.TxnHash +} + +func (p PreConfBid) GetBidAmt() *big.Int { + return p.Bid +} + +// Verifies the bid +func (p PreConfBid) VerifySearcherSignature() (common.Address, error) { + if p.BidHash == nil || p.Signature == nil { + return common.Address{}, ErrMissingHashSignature + } + + return eipVerify(constructBidPayload(p.TxnHash, p.Bid, p.Blocknumber), p.BidHash, p.Signature) +} + +// Adds bidHash and Signature to preconfbid +// Fails atomically +func (p *PreConfBid) constructHashAndSignature(privKey *ecdsa.PrivateKey) (err error) { + if p.BidHash != nil || p.Signature != nil { + return ErrAlreadySignedBid + } + + internalPayload := constructBidPayload(p.TxnHash, p.Bid, p.Blocknumber) + + bidHash, _, err := apitypes.TypedDataAndHash(internalPayload) + if err != nil { + return err + } + sig, err := crypto.Sign(bidHash, privKey) + if err != nil { + return err + } + + p.BidHash = bidHash + p.Signature = sig + + return nil +} + +// Constructs the EIP712 formatted bid +func constructCommitmentPayload(txnHash string, bid *big.Int, blockNumber *big.Int, bidHash []byte, signature []byte) apitypes.TypedData { + signerData := apitypes.TypedData{ + Types: apitypes.Types{ + "PreConfCommitment": []apitypes.Type{ + {Name: "txnHash", Type: "string"}, + {Name: "bid", Type: "uint64"}, + {Name: "blockNumber", Type: "uint64"}, + {Name: "bidHash", Type: "string"}, // Hex Encoded Hash + {Name: "signature", Type: "string"}, // Hex Encoded Signature + }, + "EIP712Domain": []apitypes.Type{ + {Name: "name", Type: "string"}, + {Name: "version", Type: "string"}, + }, + }, + PrimaryType: "PreConfCommitment", + Domain: apitypes.TypedDataDomain{ + Name: "PreConfCommitment", + Version: "1", + }, + Message: apitypes.TypedDataMessage{ + "txnHash": txnHash, + "bid": bid, + "blockNumber": blockNumber, + "bidHash": hex.EncodeToString(bidHash), + "signature": hex.EncodeToString(signature), + }, + } + + return signerData +} + +// Constructs the EIP712 formatted bid +func constructBidPayload(txnHash string, bid *big.Int, blockNumber *big.Int) apitypes.TypedData { + signerData := apitypes.TypedData{ + Types: apitypes.Types{ + "PreConfBid": []apitypes.Type{ + {Name: "txnHash", Type: "string"}, + {Name: "bid", Type: "uint64"}, + {Name: "blockNumber", Type: "uint64"}, + }, + "EIP712Domain": []apitypes.Type{ + {Name: "name", Type: "string"}, + {Name: "version", Type: "string"}, + }, + }, + PrimaryType: "PreConfBid", + Domain: apitypes.TypedDataDomain{ + Name: "PreConfBid", + Version: "1", + }, + Message: apitypes.TypedDataMessage{ + "txnHash": txnHash, + "bid": bid, + "blockNumber": blockNumber, + }, + } + + return signerData +} diff --git a/pkg/structures/preconf/bid_test.go b/pkg/structures/preconf/bid_test.go new file mode 100644 index 00000000..09730a40 --- /dev/null +++ b/pkg/structures/preconf/bid_test.go @@ -0,0 +1,66 @@ +package preconf + +// construct test for bid +import ( + "encoding/json" + "math/big" + "testing" + + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient" +) + +func TestBid(t *testing.T) { + // Connect to Ganache + key, _ := crypto.GenerateKey() + + bid, err := ConstructSignedBid(big.NewInt(10), "0xkartik", big.NewInt(2), key) + if err != nil { + t.Fatal(err) + } + address, err := bid.VerifySearcherSignature() + t.Log(address) + b, _ := json.Marshal(bid) + var bid2 PreConfBid + json.Unmarshal(b, &bid2) + if err != nil { + t.Fatal(err) + } + t.Log(hexutil.Bytes(bid2.BidHash)) + sig := hexutil.Bytes(bid2.Signature) + t.Log(sig) + + if address.Big().Cmp(crypto.PubkeyToAddress(key.PublicKey).Big()) != 0 { + t.Fatal("Address not same as signer") + } +} + +func TestCommitment(t *testing.T) { + client, err := ethclient.Dial("http://54.200.76.18:8545") + if err != nil { + t.Fatalf("Failed to connect to the Ethereum client: %v", err) + } + key, _ := crypto.GenerateKey() + bid, err := ConstructSignedBid(big.NewInt(10), "0xkadrtik", big.NewInt(2), key) + if err != nil { + t.Fatal(err) + } + + b, _ := json.Marshal(bid) + var bid2 PreConfBid + json.Unmarshal(b, &bid2) + commit, err := bid2.ConstructCommitment(key) + + if err != nil { + t.Fatal(err) + } + commit.VerifyBuilderSignature() + privateKey, _ := crypto.HexToECDSA("7cea3c338ce48647725ca014a52a80b2a8eb71d184168c343150a98100439d1b") + + txn, err := commit.StoreCommitmentToDA(privateKey, "0x169c9cd14923ef3fed0e0ce98cdc71c3d6037728", client) + if err != nil { + t.Fatal(err) + } + t.Log(txn.Hash().Hex()) +} From eaab5be98e4be9b4c9c3f0e0a2eb314a514ffdbc Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Wed, 27 Sep 2023 10:16:42 -0700 Subject: [PATCH 03/27] Adds commitment construction and propogation to bid handling. --- pkg/preconfirmation/preconfirmation.go | 22 ++++++++++++++++++++-- pkg/structures/preconf/bid.go | 21 +++++++++++++++++---- pkg/structures/preconf/bid_test.go | 3 ++- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index 78557bc0..ddffd811 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -7,6 +7,11 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/primevprotocol/mev-commit/pkg/p2p" + + "github.com/ethereum/go-ethereum/common" + "github.com/primevprotocol/mev-commit/pkg/p2p" + "github.com/primevprotocol/mev-commit/pkg/structures/preconf" + "github.com/primevprotocol/mev-commit/pkg/p2p/msgpack" "github.com/primevprotocol/mev-commit/pkg/topology" "golang.org/x/sync/semaphore" @@ -24,16 +29,18 @@ type P2PService interface { } type Preconfirmation struct { + signer preconf.Signer topo topology.Topology streamer P2PService sem *semaphore.Weighted quit chan struct{} } -func New(topo topology.Topology, streamer P2PService) *Preconfirmation { +func New(topo topology.Topology, streamer P2PService, key *ecdsa.PrivateKey) *Preconfirmation { return &Preconfirmation{ topo: topo, streamer: streamer, + signer: preconf.PrivateKeySigner{PrivKey: key}, } } @@ -131,7 +138,18 @@ func (p *Preconfirmation) handleBid( } /* TODO(@ckartik): Determine if the bid is to be acted on - e.g constructed into a pre-confimration */ - _ = ethAddress + searcherStream, err := p.streamer.NewStream(ctx, p2p.Peer{EthAddress: ethAddress, Type: p2p.PeerTypeSearcher}, ProtocolName, ProtocolVersion, "commitment") + if err != nil { + return err + } + + commitment, err := bid.ConstructCommitment(p.signer) + if err != nil { + return err + } + + _, w := msgpack.NewReaderWriter[preconf.PreconfCommitment, preconf.PreconfCommitment](searcherStream) + w.WriteMsg(ctx, &commitment) // if recieved from searcher broadcast to builder peers // elseif recieved from builder, don't broadcast diff --git a/pkg/structures/preconf/bid.go b/pkg/structures/preconf/bid.go index 0f6d251d..a21844cb 100644 --- a/pkg/structures/preconf/bid.go +++ b/pkg/structures/preconf/bid.go @@ -72,6 +72,18 @@ type IPreconfBidBuilder interface { ConstructCommitment(*ecdsa.PrivateKey) (PreconfCommitment, error) // Verfiy Signature and than constrcut the commitment } +type Signer interface { + Sign([]byte) ([]byte, error) +} + +type PrivateKeySigner struct { + PrivKey *ecdsa.PrivateKey +} + +func (p PrivateKeySigner) Sign([]byte) ([]byte, error) { + return crypto.Sign([]byte{}, p.PrivKey) +} + func (p PreconfCommitment) VerifyBuilderSignature() (common.Address, error) { if p.DataHash == nil || p.CommitmentSignature == nil { return common.Address{}, ErrMissingHashSignature @@ -132,7 +144,7 @@ func (p PreconfCommitment) CommitmentOriginator() (common.Address, *ecdsa.Public return crypto.PubkeyToAddress(*pubkey), pubkey, nil } -func (p PreConfBid) ConstructCommitment(privKey *ecdsa.PrivateKey) (PreconfCommitment, error) { +func (p PreConfBid) ConstructCommitment(signer Signer) (PreconfCommitment, error) { _, err := p.VerifySearcherSignature() if err != nil { return PreconfCommitment{}, err @@ -141,7 +153,7 @@ func (p PreConfBid) ConstructCommitment(privKey *ecdsa.PrivateKey) (PreconfCommi PreConfBid: p, } - err = commitment.constructHashAndSignature(privKey) + err = commitment.constructHashAndSignature(signer) if err != nil { return PreconfCommitment{}, err } @@ -151,7 +163,7 @@ func (p PreConfBid) ConstructCommitment(privKey *ecdsa.PrivateKey) (PreconfCommi // Adds bidHash and Signature to preconfbid // Fails atomically -func (p *PreconfCommitment) constructHashAndSignature(privKey *ecdsa.PrivateKey) (err error) { +func (p *PreconfCommitment) constructHashAndSignature(signer Signer) (err error) { if p.DataHash != nil || p.CommitmentSignature != nil { return ErrAlreadySignedCommitment } @@ -162,7 +174,8 @@ func (p *PreconfCommitment) constructHashAndSignature(privKey *ecdsa.PrivateKey) if err != nil { return err } - sig, err := crypto.Sign(dataHash, privKey) + + sig, err := signer.Sign(dataHash) if err != nil { return err } diff --git a/pkg/structures/preconf/bid_test.go b/pkg/structures/preconf/bid_test.go index 09730a40..4eb2d596 100644 --- a/pkg/structures/preconf/bid_test.go +++ b/pkg/structures/preconf/bid_test.go @@ -42,6 +42,7 @@ func TestCommitment(t *testing.T) { t.Fatalf("Failed to connect to the Ethereum client: %v", err) } key, _ := crypto.GenerateKey() + signer := PrivateKeySigner{key} bid, err := ConstructSignedBid(big.NewInt(10), "0xkadrtik", big.NewInt(2), key) if err != nil { t.Fatal(err) @@ -50,7 +51,7 @@ func TestCommitment(t *testing.T) { b, _ := json.Marshal(bid) var bid2 PreConfBid json.Unmarshal(b, &bid2) - commit, err := bid2.ConstructCommitment(key) + commit, err := bid2.ConstructCommitment(signer) if err != nil { t.Fatal(err) From fbd4f5047b9ac86a1d3f6ce1cc667cb3e76c83aa Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Wed, 27 Sep 2023 10:22:31 -0700 Subject: [PATCH 04/27] Adds handleCommitment function. --- pkg/preconfirmation/preconfirmation.go | 53 ++++++++++++-------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index ddffd811..37783c21 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -3,7 +3,6 @@ package preconfirmation import ( "context" "crypto/ecdsa" - "math/big" "github.com/ethereum/go-ethereum/common" "github.com/primevprotocol/mev-commit/pkg/p2p" @@ -53,41 +52,37 @@ func (p *Preconfirmation) Protocol() p2p.ProtocolSpec { Name: "bid", Handler: p.handleBid, }, - // { // This is going to be a stream exclusively from the builder to the searcher - // Name: "commitment", - // Handler: p.handleCommitment, - // }, + { // This is going to be a stream exclusively from the builder to the searcher + Name: "commitment", + Handler: p.handleCommitment, + }, }, } } -type UnsignedPreConfBid struct { - TxnHash string `json:"txnHash"` - Bid *big.Int `json:"bid"` - Blocknumber *big.Int `json:"blocknumber"` - // UUID string `json:"uuid"` // Assuming string representation for byte16 -} - -type PreConfBid struct { // Adds blocknumber for pre-conf bid - Will need to manage how to reciever acts on a bid / TTL is the blocknumber - UnsignedPreConfBid - - BidHash []byte `json:"bidhash"` - Signature []byte `json:"signature"` -} +// handlecommitment is meant to be used by the searcher exclusively to read the commitment value from the builder. +// They should verify the authenticity of the commitment +func (p *Preconfirmation) handleCommitment( + ctx context.Context, + peer p2p.Peer, + stream p2p.Stream, +) error { + r, _ := msgpack.NewReaderWriter[preconf.PreconfCommitment, preconf.PreconfCommitment](stream) + commitment, err := r.ReadMsg(ctx) + if err != nil { + return err + } -type PreconfCommitment struct { - PreConfBid + // Process commitment as a searcher + providerAddress, err := commitment.VerifyBuilderSignature() + userAddress, err := commitment.VerifySearcherSignature() + _ = providerAddress + _ = userAddress - DataHash []byte `json:"data_hash"` - CommitmentSignature []byte `json:"commitment_signature"` -} + // Check that user address is personal address + // me == useraddress -// golang interface -type IPreconfBid interface { - GetTxnHash() string - GetBidAmt() *big.Int - VerifySearcherSignature() (common.Address, error) - BidOriginator() (common.Address, *ecdsa.PublicKey, error) + return nil } func (p *Preconfirmation) verifyBid( From dbf74fb92370eb830a29c6c693b5427f0c8ed3d3 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Thu, 28 Sep 2023 00:45:07 -0700 Subject: [PATCH 05/27] WIP - part 2. --- .gitignore | 1 + go.mod | 16 ++++ go.sum | 108 +++++++++++++++++++++++++ pkg/preconfirmation/commitment.go | 89 ++++++++++++++++++++ pkg/preconfirmation/preconfirmation.go | 98 +++++++++------------- pkg/structures/preconf/bid.go | 31 ++++++- 6 files changed, 283 insertions(+), 60 deletions(-) create mode 100644 .gitignore create mode 100644 pkg/preconfirmation/commitment.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..5657f6ea --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor \ No newline at end of file diff --git a/go.mod b/go.mod index 573afdf8..a073439e 100644 --- a/go.mod +++ b/go.mod @@ -13,19 +13,29 @@ require ( ) require ( + github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/StackExchange/wmi v1.2.1 // indirect github.com/benbjohnson/clock v1.3.5 // indirect github.com/beorn7/perks v1.0.1 // indirect + github.com/bits-and-blooms/bitset v1.5.0 // indirect github.com/btcsuite/btcd v0.22.0-beta // indirect github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/consensys/bavard v0.1.13 // indirect + github.com/consensys/gnark-crypto v0.10.0 // indirect github.com/containerd/cgroups v1.1.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect + github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect + github.com/deckarep/golang-set/v2 v2.1.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/elastic/gosigar v0.14.2 // indirect + github.com/ethereum/c-kzg-4844 v0.3.1 // indirect github.com/flynn/noise v1.0.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect + github.com/go-ole/go-ole v1.2.5 // indirect + github.com/go-stack/stack v1.8.1 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect @@ -58,6 +68,7 @@ require ( github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect github.com/minio/sha256-simd v1.0.1 // indirect + github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/mr-tron/base58 v1.2.0 // indirect github.com/multiformats/go-base32 v0.1.0 // indirect github.com/multiformats/go-base36 v0.2.0 // indirect @@ -81,7 +92,11 @@ require ( github.com/quic-go/quic-go v0.38.1 // indirect github.com/quic-go/webtransport-go v0.5.3 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect + github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect + github.com/supranational/blst v0.3.11 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect go.uber.org/dig v1.17.0 // indirect go.uber.org/fx v1.20.0 // indirect @@ -95,4 +110,5 @@ require ( golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect google.golang.org/protobuf v1.30.0 // indirect lukechampine.com/blake3 v1.2.1 // indirect + rsc.io/tmplfunc v0.0.3 // indirect ) diff --git a/go.sum b/go.sum index a362d5b6..1a96fba8 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,14 @@ dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1 dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU= git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= +github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= +github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= +github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= +github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= +github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= @@ -17,6 +25,8 @@ github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZx github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bits-and-blooms/bitset v1.5.0 h1:NpE8frKRLGHIcEzkR+gZhiioW1+WbYV6fKwD6ZIpQT8= +github.com/bits-and-blooms/bitset v1.5.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.22.0-beta h1:LTDpDKUM5EeOFBPM8IXpinEcmZ6FWfNZbE3lfrfdnWo= @@ -38,6 +48,20 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cilium/ebpf v0.2.0/go.mod h1:To2CFviqOWL/M0gIMsvSMlqe7em/l1ALkX1PyjrX2Qs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cockroachdb/errors v1.8.1 h1:A5+txlVZfOqFBDa4mGz2bUWSp0aHElvHX2bKkdbQu+Y= +github.com/cockroachdb/errors v1.8.1/go.mod h1:qGwQn6JmZ+oMjuLwjWzUNqblqk0xl4CVV3SQbGwK7Ac= +github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f h1:o/kfcElHqOiXqcou5a3rIlMc7oJbMQkeLk0VQJ7zgqY= +github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= +github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06 h1:T+Np/xtzIjYM/P5NAw0e2Rf1FGvzDau1h54MKvx8G7w= +github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06/go.mod h1:bynZ3gvVyhlvjLI7PT6dmZ7g76xzJ7HpxfjgkzCGz6s= +github.com/cockroachdb/redact v1.0.8 h1:8QG/764wK+vmEYoOlfobpe12EQcS81ukx/a4hdVMxNw= +github.com/cockroachdb/redact v1.0.8/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= +github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 h1:IKgmqgMQlVJIZj19CdocBeSfSaiCbEBZGKODaixqtHM= +github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2/go.mod h1:8BT+cPK6xvFOcRlk0R8eg+OTkcqI6baNH4xAkpiYVvQ= +github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= +github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= +github.com/consensys/gnark-crypto v0.10.0 h1:zRh22SR7o4K35SoNqouS9J/TKHTyU2QWaj5ldehyXtA= +github.com/consensys/gnark-crypto v0.10.0/go.mod h1:Iq/P3HHl0ElSjsg2E1gsMwhAyxnxoKK5nVyZKd+/KhU= github.com/containerd/cgroups v0.0.0-20201119153540-4cbc285b3327/go.mod h1:ZJeTFisyysqgcCdecO57Dj79RfL0LNeGiFUqLYQRYLE= github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw= @@ -47,12 +71,18 @@ github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8 github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/crate-crypto/go-kzg-4844 v0.3.0 h1:UBlWE0CgyFqqzTI+IFyCzA7A3Zw4iip6uzRv5NIXG0A= +github.com/crate-crypto/go-kzg-4844 v0.3.0/go.mod h1:SBP7ikXEgDnUPONgm33HtuDZEDtWa3L4QtN1ocJSEQ4= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U= +github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI= +github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= @@ -65,29 +95,45 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/elastic/gosigar v0.12.0/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= github.com/elastic/gosigar v0.14.2 h1:Dg80n8cr90OZ7x+bAax/QjoW/XqTI11RmA79ZwIm9/4= github.com/elastic/gosigar v0.14.2/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= +github.com/ethereum/c-kzg-4844 v0.3.1 h1:sR65+68+WdnMKxseNWxSJuAv2tsUrihTpVBTfM/U5Zg= +github.com/ethereum/c-kzg-4844 v0.3.1/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/ethereum/go-ethereum v1.13.1 h1:UF2FaUKPIy5jeZk3X06ait3y2Q4wI+vJ1l7+UARp+60= github.com/ethereum/go-ethereum v1.13.1/go.mod h1:xHQKzwkHSl0gnSjZK1mWa06XEdm9685AHqhRknOzqGQ= +github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c= +github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ= github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk= github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= +github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqGNY4FhTFhk+o9oFHGINQ/+vhlm8HFzi6znCI= +github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY= +github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= +github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= +github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-jwt/jwt/v4 v4.3.0 h1:kHL1vqdqWNfATmA0FNMdmZNMyZI1U6O31X4rlIPoBog= +github.com/golang-jwt/jwt/v4 v4.3.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -99,6 +145,8 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk= +github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -113,6 +161,9 @@ github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXi github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b h1:h9U78+dx9a4BKdQkBBos92HalKpaGKHrp+3Uo6yTodo= github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= +github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= @@ -120,6 +171,12 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= +github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE= +github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0= +github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 h1:3JQNjnMRil1yD0IfZKHF9GxxWKDJGj8I0IqOUol//sw= +github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= +github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= +github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o= github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -160,6 +217,10 @@ github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= +github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38yPW7c= @@ -186,9 +247,13 @@ github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd h1:br0buuQ854V8u83wA0rVZ8ttrq5CpaPZdvrK0LP2lOk= github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd/go.mod h1:QuCEs1Nt24+FYQEqAAncTDPJIuGs+LxK1MCiFL25pMU= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= @@ -206,6 +271,13 @@ github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8Rv github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= +github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= +github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= +github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= +github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= +github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= +github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= @@ -237,6 +309,8 @@ github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/n github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= @@ -280,9 +354,16 @@ github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtB github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtDqv66NfsMU= github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= +github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= +github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= +github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shurcooL/component v0.0.0-20170202220835-f88ec8f54cc4/go.mod h1:XhFIlyj5a1fBNx5aJTbKoIq0mNaPvOagO+HjB3EtxrY= github.com/shurcooL/events v0.0.0-20181021180414-410e4ca65f48/go.mod h1:5u70Mqkb5O5cxEA8nxTsgrgLehJeAw6Oc4Ab1c/P1HM= github.com/shurcooL/github_flavored_markdown v0.0.0-20181002035957-2122de532470/go.mod h1:2dOwnU2uBioM+SGy2aZoq1f/Sd1l9OkAeAUvjSyvgU0= @@ -311,6 +392,8 @@ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:Udh github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= +github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -319,14 +402,29 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= +github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= +github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= +github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= +github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= +github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= +github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= +github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU= github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM= github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= @@ -417,6 +515,7 @@ golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190316082340-a2f829d7f35f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -428,6 +527,7 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -438,6 +538,8 @@ golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= +golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -483,10 +585,14 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= +gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= @@ -497,5 +603,7 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI= lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k= +rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= +rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck= sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0= diff --git a/pkg/preconfirmation/commitment.go b/pkg/preconfirmation/commitment.go new file mode 100644 index 00000000..40ac6e99 --- /dev/null +++ b/pkg/preconfirmation/commitment.go @@ -0,0 +1,89 @@ +package preconfirmation + +import ( + "context" + + "github.com/ethereum/go-ethereum/common" + "github.com/primevprotocol/mev-commit/pkg/p2p" + "github.com/primevprotocol/mev-commit/pkg/p2p/msgpack" + "github.com/primevprotocol/mev-commit/pkg/structures/preconf" + "github.com/primevprotocol/mev-commit/pkg/topology" + "golang.org/x/sync/semaphore" +) + +type CommitmentCallback struct { + signer preconf.Signer + topo topology.Topology + streamer P2PService + sem *semaphore.Weighted + quit chan struct{} +} + +func (cc *CommitmentCallback) Protocol() p2p.ProtocolSpec { + return p2p.ProtocolSpec{ + Name: ProtocolName, + Version: ProtocolVersion, + StreamSpecs: []p2p.StreamSpec{ + { // This is going to be a stream exclusively from the builder to the searcher + Name: "commitment", + Handler: cc.handleCommitment, + }, + }, + } +} + +func (cc *CommitmentCallback) ConstructAndSendCommitment(ctx context.Context, userAddress common.Address, bid *preconf.PreConfBid) error { + taregetUserPeer := p2p.Peer{EthAddress: userAddress, Type: p2p.PeerTypeSearcher} + + // Create a new connection + + /* TODO(@ckartik): Determine if the bid is to be acted on - e.g constructed into a pre-confimration */ + searcherStream, err := cc.streamer.NewStream(ctx, taregetUserPeer, ProtocolName, ProtocolVersion, "commitment") + if err != nil { + return err + } + + commitment, err := bid.ConstructCommitment(cc.signer) + if err != nil { + return err + } + + _, w := msgpack.NewReaderWriter[preconf.PreconfCommitment, preconf.PreconfCommitment](searcherStream) + err = w.WriteMsg(ctx, &commitment) + + return err +} + +// handlecommitment is meant to be used by the searcher exclusively to read the commitment value from the builder. +// They should verify the authenticity of the commitment +func (cc *CommitmentCallback) handleCommitment( + ctx context.Context, + peer p2p.Peer, + stream p2p.Stream, +) error { + r, _ := msgpack.NewReaderWriter[preconf.PreconfCommitment, preconf.PreconfCommitment](stream) + commitment, err := r.ReadMsg(ctx) + if err != nil { + return err + } + + // Process commitment as a searcher + providerAddress, err := commitment.VerifyBuilderSignature() + userAddress, err := commitment.VerifySearcherSignature() + _ = providerAddress + _ = userAddress + + // Check that user address is personal address + // me == useraddress + + /* TODO(@ckartik): Determine if the bid is to be acted on - e.g constructed into a pre-confimration */ + userStream, err := cc.streamer.NewStream(ctx, peer, ProtocolName, ProtocolVersion, "commitment") + if err != nil { + return err + } + + _, w := msgpack.NewReaderWriter[preconf.PreconfCommitment, preconf.PreconfCommitment](userStream) + err = w.WriteMsg(ctx, commitment) + + return err +} diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index 37783c21..7dfbe716 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -3,12 +3,11 @@ package preconfirmation import ( "context" "crypto/ecdsa" + "errors" "github.com/ethereum/go-ethereum/common" "github.com/primevprotocol/mev-commit/pkg/p2p" - "github.com/ethereum/go-ethereum/common" - "github.com/primevprotocol/mev-commit/pkg/p2p" "github.com/primevprotocol/mev-commit/pkg/structures/preconf" "github.com/primevprotocol/mev-commit/pkg/p2p/msgpack" @@ -52,41 +51,49 @@ func (p *Preconfirmation) Protocol() p2p.ProtocolSpec { Name: "bid", Handler: p.handleBid, }, - { // This is going to be a stream exclusively from the builder to the searcher - Name: "commitment", - Handler: p.handleCommitment, - }, }, } } -// handlecommitment is meant to be used by the searcher exclusively to read the commitment value from the builder. -// They should verify the authenticity of the commitment -func (p *Preconfirmation) handleCommitment( - ctx context.Context, - peer p2p.Peer, - stream p2p.Stream, -) error { - r, _ := msgpack.NewReaderWriter[preconf.PreconfCommitment, preconf.PreconfCommitment](stream) - commitment, err := r.ReadMsg(ctx) +// Local store of bids out +var bidsOut = make(map[common.Address]preconf.PreConfBid) + +func (p *Preconfirmation) SendBid(ctx context.Context, bid preconf.UnsignedPreConfBid) error { + signedBid, err := preconf.ConvertIntoSignedBid(bid, p.signer) if err != nil { return err } - // Process commitment as a searcher - providerAddress, err := commitment.VerifyBuilderSignature() - userAddress, err := commitment.VerifySearcherSignature() - _ = providerAddress - _ = userAddress + builders := p.topo.GetPeers(topology.Query{Type: p2p.PeerTypeBuilder}) + for _, builder := range builders { + // Create a new connection + builderStream, err := p.streamer.NewStream(ctx, builder, ProtocolName, ProtocolVersion, "bid") + if err != nil { + return err + } + + r, w := msgpack.NewReaderWriter[preconf.PreconfCommitment, preconf.PreConfBid](builderStream) + err = w.WriteMsg(ctx, &signedBid) + if err != nil { + return err + } - // Check that user address is personal address - // me == useraddress + commitment, err := r.ReadMsg(ctx) + + // Process commitment as a searcher + providerAddress, err := commitment.VerifyBuilderSignature() + userAddress, err := commitment.VerifySearcherSignature() + _ = providerAddress + _ = userAddress + + // Verify the bid details correspond. + } return nil } func (p *Preconfirmation) verifyBid( - bid *PreConfBid, + bid *preconf.PreConfBid, ) (common.Address, error) { ethAddress, err := bid.VerifySearcherSignature() @@ -97,31 +104,23 @@ func (p *Preconfirmation) verifyBid( return ethAddress, nil } -// BroadcastBid sends the bid to the specified peer -func (p *Preconfirmation) BroadcastBid(ctx context.Context, peer p2p.Peer, bid *PreConfBid) error { - stream, err := p.streamer.NewStream(ctx, peer, ProtocolName, ProtocolVersion, "bid") - if err != nil { - return err - } - - _, w := msgpack.NewReaderWriter[PreConfBid, PreConfBid](stream) - if err := w.WriteMsg(ctx, bid); err != nil { - return err - } - - return nil -} +var ErrInvalidSearcherTypeForBid = errors.New("invalid searcher type for bid") // handlebid is the function that is called when a bid is received // TODO(@ckartik): // When you open a stream with a searcher - the other side of the stream has the handler +// handlebid could have a bid sent by a searcher node or a builder node. func (p *Preconfirmation) handleBid( ctx context.Context, peer p2p.Peer, stream p2p.Stream, ) error { + if peer.Type != p2p.PeerTypeSearcher { + return ErrInvalidSearcherTypeForBid + } + // TODO(@ckartik): Change to reader only once availble - r, _ := msgpack.NewReaderWriter[preconf.PreConfBid, preconf.PreConfBid](stream) + r, w := msgpack.NewReaderWriter[preconf.PreConfBid, preconf.PreconfCommitment](stream) bid, err := r.ReadMsg(ctx) if err != nil { return err @@ -132,10 +131,8 @@ func (p *Preconfirmation) handleBid( return err } - /* TODO(@ckartik): Determine if the bid is to be acted on - e.g constructed into a pre-confimration */ - searcherStream, err := p.streamer.NewStream(ctx, p2p.Peer{EthAddress: ethAddress, Type: p2p.PeerTypeSearcher}, ProtocolName, ProtocolVersion, "commitment") - if err != nil { - return err + if peer.EthAddress != ethAddress { + return errors.New("eth address does not match") } commitment, err := bid.ConstructCommitment(p.signer) @@ -143,20 +140,5 @@ func (p *Preconfirmation) handleBid( return err } - _, w := msgpack.NewReaderWriter[preconf.PreconfCommitment, preconf.PreconfCommitment](searcherStream) - w.WriteMsg(ctx, &commitment) - // if recieved from searcher broadcast to builder peers - // elseif recieved from builder, don't broadcast - - // Query Focused on only selecting builder peers - builderPeers := p.topo.GetPeers(topology.Query{}) - for _, peer := range builderPeers { - // Send bid to peers - err := p.BroadcastBid(ctx, peer, bid) - if err != nil { - return err - } - } - - return nil + return w.WriteMsg(ctx, &commitment) } diff --git a/pkg/structures/preconf/bid.go b/pkg/structures/preconf/bid.go index a21844cb..0c51d2ed 100644 --- a/pkg/structures/preconf/bid.go +++ b/pkg/structures/preconf/bid.go @@ -186,6 +186,10 @@ func (p *PreconfCommitment) constructHashAndSignature(signer Signer) (err error) return nil } +func ConvertIntoSignedBid(unsignedBid UnsignedPreConfBid, signer Signer) (PreConfBid, error) { + return unsignedBid.constructHashAndSignature(signer) +} + // Returns a PreConfBid Object with an EIP712 signature of the payload func ConstructSignedBid(bidamt *big.Int, txnhash string, blocknumber *big.Int, key *ecdsa.PrivateKey) (IPreconfBidSearcher, error) { bid := &PreConfBid{ @@ -224,7 +228,29 @@ func (p PreConfBid) VerifySearcherSignature() (common.Address, error) { // Adds bidHash and Signature to preconfbid // Fails atomically -func (p *PreConfBid) constructHashAndSignature(privKey *ecdsa.PrivateKey) (err error) { +func (p *UnsignedPreConfBid) constructHashAndSignature(signer Signer) (PreConfBid, error) { + internalPayload := constructBidPayload(p.TxnHash, p.Bid, p.Blocknumber) + + bidHash, _, err := apitypes.TypedDataAndHash(internalPayload) + if err != nil { + return PreConfBid{}, err + } + + sig, err := signer.Sign(bidHash) + if err != nil { + return PreConfBid{}, err + } + + return PreConfBid{ + UnsignedPreConfBid: *p, + BidHash: bidHash, + Signature: sig, + }, nil +} + +// Adds bidHash and Signature to preconfbid +// Fails atomically +func (p *PreConfBid) constructHashAndSignature(signer Signer) (err error) { if p.BidHash != nil || p.Signature != nil { return ErrAlreadySignedBid } @@ -235,7 +261,8 @@ func (p *PreConfBid) constructHashAndSignature(privKey *ecdsa.PrivateKey) (err e if err != nil { return err } - sig, err := crypto.Sign(bidHash, privKey) + + sig, err := signer.Sign(bidHash) if err != nil { return err } From b406a27434a88a96b4d6ebb9250e830ebfed2db6 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Thu, 28 Sep 2023 13:21:50 -0700 Subject: [PATCH 06/27] Adds storage abstraction for commitments. --- pkg/preconfirmation/preconfirmation.go | 61 +++++++++++++++----------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index 7dfbe716..471c9b6b 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -31,6 +31,8 @@ type Preconfirmation struct { topo topology.Topology streamer P2PService sem *semaphore.Weighted + cs CommitmentsStore + us UserStore quit chan struct{} } @@ -55,9 +57,21 @@ func (p *Preconfirmation) Protocol() p2p.ProtocolSpec { } } -// Local store of bids out -var bidsOut = make(map[common.Address]preconf.PreConfBid) +// BidHash -> map of preconfs +// Key: BidHash +// Value: List of preconfs +var commitments map[string][]preconf.PreconfCommitment +type CommitmentsStore interface { + GetCommitments(bidHash []byte) ([]preconf.PreconfCommitment, error) + AddCommitment(bidHash []byte, commitment *preconf.PreconfCommitment) error +} + +type UserStore interface { + CheckUserRegistred(common.Address) bool +} + +// SendBid is meant to be called by the searcher to construct and send bids to the builder func (p *Preconfirmation) SendBid(ctx context.Context, bid preconf.UnsignedPreConfBid) error { signedBid, err := preconf.ConvertIntoSignedBid(bid, p.signer) if err != nil { @@ -65,6 +79,8 @@ func (p *Preconfirmation) SendBid(ctx context.Context, bid preconf.UnsignedPreCo } builders := p.topo.GetPeers(topology.Query{Type: p2p.PeerTypeBuilder}) + + // TODO(@ckartik): Push into a channel and process in parallel for _, builder := range builders { // Create a new connection builderStream, err := p.streamer.NewStream(ctx, builder, ProtocolName, ProtocolVersion, "bid") @@ -82,34 +98,28 @@ func (p *Preconfirmation) SendBid(ctx context.Context, bid preconf.UnsignedPreCo // Process commitment as a searcher providerAddress, err := commitment.VerifyBuilderSignature() + if err != nil { + return err + } userAddress, err := commitment.VerifySearcherSignature() + if err != nil { + return err + } + _ = providerAddress _ = userAddress // Verify the bid details correspond. + p.cs.AddCommitment(signedBid.BidHash, commitment) } return nil } -func (p *Preconfirmation) verifyBid( - bid *preconf.PreConfBid, -) (common.Address, error) { - - ethAddress, err := bid.VerifySearcherSignature() - if err != nil { - return common.Address{}, err - } - - return ethAddress, nil -} - var ErrInvalidSearcherTypeForBid = errors.New("invalid searcher type for bid") // handlebid is the function that is called when a bid is received -// TODO(@ckartik): -// When you open a stream with a searcher - the other side of the stream has the handler -// handlebid could have a bid sent by a searcher node or a builder node. +// It is meant to be used by the builder exclusively to read the bid value from the searcher. func (p *Preconfirmation) handleBid( ctx context.Context, peer p2p.Peer, @@ -126,19 +136,20 @@ func (p *Preconfirmation) handleBid( return err } - ethAddress, err := p.verifyBid(bid) + ethAddress, err := bid.VerifySearcherSignature() if err != nil { return err } - if peer.EthAddress != ethAddress { - return errors.New("eth address does not match") - } + if p.us.CheckUserRegistred(ethAddress) { + // More conditional Logic to determine signing of bid + commitment, err := bid.ConstructCommitment(p.signer) + if err != nil { + return err + } - commitment, err := bid.ConstructCommitment(p.signer) - if err != nil { - return err + return w.WriteMsg(ctx, &commitment) } - return w.WriteMsg(ctx, &commitment) + return nil } From 76aa376e338ed4e10dccfd1c56d94e4ba89183d9 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Thu, 28 Sep 2023 13:23:03 -0700 Subject: [PATCH 07/27] Removes redundant seperate protocol for commitments. --- pkg/preconfirmation/commitment.go | 89 ------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 pkg/preconfirmation/commitment.go diff --git a/pkg/preconfirmation/commitment.go b/pkg/preconfirmation/commitment.go deleted file mode 100644 index 40ac6e99..00000000 --- a/pkg/preconfirmation/commitment.go +++ /dev/null @@ -1,89 +0,0 @@ -package preconfirmation - -import ( - "context" - - "github.com/ethereum/go-ethereum/common" - "github.com/primevprotocol/mev-commit/pkg/p2p" - "github.com/primevprotocol/mev-commit/pkg/p2p/msgpack" - "github.com/primevprotocol/mev-commit/pkg/structures/preconf" - "github.com/primevprotocol/mev-commit/pkg/topology" - "golang.org/x/sync/semaphore" -) - -type CommitmentCallback struct { - signer preconf.Signer - topo topology.Topology - streamer P2PService - sem *semaphore.Weighted - quit chan struct{} -} - -func (cc *CommitmentCallback) Protocol() p2p.ProtocolSpec { - return p2p.ProtocolSpec{ - Name: ProtocolName, - Version: ProtocolVersion, - StreamSpecs: []p2p.StreamSpec{ - { // This is going to be a stream exclusively from the builder to the searcher - Name: "commitment", - Handler: cc.handleCommitment, - }, - }, - } -} - -func (cc *CommitmentCallback) ConstructAndSendCommitment(ctx context.Context, userAddress common.Address, bid *preconf.PreConfBid) error { - taregetUserPeer := p2p.Peer{EthAddress: userAddress, Type: p2p.PeerTypeSearcher} - - // Create a new connection - - /* TODO(@ckartik): Determine if the bid is to be acted on - e.g constructed into a pre-confimration */ - searcherStream, err := cc.streamer.NewStream(ctx, taregetUserPeer, ProtocolName, ProtocolVersion, "commitment") - if err != nil { - return err - } - - commitment, err := bid.ConstructCommitment(cc.signer) - if err != nil { - return err - } - - _, w := msgpack.NewReaderWriter[preconf.PreconfCommitment, preconf.PreconfCommitment](searcherStream) - err = w.WriteMsg(ctx, &commitment) - - return err -} - -// handlecommitment is meant to be used by the searcher exclusively to read the commitment value from the builder. -// They should verify the authenticity of the commitment -func (cc *CommitmentCallback) handleCommitment( - ctx context.Context, - peer p2p.Peer, - stream p2p.Stream, -) error { - r, _ := msgpack.NewReaderWriter[preconf.PreconfCommitment, preconf.PreconfCommitment](stream) - commitment, err := r.ReadMsg(ctx) - if err != nil { - return err - } - - // Process commitment as a searcher - providerAddress, err := commitment.VerifyBuilderSignature() - userAddress, err := commitment.VerifySearcherSignature() - _ = providerAddress - _ = userAddress - - // Check that user address is personal address - // me == useraddress - - /* TODO(@ckartik): Determine if the bid is to be acted on - e.g constructed into a pre-confimration */ - userStream, err := cc.streamer.NewStream(ctx, peer, ProtocolName, ProtocolVersion, "commitment") - if err != nil { - return err - } - - _, w := msgpack.NewReaderWriter[preconf.PreconfCommitment, preconf.PreconfCommitment](userStream) - err = w.WriteMsg(ctx, commitment) - - return err -} From 7a2149844874207cc87a988d198a0b524d8366eb Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Thu, 28 Sep 2023 13:27:47 -0700 Subject: [PATCH 08/27] Fixes spacing. --- pkg/preconfirmation/preconfirmation.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index 471c9b6b..d94bf3e0 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -7,10 +7,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/primevprotocol/mev-commit/pkg/p2p" - - "github.com/primevprotocol/mev-commit/pkg/structures/preconf" - "github.com/primevprotocol/mev-commit/pkg/p2p/msgpack" + "github.com/primevprotocol/mev-commit/pkg/structures/preconf" "github.com/primevprotocol/mev-commit/pkg/topology" "golang.org/x/sync/semaphore" ) From e6df471dc8c03d8ad9775b50d13d2275e4105eb6 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Thu, 28 Sep 2023 13:30:23 -0700 Subject: [PATCH 09/27] Fixes go vet issues. --- pkg/structures/preconf/bid.go | 4 ++-- pkg/structures/preconf/bid_test.go | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/pkg/structures/preconf/bid.go b/pkg/structures/preconf/bid.go index 0c51d2ed..36a2253a 100644 --- a/pkg/structures/preconf/bid.go +++ b/pkg/structures/preconf/bid.go @@ -199,8 +199,8 @@ func ConstructSignedBid(bidamt *big.Int, txnhash string, blocknumber *big.Int, k Blocknumber: blocknumber, }, } - - err := bid.constructHashAndSignature(key) + // init signer + err := bid.constructHashAndSignature(PrivateKeySigner{key}) if err != nil { return nil, err } diff --git a/pkg/structures/preconf/bid_test.go b/pkg/structures/preconf/bid_test.go index 4eb2d596..fff4a779 100644 --- a/pkg/structures/preconf/bid_test.go +++ b/pkg/structures/preconf/bid_test.go @@ -8,7 +8,6 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/ethclient" ) func TestBid(t *testing.T) { @@ -37,10 +36,10 @@ func TestBid(t *testing.T) { } func TestCommitment(t *testing.T) { - client, err := ethclient.Dial("http://54.200.76.18:8545") - if err != nil { - t.Fatalf("Failed to connect to the Ethereum client: %v", err) - } + // // client, err := ethclient.Dial("http://54.200.76.18:8545") + // if err != nil { + // t.Fatalf("Failed to connect to the Ethereum client: %v", err) + // } key, _ := crypto.GenerateKey() signer := PrivateKeySigner{key} bid, err := ConstructSignedBid(big.NewInt(10), "0xkadrtik", big.NewInt(2), key) @@ -57,11 +56,11 @@ func TestCommitment(t *testing.T) { t.Fatal(err) } commit.VerifyBuilderSignature() - privateKey, _ := crypto.HexToECDSA("7cea3c338ce48647725ca014a52a80b2a8eb71d184168c343150a98100439d1b") + // privateKey, _ := crypto.HexToECDSA("7cea3c338ce48647725ca014a52a80b2a8eb71d184168c343150a98100439d1b") - txn, err := commit.StoreCommitmentToDA(privateKey, "0x169c9cd14923ef3fed0e0ce98cdc71c3d6037728", client) - if err != nil { - t.Fatal(err) - } - t.Log(txn.Hash().Hex()) + // txn, err := commit.StoreCommitmentToDA(privateKey, "0x169c9cd14923ef3fed0e0ce98cdc71c3d6037728", client) + // if err != nil { + // t.Fatal(err) + // } + // t.Log(txn.Hash().Hex()) } From ffcbc8a25487e22c6075806ce9a33aaef9422986 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Thu, 28 Sep 2023 13:31:26 -0700 Subject: [PATCH 10/27] Removes test file from bid. --- pkg/structures/preconf/bid_test.go | 66 ------------------------------ 1 file changed, 66 deletions(-) delete mode 100644 pkg/structures/preconf/bid_test.go diff --git a/pkg/structures/preconf/bid_test.go b/pkg/structures/preconf/bid_test.go deleted file mode 100644 index fff4a779..00000000 --- a/pkg/structures/preconf/bid_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package preconf - -// construct test for bid -import ( - "encoding/json" - "math/big" - "testing" - - "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/crypto" -) - -func TestBid(t *testing.T) { - // Connect to Ganache - key, _ := crypto.GenerateKey() - - bid, err := ConstructSignedBid(big.NewInt(10), "0xkartik", big.NewInt(2), key) - if err != nil { - t.Fatal(err) - } - address, err := bid.VerifySearcherSignature() - t.Log(address) - b, _ := json.Marshal(bid) - var bid2 PreConfBid - json.Unmarshal(b, &bid2) - if err != nil { - t.Fatal(err) - } - t.Log(hexutil.Bytes(bid2.BidHash)) - sig := hexutil.Bytes(bid2.Signature) - t.Log(sig) - - if address.Big().Cmp(crypto.PubkeyToAddress(key.PublicKey).Big()) != 0 { - t.Fatal("Address not same as signer") - } -} - -func TestCommitment(t *testing.T) { - // // client, err := ethclient.Dial("http://54.200.76.18:8545") - // if err != nil { - // t.Fatalf("Failed to connect to the Ethereum client: %v", err) - // } - key, _ := crypto.GenerateKey() - signer := PrivateKeySigner{key} - bid, err := ConstructSignedBid(big.NewInt(10), "0xkadrtik", big.NewInt(2), key) - if err != nil { - t.Fatal(err) - } - - b, _ := json.Marshal(bid) - var bid2 PreConfBid - json.Unmarshal(b, &bid2) - commit, err := bid2.ConstructCommitment(signer) - - if err != nil { - t.Fatal(err) - } - commit.VerifyBuilderSignature() - // privateKey, _ := crypto.HexToECDSA("7cea3c338ce48647725ca014a52a80b2a8eb71d184168c343150a98100439d1b") - - // txn, err := commit.StoreCommitmentToDA(privateKey, "0x169c9cd14923ef3fed0e0ce98cdc71c3d6037728", client) - // if err != nil { - // t.Fatal(err) - // } - // t.Log(txn.Hash().Hex()) -} From 14bedd8d2ab58995435cc2acfb3936d8e26c830b Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Thu, 28 Sep 2023 13:35:00 -0700 Subject: [PATCH 11/27] Fixes linter issues. --- pkg/preconfirmation/preconfirmation.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index d94bf3e0..aae97397 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -10,7 +10,6 @@ import ( "github.com/primevprotocol/mev-commit/pkg/p2p/msgpack" "github.com/primevprotocol/mev-commit/pkg/structures/preconf" "github.com/primevprotocol/mev-commit/pkg/topology" - "golang.org/x/sync/semaphore" ) const ( @@ -28,10 +27,8 @@ type Preconfirmation struct { signer preconf.Signer topo topology.Topology streamer P2PService - sem *semaphore.Weighted cs CommitmentsStore us UserStore - quit chan struct{} } func New(topo topology.Topology, streamer P2PService, key *ecdsa.PrivateKey) *Preconfirmation { @@ -58,8 +55,7 @@ func (p *Preconfirmation) Protocol() p2p.ProtocolSpec { // BidHash -> map of preconfs // Key: BidHash // Value: List of preconfs -var commitments map[string][]preconf.PreconfCommitment - +// var commitments map[string][]preconf.PreconfCommitment type CommitmentsStore interface { GetCommitments(bidHash []byte) ([]preconf.PreconfCommitment, error) AddCommitment(bidHash []byte, commitment *preconf.PreconfCommitment) error @@ -108,7 +104,10 @@ func (p *Preconfirmation) SendBid(ctx context.Context, bid preconf.UnsignedPreCo _ = userAddress // Verify the bid details correspond. - p.cs.AddCommitment(signedBid.BidHash, commitment) + err = p.cs.AddCommitment(signedBid.BidHash, commitment) + if err != nil { + return err + } } return nil From e71303624a10febf277afa73180ba37cb89ff007 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Thu, 28 Sep 2023 13:39:49 -0700 Subject: [PATCH 12/27] resolve err linting. --- pkg/preconfirmation/preconfirmation.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index aae97397..7b5327b6 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -89,6 +89,9 @@ func (p *Preconfirmation) SendBid(ctx context.Context, bid preconf.UnsignedPreCo } commitment, err := r.ReadMsg(ctx) + if err != nil { + return err + } // Process commitment as a searcher providerAddress, err := commitment.VerifyBuilderSignature() From b0c85d18ce27690a36a53dda9e3e63c75e5ec0d6 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Thu, 28 Sep 2023 17:46:12 -0700 Subject: [PATCH 13/27] Adds test and fixes bug with signer. --- pkg/preconfirmation/preconfirmation_test.go | 95 +++++++++++++++++++++ pkg/structures/preconf/bid.go | 4 +- 2 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 pkg/preconfirmation/preconfirmation_test.go diff --git a/pkg/preconfirmation/preconfirmation_test.go b/pkg/preconfirmation/preconfirmation_test.go new file mode 100644 index 00000000..ec955c33 --- /dev/null +++ b/pkg/preconfirmation/preconfirmation_test.go @@ -0,0 +1,95 @@ +package preconfirmation_test + +import ( + "context" + "errors" + "math/big" + "sync" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/primevprotocol/mev-commit/pkg/p2p" + p2ptest "github.com/primevprotocol/mev-commit/pkg/p2p/testing" + "github.com/primevprotocol/mev-commit/pkg/preconfirmation" + "github.com/primevprotocol/mev-commit/pkg/structures/preconf" + "github.com/primevprotocol/mev-commit/pkg/topology" +) + +type testTopo struct { + mu sync.Mutex + peers []p2p.Peer +} + +func (t *testTopo) AddPeers(peers ...p2p.Peer) { + t.mu.Lock() + defer t.mu.Unlock() + + t.peers = append(t.peers, peers...) +} + +func (t *testTopo) GetPeers(q topology.Query) []p2p.Peer { + t.mu.Lock() + defer t.mu.Unlock() + + return t.peers +} + +func (t *testTopo) Connected(p2p.Peer) { + return +} + +func (t *testTopo) Disconnected(p2p.Peer) { + return +} + +func TestPreconfBidSubmission(t *testing.T) { + t.Parallel() + + t.Run("ok", func(t *testing.T) { + client := p2p.Peer{ + EthAddress: common.HexToAddress("0x1"), + Type: p2p.PeerTypeSearcher, + } + server := p2p.Peer{ + EthAddress: common.HexToAddress("0x2"), + Type: p2p.PeerTypeBuilder, + } + + svc := p2ptest.New( + p2ptest.WithConnectFunc(func(addr []byte) (p2p.Peer, error) { + if string(addr) != "test" { + return p2p.Peer{}, errors.New("invalid address") + } + return client, nil + }), + p2ptest.WithAddressbookFunc(func(p p2p.Peer) ([]byte, error) { + if p.EthAddress != client.EthAddress { + return nil, errors.New("invalid peer") + } + return []byte("test"), nil + }), + ) + + topo := &testTopo{} + key, _ := crypto.GenerateKey() + p := preconfirmation.New(topo, svc, key) + + svc.SetPeerHandler(server, p.Protocol()) + err := p.SendBid(context.Background(), preconf.UnsignedPreConfBid{TxnHash: "0x4c03a845396b770ad41b975d6bd3bf8c2bd5cca36867a3301f9598f2e3e9518d", Bid: big.NewInt(10), Blocknumber: big.NewInt(10)}) + if err != nil { + t.Fatal(err) + } + + // start := time.Now() + // for { + // if time.Since(start) > 5*time.Second { + // t.Fatal("timed out") + // } + // if len(topo.peers) == 1 { + // break + // } + // time.Sleep(100 * time.Millisecond) + // } + }) +} diff --git a/pkg/structures/preconf/bid.go b/pkg/structures/preconf/bid.go index 36a2253a..16db75d2 100644 --- a/pkg/structures/preconf/bid.go +++ b/pkg/structures/preconf/bid.go @@ -80,8 +80,8 @@ type PrivateKeySigner struct { PrivKey *ecdsa.PrivateKey } -func (p PrivateKeySigner) Sign([]byte) ([]byte, error) { - return crypto.Sign([]byte{}, p.PrivKey) +func (p PrivateKeySigner) Sign(digest []byte) ([]byte, error) { + return crypto.Sign(digest, p.PrivKey) } func (p PreconfCommitment) VerifyBuilderSignature() (common.Address, error) { From 2cb035231c77856928d254624497ae3d7b0cb49c Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Fri, 29 Sep 2023 11:48:26 -0700 Subject: [PATCH 14/27] Remove redundant return statements. --- pkg/preconfirmation/preconfirmation_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/preconfirmation/preconfirmation_test.go b/pkg/preconfirmation/preconfirmation_test.go index ec955c33..52d32f3d 100644 --- a/pkg/preconfirmation/preconfirmation_test.go +++ b/pkg/preconfirmation/preconfirmation_test.go @@ -36,11 +36,9 @@ func (t *testTopo) GetPeers(q topology.Query) []p2p.Peer { } func (t *testTopo) Connected(p2p.Peer) { - return } func (t *testTopo) Disconnected(p2p.Peer) { - return } func TestPreconfBidSubmission(t *testing.T) { From 4cb13a56caf210cb2bbc03d22d7217fdad7c5a71 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Fri, 29 Sep 2023 14:22:30 -0700 Subject: [PATCH 15/27] Adds refactor of preconfs package. --- pkg/preconfirmation/preconfirmation.go | 13 ++- pkg/structures/preconf/bid.go | 155 +++++-------------------- 2 files changed, 41 insertions(+), 127 deletions(-) diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index 7b5327b6..7246d73b 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -4,6 +4,7 @@ import ( "context" "crypto/ecdsa" "errors" + "math/big" "github.com/ethereum/go-ethereum/common" "github.com/primevprotocol/mev-commit/pkg/p2p" @@ -65,9 +66,15 @@ type UserStore interface { CheckUserRegistred(common.Address) bool } +/* + + TxnHash string `json:"txnHash"` + Bid *big.Int `json:"bid"` + Blocknumber *big.Int `json:"blocknumber"` +*/ // SendBid is meant to be called by the searcher to construct and send bids to the builder -func (p *Preconfirmation) SendBid(ctx context.Context, bid preconf.UnsignedPreConfBid) error { - signedBid, err := preconf.ConvertIntoSignedBid(bid, p.signer) +func (p *Preconfirmation) SendBid(ctx context.Context, txnHash string, bidamt *big.Int, blockNumber *big.Int) error { + signedBid, err := preconf.ConstructSignedBid(bidamt, txnHash, blockNumber, p.signer) if err != nil { return err } @@ -143,7 +150,7 @@ func (p *Preconfirmation) handleBid( if p.us.CheckUserRegistred(ethAddress) { // More conditional Logic to determine signing of bid - commitment, err := bid.ConstructCommitment(p.signer) + commitment, err := preconf.ConstructCommitment(*bid, p.signer) if err != nil { return err } diff --git a/pkg/structures/preconf/bid.go b/pkg/structures/preconf/bid.go index 16db75d2..f8f56660 100644 --- a/pkg/structures/preconf/bid.go +++ b/pkg/structures/preconf/bid.go @@ -20,18 +20,20 @@ var ( ErrAlreadySignedCommitment = errors.New("commitment is already hashed or signed") ) -type UnsignedPreConfBid struct { - TxnHash string `json:"txnHash"` - Bid *big.Int `json:"bid"` - Blocknumber *big.Int `json:"blocknumber"` - // UUID string `json:"uuid"` // Assuming string representation for byte16 -} +// type UnsignedPreConfBid struct { +// TxnHash string `json:"txnHash"` +// Bid *big.Int `json:"bid"` +// Blocknumber *big.Int `json:"blocknumber"` +// // UUID string `json:"uuid"` // Assuming string representation for byte16 +// } // Most of the bid details can go to the data-availabilty layer if needed, and only have the hash+sig live on chian // Preconf bid structure // PreConfBid represents the bid data. type PreConfBid struct { // Adds blocknumber for pre-conf bid - Will need to manage how to reciever acts on a bid / TTL is the blocknumber - UnsignedPreConfBid + TxnHash string `json:"txnHash"` + Bid *big.Int `json:"bid"` + Blocknumber *big.Int `json:"blocknumber"` BidHash []byte `json:"bidhash"` // TODO(@ckaritk): name better Signature []byte `json:"signature"` @@ -44,34 +46,6 @@ type PreconfCommitment struct { CommitmentSignature []byte `json:"commitment_signature"` } -// golang interface -type IPreconfBid interface { - GetTxnHash() string - GetBidAmt() *big.Int - VerifySearcherSignature() (common.Address, error) - BidOriginator() (common.Address, *ecdsa.PublicKey, error) -} - -type IPreconfCommitment interface { - IPreconfBid // TODO Implement for underlying data-structure - VerifyBuilderSignature() (common.Address, error) - CommitmentOriginator() (common.Address, *ecdsa.PublicKey, error) -} - -type IPreconfCommitmentBuilder interface { - IPreconfCommitment - PublishCommitment() error -} - -type IPreconfBidSearcher interface { - IPreconfBid -} - -type IPreconfBidBuilder interface { - IPreconfBid - ConstructCommitment(*ecdsa.PrivateKey) (PreconfCommitment, error) // Verfiy Signature and than constrcut the commitment -} - type Signer interface { Sign([]byte) ([]byte, error) } @@ -131,7 +105,7 @@ func (p PreConfBid) BidOriginator() (common.Address, *ecdsa.PublicKey, error) { } func (p PreconfCommitment) CommitmentOriginator() (common.Address, *ecdsa.PublicKey, error) { - _, err := p.VerifyBuilderSignature() + _, err := VerifyBuilderSignature(p) if err != nil { return common.Address{}, nil, err } @@ -144,7 +118,7 @@ func (p PreconfCommitment) CommitmentOriginator() (common.Address, *ecdsa.Public return crypto.PubkeyToAddress(*pubkey), pubkey, nil } -func (p PreConfBid) ConstructCommitment(signer Signer) (PreconfCommitment, error) { +func ConstructCommitment(p PreConfBid, signer Signer) (PreconfCommitment, error) { _, err := p.VerifySearcherSignature() if err != nil { return PreconfCommitment{}, err @@ -153,83 +127,33 @@ func (p PreConfBid) ConstructCommitment(signer Signer) (PreconfCommitment, error PreConfBid: p, } - err = commitment.constructHashAndSignature(signer) - if err != nil { - return PreconfCommitment{}, err - } - - return commitment, nil -} - -// Adds bidHash and Signature to preconfbid -// Fails atomically -func (p *PreconfCommitment) constructHashAndSignature(signer Signer) (err error) { - if p.DataHash != nil || p.CommitmentSignature != nil { - return ErrAlreadySignedCommitment - } - eip712Payload := constructCommitmentPayload(p.TxnHash, p.Bid, p.Blocknumber, p.BidHash, p.Signature) dataHash, _, err := apitypes.TypedDataAndHash(eip712Payload) if err != nil { - return err + return PreconfCommitment{}, err } sig, err := signer.Sign(dataHash) if err != nil { - return err + return PreconfCommitment{}, err } - p.DataHash = dataHash - p.CommitmentSignature = sig - - return nil -} + commitment.DataHash = dataHash + commitment.CommitmentSignature = sig -func ConvertIntoSignedBid(unsignedBid UnsignedPreConfBid, signer Signer) (PreConfBid, error) { - return unsignedBid.constructHashAndSignature(signer) + return commitment, nil } // Returns a PreConfBid Object with an EIP712 signature of the payload -func ConstructSignedBid(bidamt *big.Int, txnhash string, blocknumber *big.Int, key *ecdsa.PrivateKey) (IPreconfBidSearcher, error) { - bid := &PreConfBid{ - UnsignedPreConfBid: UnsignedPreConfBid{ - Bid: bidamt, - TxnHash: txnhash, - Blocknumber: blocknumber, - }, - } - // init signer - err := bid.constructHashAndSignature(PrivateKeySigner{key}) - if err != nil { - return nil, err +func ConstructSignedBid(bidamt *big.Int, txnhash string, blocknumber *big.Int, signer Signer) (PreConfBid, error) { + bid := PreConfBid{ + Bid: bidamt, + TxnHash: txnhash, + Blocknumber: blocknumber, } - return bid, nil -} - -// Verifies the bid -func (p PreConfBid) GetTxnHash() string { - return p.TxnHash -} - -func (p PreConfBid) GetBidAmt() *big.Int { - return p.Bid -} - -// Verifies the bid -func (p PreConfBid) VerifySearcherSignature() (common.Address, error) { - if p.BidHash == nil || p.Signature == nil { - return common.Address{}, ErrMissingHashSignature - } - - return eipVerify(constructBidPayload(p.TxnHash, p.Bid, p.Blocknumber), p.BidHash, p.Signature) -} - -// Adds bidHash and Signature to preconfbid -// Fails atomically -func (p *UnsignedPreConfBid) constructHashAndSignature(signer Signer) (PreConfBid, error) { - internalPayload := constructBidPayload(p.TxnHash, p.Bid, p.Blocknumber) + internalPayload := constructBidPayload(txnhash, bidamt, blocknumber) bidHash, _, err := apitypes.TypedDataAndHash(internalPayload) if err != nil { @@ -241,36 +165,19 @@ func (p *UnsignedPreConfBid) constructHashAndSignature(signer Signer) (PreConfBi return PreConfBid{}, err } - return PreConfBid{ - UnsignedPreConfBid: *p, - BidHash: bidHash, - Signature: sig, - }, nil -} - -// Adds bidHash and Signature to preconfbid -// Fails atomically -func (p *PreConfBid) constructHashAndSignature(signer Signer) (err error) { - if p.BidHash != nil || p.Signature != nil { - return ErrAlreadySignedBid - } + bid.BidHash = bidHash + bid.Signature = sig - internalPayload := constructBidPayload(p.TxnHash, p.Bid, p.Blocknumber) - - bidHash, _, err := apitypes.TypedDataAndHash(internalPayload) - if err != nil { - return err - } + return bid, nil +} - sig, err := signer.Sign(bidHash) - if err != nil { - return err +// Verifies the bid +func (p PreConfBid) VerifySearcherSignature() (common.Address, error) { + if p.BidHash == nil || p.Signature == nil { + return common.Address{}, ErrMissingHashSignature } - p.BidHash = bidHash - p.Signature = sig - - return nil + return eipVerify(constructBidPayload(p.TxnHash, p.Bid, p.Blocknumber), p.BidHash, p.Signature) } // Constructs the EIP712 formatted bid From 83ca314c302c200ddd8b234bd2eef8cdce72aca0 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Fri, 29 Sep 2023 15:08:42 -0700 Subject: [PATCH 16/27] Correct useage. --- pkg/structures/preconf/bid.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/structures/preconf/bid.go b/pkg/structures/preconf/bid.go index f8f56660..e7d3c365 100644 --- a/pkg/structures/preconf/bid.go +++ b/pkg/structures/preconf/bid.go @@ -105,7 +105,7 @@ func (p PreConfBid) BidOriginator() (common.Address, *ecdsa.PublicKey, error) { } func (p PreconfCommitment) CommitmentOriginator() (common.Address, *ecdsa.PublicKey, error) { - _, err := VerifyBuilderSignature(p) + _, err := p.VerifyBuilderSignature() if err != nil { return common.Address{}, nil, err } From 024da80497db04e0c25670af8dab6721e370c4d9 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Fri, 29 Sep 2023 15:46:13 -0700 Subject: [PATCH 17/27] fixes go.mod file. --- go.mod | 11 ++--------- go.sum | 39 --------------------------------------- 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/go.mod b/go.mod index d238fd31..646491a0 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/primevprotocol/mev-commit -go 1.21.1 +go 1.21 require ( github.com/ethereum/go-ethereum v1.13.2 @@ -15,8 +15,6 @@ require ( ) require ( - github.com/Microsoft/go-winio v0.6.1 // indirect - github.com/StackExchange/wmi v1.2.1 // indirect github.com/benbjohnson/clock v1.3.5 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.5.0 // indirect @@ -27,17 +25,15 @@ require ( github.com/consensys/gnark-crypto v0.10.0 // indirect github.com/containerd/cgroups v1.1.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect - github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect - github.com/deckarep/golang-set/v2 v2.1.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/elastic/gosigar v0.14.2 // indirect github.com/ethereum/c-kzg-4844 v0.3.1 // indirect github.com/flynn/noise v1.0.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect - github.com/go-ole/go-ole v1.2.5 // indirect github.com/go-stack/stack v1.8.1 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect @@ -95,12 +91,9 @@ require ( github.com/quic-go/quic-go v0.38.1 // indirect github.com/quic-go/webtransport-go v0.5.3 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect - github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/supranational/blst v0.3.11 // indirect - github.com/tklauser/go-sysconf v0.3.12 // indirect - github.com/tklauser/numcpus v0.6.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect go.uber.org/dig v1.17.0 // indirect diff --git a/go.sum b/go.sum index 205011f0..dd173661 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,6 @@ git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGy github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= -github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= -github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= @@ -81,8 +79,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U= -github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI= -github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= @@ -97,8 +93,6 @@ github.com/elastic/gosigar v0.14.2 h1:Dg80n8cr90OZ7x+bAax/QjoW/XqTI11RmA79ZwIm9/ github.com/elastic/gosigar v0.14.2/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= github.com/ethereum/c-kzg-4844 v0.3.1 h1:sR65+68+WdnMKxseNWxSJuAv2tsUrihTpVBTfM/U5Zg= github.com/ethereum/c-kzg-4844 v0.3.1/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= -github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c= -github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/ethereum/go-ethereum v1.13.2 h1:g9mCpfPWqCA1OL4e6C98PeVttb0HadfBRuKTGvMnOvw= github.com/ethereum/go-ethereum v1.13.2/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= @@ -107,10 +101,6 @@ github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwU github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk= github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= -github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqGNY4FhTFhk+o9oFHGINQ/+vhlm8HFzi6znCI= -github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= @@ -132,8 +122,6 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang-jwt/jwt/v4 v4.3.0 h1:kHL1vqdqWNfATmA0FNMdmZNMyZI1U6O31X4rlIPoBog= -github.com/golang-jwt/jwt/v4 v4.3.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -162,8 +150,6 @@ github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OI github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b h1:h9U78+dx9a4BKdQkBBos92HalKpaGKHrp+3Uo6yTodo= github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= @@ -171,12 +157,6 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= -github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE= -github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0= -github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 h1:3JQNjnMRil1yD0IfZKHF9GxxWKDJGj8I0IqOUol//sw= -github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= -github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= -github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o= github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -247,8 +227,6 @@ github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd h1:br0buuQ854V8u83wA0rVZ8ttrq5CpaPZdvrK0LP2lOk= github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd/go.mod h1:QuCEs1Nt24+FYQEqAAncTDPJIuGs+LxK1MCiFL25pMU= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= @@ -271,10 +249,6 @@ github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8Rv github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= -github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= -github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= -github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= @@ -352,9 +326,6 @@ github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2Ep github.com/quic-go/webtransport-go v0.5.3/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtDqv66NfsMU= -github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= -github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= -github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= @@ -392,8 +363,6 @@ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:Udh github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= -github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -411,9 +380,6 @@ github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFA github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= -github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= -github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= -github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= @@ -515,7 +481,6 @@ golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190316082340-a2f829d7f35f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -537,8 +502,6 @@ golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= -golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -584,8 +547,6 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= -gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 0faa14d2542049bc4b002edd0802c5aa41c005a8 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Sat, 30 Sep 2023 12:15:44 -0700 Subject: [PATCH 18/27] Fixes test call. --- pkg/preconfirmation/preconfirmation.go | 8 ++++++-- pkg/preconfirmation/preconfirmation_test.go | 3 +-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index 7246d73b..874cf80e 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -26,13 +26,17 @@ type P2PService interface { type Preconfirmation struct { signer preconf.Signer - topo topology.Topology + topo Topology streamer P2PService cs CommitmentsStore us UserStore } -func New(topo topology.Topology, streamer P2PService, key *ecdsa.PrivateKey) *Preconfirmation { +type Topology interface { + GetPeers(topology.Query) []p2p.Peer +} + +func New(topo Topology, streamer P2PService, key *ecdsa.PrivateKey) *Preconfirmation { return &Preconfirmation{ topo: topo, streamer: streamer, diff --git a/pkg/preconfirmation/preconfirmation_test.go b/pkg/preconfirmation/preconfirmation_test.go index 52d32f3d..b93392b2 100644 --- a/pkg/preconfirmation/preconfirmation_test.go +++ b/pkg/preconfirmation/preconfirmation_test.go @@ -12,7 +12,6 @@ import ( "github.com/primevprotocol/mev-commit/pkg/p2p" p2ptest "github.com/primevprotocol/mev-commit/pkg/p2p/testing" "github.com/primevprotocol/mev-commit/pkg/preconfirmation" - "github.com/primevprotocol/mev-commit/pkg/structures/preconf" "github.com/primevprotocol/mev-commit/pkg/topology" ) @@ -74,7 +73,7 @@ func TestPreconfBidSubmission(t *testing.T) { p := preconfirmation.New(topo, svc, key) svc.SetPeerHandler(server, p.Protocol()) - err := p.SendBid(context.Background(), preconf.UnsignedPreConfBid{TxnHash: "0x4c03a845396b770ad41b975d6bd3bf8c2bd5cca36867a3301f9598f2e3e9518d", Bid: big.NewInt(10), Blocknumber: big.NewInt(10)}) + err := p.SendBid(context.Background(), "0x4c03a845396b770ad41b975d6bd3bf8c2bd5cca36867a3301f9598f2e3e9518d", big.NewInt(10), big.NewInt(10)) if err != nil { t.Fatal(err) } From 7f8af3cc257c32a95532b3d4f1dea8ce40a216cc Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Sat, 30 Sep 2023 16:34:55 -0700 Subject: [PATCH 19/27] Update go version to 1.21.1. --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 646491a0..2c4a185e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/primevprotocol/mev-commit -go 1.21 +go 1.21.1 require ( github.com/ethereum/go-ethereum v1.13.2 From 65932084afb9d73c7e38d8419133200493e1ba8e Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Sat, 30 Sep 2023 16:36:46 -0700 Subject: [PATCH 20/27] Removes redundant comments. --- pkg/preconfirmation/preconfirmation.go | 6 ------ pkg/preconfirmation/preconfirmation_test.go | 11 +---------- pkg/structures/preconf/bid.go | 9 --------- 3 files changed, 1 insertion(+), 25 deletions(-) diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index 874cf80e..8edfd4b0 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -70,12 +70,6 @@ type UserStore interface { CheckUserRegistred(common.Address) bool } -/* - - TxnHash string `json:"txnHash"` - Bid *big.Int `json:"bid"` - Blocknumber *big.Int `json:"blocknumber"` -*/ // SendBid is meant to be called by the searcher to construct and send bids to the builder func (p *Preconfirmation) SendBid(ctx context.Context, txnHash string, bidamt *big.Int, blockNumber *big.Int) error { signedBid, err := preconf.ConstructSignedBid(bidamt, txnHash, blockNumber, p.signer) diff --git a/pkg/preconfirmation/preconfirmation_test.go b/pkg/preconfirmation/preconfirmation_test.go index b93392b2..4bcad0b9 100644 --- a/pkg/preconfirmation/preconfirmation_test.go +++ b/pkg/preconfirmation/preconfirmation_test.go @@ -78,15 +78,6 @@ func TestPreconfBidSubmission(t *testing.T) { t.Fatal(err) } - // start := time.Now() - // for { - // if time.Since(start) > 5*time.Second { - // t.Fatal("timed out") - // } - // if len(topo.peers) == 1 { - // break - // } - // time.Sleep(100 * time.Millisecond) - // } + // TODO(@ckartik): Verify output. }) } diff --git a/pkg/structures/preconf/bid.go b/pkg/structures/preconf/bid.go index e7d3c365..8e587d89 100644 --- a/pkg/structures/preconf/bid.go +++ b/pkg/structures/preconf/bid.go @@ -20,15 +20,6 @@ var ( ErrAlreadySignedCommitment = errors.New("commitment is already hashed or signed") ) -// type UnsignedPreConfBid struct { -// TxnHash string `json:"txnHash"` -// Bid *big.Int `json:"bid"` -// Blocknumber *big.Int `json:"blocknumber"` -// // UUID string `json:"uuid"` // Assuming string representation for byte16 -// } - -// Most of the bid details can go to the data-availabilty layer if needed, and only have the hash+sig live on chian -// Preconf bid structure // PreConfBid represents the bid data. type PreConfBid struct { // Adds blocknumber for pre-conf bid - Will need to manage how to reciever acts on a bid / TTL is the blocknumber TxnHash string `json:"txnHash"` From 6d6f1f8ebd41d5c1f13b3560f36945d0761ed2d3 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Sat, 30 Sep 2023 16:44:55 -0700 Subject: [PATCH 21/27] Nit cleanup. --- pkg/preconfirmation/preconfirmation.go | 14 ++++++++------ pkg/preconfirmation/preconfirmation_test.go | 1 - 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index 8edfd4b0..b06292bc 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -70,7 +70,12 @@ type UserStore interface { CheckUserRegistred(common.Address) bool } -// SendBid is meant to be called by the searcher to construct and send bids to the builder +// SendBid is meant to be called by the searcher to construct and send bids to the builder. +// It takes the txnHash, the bid amount in wei and the maximum valid block number. +// It waits for commitments from all builders and then returns. +// TODO(@ckartik): construct seperate go-routine to wait for commitments, with a context that cancels if a timeout is reached. +// +// It returns an error if the bid is not valid. func (p *Preconfirmation) SendBid(ctx context.Context, txnHash string, bidamt *big.Int, blockNumber *big.Int) error { signedBid, err := preconf.ConstructSignedBid(bidamt, txnHash, blockNumber, p.signer) if err != nil { @@ -99,18 +104,15 @@ func (p *Preconfirmation) SendBid(ctx context.Context, txnHash string, bidamt *b } // Process commitment as a searcher - providerAddress, err := commitment.VerifyBuilderSignature() + _, err = commitment.VerifyBuilderSignature() if err != nil { return err } - userAddress, err := commitment.VerifySearcherSignature() + _, err = commitment.VerifySearcherSignature() if err != nil { return err } - _ = providerAddress - _ = userAddress - // Verify the bid details correspond. err = p.cs.AddCommitment(signedBid.BidHash, commitment) if err != nil { diff --git a/pkg/preconfirmation/preconfirmation_test.go b/pkg/preconfirmation/preconfirmation_test.go index 4bcad0b9..637ef786 100644 --- a/pkg/preconfirmation/preconfirmation_test.go +++ b/pkg/preconfirmation/preconfirmation_test.go @@ -78,6 +78,5 @@ func TestPreconfBidSubmission(t *testing.T) { t.Fatal(err) } - // TODO(@ckartik): Verify output. }) } From b4e92b4a52b1c8892b7fa1c434490a43c6705892 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Sat, 30 Sep 2023 16:59:57 -0700 Subject: [PATCH 22/27] Return only pointers. --- pkg/preconfirmation/preconfirmation.go | 4 +-- pkg/structures/preconf/bid.go | 36 ++++++++++++++------------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index b06292bc..6b97c90e 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -67,7 +67,7 @@ type CommitmentsStore interface { } type UserStore interface { - CheckUserRegistred(common.Address) bool + CheckUserRegistred(*common.Address) bool } // SendBid is meant to be called by the searcher to construct and send bids to the builder. @@ -155,7 +155,7 @@ func (p *Preconfirmation) handleBid( return err } - return w.WriteMsg(ctx, &commitment) + return w.WriteMsg(ctx, commitment) } return nil diff --git a/pkg/structures/preconf/bid.go b/pkg/structures/preconf/bid.go index 8e587d89..341cd298 100644 --- a/pkg/structures/preconf/bid.go +++ b/pkg/structures/preconf/bid.go @@ -49,9 +49,9 @@ func (p PrivateKeySigner) Sign(digest []byte) ([]byte, error) { return crypto.Sign(digest, p.PrivKey) } -func (p PreconfCommitment) VerifyBuilderSignature() (common.Address, error) { +func (p *PreconfCommitment) VerifyBuilderSignature() (*common.Address, error) { if p.DataHash == nil || p.CommitmentSignature == nil { - return common.Address{}, ErrMissingHashSignature + return nil, ErrMissingHashSignature } internalPayload := constructCommitmentPayload(p.TxnHash, p.Bid, p.Blocknumber, p.BidHash, p.Signature) @@ -59,29 +59,31 @@ func (p PreconfCommitment) VerifyBuilderSignature() (common.Address, error) { return eipVerify(internalPayload, p.DataHash, p.Signature) } -func eipVerify(internalPayload apitypes.TypedData, expectedhash []byte, signature []byte) (common.Address, error) { +func eipVerify(internalPayload apitypes.TypedData, expectedhash []byte, signature []byte) (*common.Address, error) { payloadHash, _, err := apitypes.TypedDataAndHash(internalPayload) if err != nil { - return common.Address{}, err + return nil, err } if !bytes.Equal(payloadHash, expectedhash) { - return common.Address{}, ErrInvalidHash + return nil, ErrInvalidHash } pubkey, err := crypto.SigToPub(payloadHash, signature) if err != nil { - return common.Address{}, err + return nil, err } if !crypto.VerifySignature(crypto.FromECDSAPub(pubkey), payloadHash, signature[:len(signature)-1]) { - return common.Address{}, ErrInvalidSignature + return nil, ErrInvalidSignature } - return crypto.PubkeyToAddress(*pubkey), err + c := crypto.PubkeyToAddress(*pubkey) + + return &c, err } -func (p PreConfBid) BidOriginator() (common.Address, *ecdsa.PublicKey, error) { +func (p *PreConfBid) BidOriginator() (common.Address, *ecdsa.PublicKey, error) { _, err := p.VerifySearcherSignature() if err != nil { return common.Address{}, nil, err @@ -95,7 +97,7 @@ func (p PreConfBid) BidOriginator() (common.Address, *ecdsa.PublicKey, error) { return crypto.PubkeyToAddress(*pubkey), pubkey, nil } -func (p PreconfCommitment) CommitmentOriginator() (common.Address, *ecdsa.PublicKey, error) { +func (p *PreconfCommitment) CommitmentOriginator() (common.Address, *ecdsa.PublicKey, error) { _, err := p.VerifyBuilderSignature() if err != nil { return common.Address{}, nil, err @@ -109,10 +111,10 @@ func (p PreconfCommitment) CommitmentOriginator() (common.Address, *ecdsa.Public return crypto.PubkeyToAddress(*pubkey), pubkey, nil } -func ConstructCommitment(p PreConfBid, signer Signer) (PreconfCommitment, error) { +func ConstructCommitment(p PreConfBid, signer Signer) (*PreconfCommitment, error) { _, err := p.VerifySearcherSignature() if err != nil { - return PreconfCommitment{}, err + return nil, err } commitment := PreconfCommitment{ PreConfBid: p, @@ -122,18 +124,18 @@ func ConstructCommitment(p PreConfBid, signer Signer) (PreconfCommitment, error) dataHash, _, err := apitypes.TypedDataAndHash(eip712Payload) if err != nil { - return PreconfCommitment{}, err + return nil, err } sig, err := signer.Sign(dataHash) if err != nil { - return PreconfCommitment{}, err + return nil, err } commitment.DataHash = dataHash commitment.CommitmentSignature = sig - return commitment, nil + return &commitment, nil } // Returns a PreConfBid Object with an EIP712 signature of the payload @@ -163,9 +165,9 @@ func ConstructSignedBid(bidamt *big.Int, txnhash string, blocknumber *big.Int, s } // Verifies the bid -func (p PreConfBid) VerifySearcherSignature() (common.Address, error) { +func (p *PreConfBid) VerifySearcherSignature() (*common.Address, error) { if p.BidHash == nil || p.Signature == nil { - return common.Address{}, ErrMissingHashSignature + return nil, ErrMissingHashSignature } return eipVerify(constructBidPayload(p.TxnHash, p.Bid, p.Blocknumber), p.BidHash, p.Signature) From ab9ddaa93ad7d1b7bf956dcd43337346ce95d82c Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Sat, 30 Sep 2023 17:03:13 -0700 Subject: [PATCH 23/27] Updates all common.address function returns to be pointers. --- pkg/structures/preconf/bid.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/structures/preconf/bid.go b/pkg/structures/preconf/bid.go index 341cd298..84ff8be0 100644 --- a/pkg/structures/preconf/bid.go +++ b/pkg/structures/preconf/bid.go @@ -83,32 +83,36 @@ func eipVerify(internalPayload apitypes.TypedData, expectedhash []byte, signatur return &c, err } -func (p *PreConfBid) BidOriginator() (common.Address, *ecdsa.PublicKey, error) { +func (p *PreConfBid) BidOriginator() (*common.Address, *ecdsa.PublicKey, error) { _, err := p.VerifySearcherSignature() if err != nil { - return common.Address{}, nil, err + return nil, nil, err } pubkey, err := crypto.SigToPub(p.BidHash, p.Signature) if err != nil { - return common.Address{}, nil, err + return nil, nil, err } - return crypto.PubkeyToAddress(*pubkey), pubkey, nil + address := crypto.PubkeyToAddress(*pubkey) + + return &address, pubkey, nil } -func (p *PreconfCommitment) CommitmentOriginator() (common.Address, *ecdsa.PublicKey, error) { +func (p *PreconfCommitment) CommitmentOriginator() (*common.Address, *ecdsa.PublicKey, error) { _, err := p.VerifyBuilderSignature() if err != nil { - return common.Address{}, nil, err + return nil, nil, err } pubkey, err := crypto.SigToPub(p.DataHash, p.CommitmentSignature) if err != nil { - return common.Address{}, nil, err + return nil, nil, err } - return crypto.PubkeyToAddress(*pubkey), pubkey, nil + address := crypto.PubkeyToAddress(*pubkey) + + return &address, pubkey, nil } func ConstructCommitment(p PreConfBid, signer Signer) (*PreconfCommitment, error) { From fdedfcc427f1bbc6f7a21a3517b9b14bc759613e Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Sat, 30 Sep 2023 17:23:01 -0700 Subject: [PATCH 24/27] Returns pointer for bid. --- pkg/preconfirmation/preconfirmation.go | 2 +- pkg/structures/preconf/bid.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index 6b97c90e..6f3ba156 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -93,7 +93,7 @@ func (p *Preconfirmation) SendBid(ctx context.Context, txnHash string, bidamt *b } r, w := msgpack.NewReaderWriter[preconf.PreconfCommitment, preconf.PreConfBid](builderStream) - err = w.WriteMsg(ctx, &signedBid) + err = w.WriteMsg(ctx, signedBid) if err != nil { return err } diff --git a/pkg/structures/preconf/bid.go b/pkg/structures/preconf/bid.go index 84ff8be0..8cbc8975 100644 --- a/pkg/structures/preconf/bid.go +++ b/pkg/structures/preconf/bid.go @@ -143,7 +143,7 @@ func ConstructCommitment(p PreConfBid, signer Signer) (*PreconfCommitment, error } // Returns a PreConfBid Object with an EIP712 signature of the payload -func ConstructSignedBid(bidamt *big.Int, txnhash string, blocknumber *big.Int, signer Signer) (PreConfBid, error) { +func ConstructSignedBid(bidamt *big.Int, txnhash string, blocknumber *big.Int, signer Signer) (*PreConfBid, error) { bid := PreConfBid{ Bid: bidamt, TxnHash: txnhash, @@ -154,18 +154,18 @@ func ConstructSignedBid(bidamt *big.Int, txnhash string, blocknumber *big.Int, s bidHash, _, err := apitypes.TypedDataAndHash(internalPayload) if err != nil { - return PreConfBid{}, err + return nil, err } sig, err := signer.Sign(bidHash) if err != nil { - return PreConfBid{}, err + return nil, err } bid.BidHash = bidHash bid.Signature = sig - return bid, nil + return &bid, nil } // Verifies the bid From 12c46a387fb7ffbc64f1ad7b81b81313bcba81f3 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Mon, 2 Oct 2023 13:16:54 -0400 Subject: [PATCH 25/27] Updates tests to be more expansive, and reduces redundant code. --- pkg/preconfirmation/preconfirmation.go | 12 +++---- pkg/preconfirmation/preconfirmation_test.go | 39 ++++++++++++++------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index 6f3ba156..03160c0f 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -18,16 +18,10 @@ const ( ProtocolVersion = "1.0.0" ) -type P2PService interface { - p2p.Streamer - p2p.Addressbook - Connect(context.Context, []byte) (p2p.Peer, error) -} - type Preconfirmation struct { signer preconf.Signer topo Topology - streamer P2PService + streamer p2p.Streamer cs CommitmentsStore us UserStore } @@ -36,11 +30,13 @@ type Topology interface { GetPeers(topology.Query) []p2p.Peer } -func New(topo Topology, streamer P2PService, key *ecdsa.PrivateKey) *Preconfirmation { +func New(topo Topology, streamer p2p.Streamer, key *ecdsa.PrivateKey, us UserStore, cs CommitmentsStore) *Preconfirmation { return &Preconfirmation{ topo: topo, streamer: streamer, signer: preconf.PrivateKeySigner{PrivKey: key}, + us: us, + cs: cs, } } diff --git a/pkg/preconfirmation/preconfirmation_test.go b/pkg/preconfirmation/preconfirmation_test.go index 637ef786..e751e9fc 100644 --- a/pkg/preconfirmation/preconfirmation_test.go +++ b/pkg/preconfirmation/preconfirmation_test.go @@ -2,7 +2,6 @@ package preconfirmation_test import ( "context" - "errors" "math/big" "sync" "testing" @@ -12,6 +11,7 @@ import ( "github.com/primevprotocol/mev-commit/pkg/p2p" p2ptest "github.com/primevprotocol/mev-commit/pkg/p2p/testing" "github.com/primevprotocol/mev-commit/pkg/preconfirmation" + "github.com/primevprotocol/mev-commit/pkg/structures/preconf" "github.com/primevprotocol/mev-commit/pkg/topology" ) @@ -31,7 +31,7 @@ func (t *testTopo) GetPeers(q topology.Query) []p2p.Peer { t.mu.Lock() defer t.mu.Unlock() - return t.peers + return []p2p.Peer{{EthAddress: common.HexToAddress("0x2"), Type: p2p.PeerTypeSearcher}} } func (t *testTopo) Connected(p2p.Peer) { @@ -40,6 +40,24 @@ func (t *testTopo) Connected(p2p.Peer) { func (t *testTopo) Disconnected(p2p.Peer) { } +type testCommitmentStore struct { +} + +func (t *testCommitmentStore) GetCommitments(bidHash []byte) ([]preconf.PreconfCommitment, error) { + return []preconf.PreconfCommitment{}, nil +} + +func (t *testCommitmentStore) AddCommitment(bidHash []byte, commitment *preconf.PreconfCommitment) error { + return nil +} + +type testUserStore struct { +} + +func (t *testUserStore) CheckUserRegistred(_ *common.Address) bool { + return true +} + func TestPreconfBidSubmission(t *testing.T) { t.Parallel() @@ -50,29 +68,24 @@ func TestPreconfBidSubmission(t *testing.T) { } server := p2p.Peer{ EthAddress: common.HexToAddress("0x2"), - Type: p2p.PeerTypeBuilder, + Type: p2p.PeerTypeSearcher, } svc := p2ptest.New( p2ptest.WithConnectFunc(func(addr []byte) (p2p.Peer, error) { - if string(addr) != "test" { - return p2p.Peer{}, errors.New("invalid address") - } return client, nil }), - p2ptest.WithAddressbookFunc(func(p p2p.Peer) ([]byte, error) { - if p.EthAddress != client.EthAddress { - return nil, errors.New("invalid peer") - } - return []byte("test"), nil - }), ) topo := &testTopo{} + us := &testUserStore{} + cs := &testCommitmentStore{} key, _ := crypto.GenerateKey() - p := preconfirmation.New(topo, svc, key) + p := preconfirmation.New(topo, svc, key, us, cs) + // svc.SetPeerHandler(client, p.Protocol()) svc.SetPeerHandler(server, p.Protocol()) + err := p.SendBid(context.Background(), "0x4c03a845396b770ad41b975d6bd3bf8c2bd5cca36867a3301f9598f2e3e9518d", big.NewInt(10), big.NewInt(10)) if err != nil { t.Fatal(err) From e3d14f9781a7c66929cdde5e83841222399573c2 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Mon, 2 Oct 2023 15:12:51 -0400 Subject: [PATCH 26/27] adds self peer node to p2ptest init. --- pkg/discovery/discovery_test.go | 1 + pkg/p2p/testing/p2p.go | 6 ++++-- pkg/preconfirmation/preconfirmation_test.go | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/discovery/discovery_test.go b/pkg/discovery/discovery_test.go index c8f9605b..89a7906c 100644 --- a/pkg/discovery/discovery_test.go +++ b/pkg/discovery/discovery_test.go @@ -61,6 +61,7 @@ func TestDiscovery(t *testing.T) { } svc := p2ptest.New( + &client, p2ptest.WithConnectFunc(func(addr []byte) (p2p.Peer, error) { if string(addr) != "test" { return p2p.Peer{}, errors.New("invalid address") diff --git a/pkg/p2p/testing/p2p.go b/pkg/p2p/testing/p2p.go index f8af2c0b..99db115c 100644 --- a/pkg/p2p/testing/p2p.go +++ b/pkg/p2p/testing/p2p.go @@ -70,6 +70,7 @@ func pipe(a, b *testStream) { type Option func(*P2PTest) type P2PTest struct { + self *p2p.Peer handlers map[string]p2p.ProtocolSpec connectFunc func([]byte) (p2p.Peer, error) addressbookFunc func(p2p.Peer) ([]byte, error) @@ -87,9 +88,10 @@ func WithAddressbookFunc(fn func(p p2p.Peer) ([]byte, error)) Option { } } -func New(opts ...Option) *P2PTest { +func New(selfNode *p2p.Peer, opts ...Option) *P2PTest { p := &P2PTest{ handlers: make(map[string]p2p.ProtocolSpec), + self: selfNode, } for _, opt := range opts { @@ -146,7 +148,7 @@ func (p *P2PTest) NewStream( go func() { defer in.Close() - err := handler(context.Background(), peer, in) + err := handler(context.Background(), *p.self, in) if err != nil { panic(err) } diff --git a/pkg/preconfirmation/preconfirmation_test.go b/pkg/preconfirmation/preconfirmation_test.go index e751e9fc..6206506d 100644 --- a/pkg/preconfirmation/preconfirmation_test.go +++ b/pkg/preconfirmation/preconfirmation_test.go @@ -31,7 +31,7 @@ func (t *testTopo) GetPeers(q topology.Query) []p2p.Peer { t.mu.Lock() defer t.mu.Unlock() - return []p2p.Peer{{EthAddress: common.HexToAddress("0x2"), Type: p2p.PeerTypeSearcher}} + return []p2p.Peer{{EthAddress: common.HexToAddress("0x2"), Type: p2p.PeerTypeBuilder}} } func (t *testTopo) Connected(p2p.Peer) { @@ -68,10 +68,11 @@ func TestPreconfBidSubmission(t *testing.T) { } server := p2p.Peer{ EthAddress: common.HexToAddress("0x2"), - Type: p2p.PeerTypeSearcher, + Type: p2p.PeerTypeBuilder, } svc := p2ptest.New( + &client, p2ptest.WithConnectFunc(func(addr []byte) (p2p.Peer, error) { return client, nil }), From fb3daf071d8ef87fa0b54d63abbfe005b0e7b1b7 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Mon, 2 Oct 2023 15:16:41 -0400 Subject: [PATCH 27/27] remove redundant code. --- pkg/preconfirmation/preconfirmation_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/preconfirmation/preconfirmation_test.go b/pkg/preconfirmation/preconfirmation_test.go index 6206506d..e9c57223 100644 --- a/pkg/preconfirmation/preconfirmation_test.go +++ b/pkg/preconfirmation/preconfirmation_test.go @@ -73,9 +73,6 @@ func TestPreconfBidSubmission(t *testing.T) { svc := p2ptest.New( &client, - p2ptest.WithConnectFunc(func(addr []byte) (p2p.Peer, error) { - return client, nil - }), ) topo := &testTopo{}