Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #31 from primevprotocol/ckartik/add-testing
Browse files Browse the repository at this point in the history
Adds Testing for Bids/Commitments
  • Loading branch information
kant777 authored Oct 3, 2023
2 parents 76581c2 + f9ef896 commit 47f3409
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 5 deletions.
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/libp2p/go-msgio v0.3.0
github.com/multiformats/go-multiaddr v0.11.0
github.com/prometheus/client_golang v1.17.0
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.25.7
github.com/vmihailenco/msgpack/v5 v5.4.0
golang.org/x/crypto v0.13.0
Expand All @@ -28,6 +29,7 @@ require (
github.com/coreos/go-systemd/v22 v22.5.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/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
Expand Down Expand Up @@ -83,6 +85,7 @@ require (
github.com/opencontainers/runtime-spec v1.1.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
Expand All @@ -107,6 +110,7 @@ require (
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ github.com/btcsuite/btcd v0.22.0-beta h1:LTDpDKUM5EeOFBPM8IXpinEcmZ6FWfNZbE3lfrf
github.com/btcsuite/btcd v0.22.0-beta/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA=
github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k=
github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o=
Expand Down
2 changes: 1 addition & 1 deletion pkg/structures/preconf/bid.go → pkg/preconf/bid.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (p *PreconfCommitment) VerifyBuilderSignature() (*common.Address, error) {

internalPayload := constructCommitmentPayload(p.TxnHash, p.Bid, p.Blocknumber, p.BidHash, p.Signature)

return eipVerify(internalPayload, p.DataHash, p.Signature)
return eipVerify(internalPayload, p.DataHash, p.CommitmentSignature)
}

func eipVerify(internalPayload apitypes.TypedData, expectedhash []byte, signature []byte) (*common.Address, error) {
Expand Down
61 changes: 61 additions & 0 deletions pkg/preconf/bid_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package preconf_test

import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/crypto"
"github.com/primevprotocol/mev-commit/pkg/preconf"
"github.com/stretchr/testify/assert"
)

func TestBids(t *testing.T) {
t.Parallel()

t.Run("bid", func(t *testing.T) {
key, _ := crypto.GenerateKey()

bid, err := preconf.ConstructSignedBid(big.NewInt(10), "0xkartik", big.NewInt(2), preconf.PrivateKeySigner{PrivKey: key})
if err != nil {
t.Fatal(err)
}
address, err := bid.VerifySearcherSignature()

if err != nil {
t.Fatal(err)
}

expectedAddress := crypto.PubkeyToAddress(key.PublicKey)

originatorAddress, pubkey, err := bid.BidOriginator()
if err != nil {
t.Fail()
}
assert.Equal(t, expectedAddress, *originatorAddress)
assert.Equal(t, expectedAddress, *address)
assert.Equal(t, key.PublicKey, *pubkey)
})
t.Run("commitment", func(t *testing.T) {
userKey, _ := crypto.GenerateKey()
userSigner := preconf.PrivateKeySigner{PrivKey: userKey}

builderKey, _ := crypto.GenerateKey()
builderSigner := preconf.PrivateKeySigner{PrivKey: builderKey}

bid, err := preconf.ConstructSignedBid(big.NewInt(10), "0xkartik", big.NewInt(2), userSigner)
if err != nil {
t.Fatal(err)
}
commitment, err := preconf.ConstructCommitment(*bid, builderSigner)
if err != nil {
t.Fail()
}
address, err := commitment.VerifyBuilderSignature()
if err != nil {
t.Fail()
}

assert.Equal(t, crypto.PubkeyToAddress(builderKey.PublicKey), *address)

})
}
2 changes: 1 addition & 1 deletion pkg/preconfirmation/preconfirmation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"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/preconf"
"github.com/primevprotocol/mev-commit/pkg/topology"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/preconfirmation/preconfirmation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"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/preconf"
"github.com/primevprotocol/mev-commit/pkg/preconfirmation"
"github.com/primevprotocol/mev-commit/pkg/structures/preconf"
"github.com/primevprotocol/mev-commit/pkg/topology"
)

Expand Down

0 comments on commit 47f3409

Please sign in to comment.