From 9731e3bdd493f3d20cc5a3ff9bab0bd8440a97c9 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 8 Jul 2024 17:30:19 +0000 Subject: [PATCH] mixpool: Reject KEs submitted too early --- mixing/mixpool/mixpool.go | 8 ++++++++ mixing/mixpool/mixpool_test.go | 3 ++- mixing/mixpool/orphans_test.go | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/mixing/mixpool/mixpool.go b/mixing/mixpool/mixpool.go index a16268289..335dbb938 100644 --- a/mixing/mixpool/mixpool.go +++ b/mixing/mixpool/mixpool.go @@ -28,6 +28,7 @@ import ( const minconf = 1 const feeRate = 0.0001e8 +const earlyKEDuration = 5 * time.Second type idPubKey = [33]byte @@ -1394,6 +1395,13 @@ func (p *Pool) checkAcceptKE(ke *wire.MsgMixKeyExchange) error { return ruleError(ErrPeerPositionOutOfBounds) } + now := time.Now() + keEpoch := time.Unix(int64(ke.Epoch), 0) + if now.Add(earlyKEDuration).Before(keEpoch) { + err := fmt.Errorf("KE received too early for stated epoch") + return ruleError(err) + } + return nil } diff --git a/mixing/mixpool/mixpool_test.go b/mixing/mixpool/mixpool_test.go index 1baa29ac1..bdfb5a814 100644 --- a/mixing/mixpool/mixpool_test.go +++ b/mixing/mixpool/mixpool_test.go @@ -14,6 +14,7 @@ import ( "math/big" "os" "testing" + "time" "decred.org/cspp/v2/solverrpc" "github.com/davecgh/go-spew/spew" @@ -255,7 +256,7 @@ func TestAccept(t *testing.T) { var ( seenPRs = []chainhash.Hash{pr.Hash()} - epoch uint64 = 0 + epoch uint64 = uint64(time.Now().Unix()) sid [32]byte = mixing.SortPRsForSession([]*wire.MsgMixPairReq{pr}, epoch) run uint32 = 0 pos uint32 = 0 diff --git a/mixing/mixpool/orphans_test.go b/mixing/mixpool/orphans_test.go index fb6bc0151..48ffd7917 100644 --- a/mixing/mixpool/orphans_test.go +++ b/mixing/mixpool/orphans_test.go @@ -8,6 +8,7 @@ import ( "errors" "reflect" "testing" + "time" "github.com/decred/dcrd/chaincfg/chainhash" "github.com/decred/dcrd/chaincfg/v3" @@ -65,7 +66,7 @@ func TestOrphans(t *testing.T) { pr.WriteHash(h) prs := []*wire.MsgMixPairReq{pr} - epoch := uint64(1704067200) + epoch := uint64(time.Now().Unix()) sid := mixing.SortPRsForSession(prs, epoch) ke := &wire.MsgMixKeyExchange{ Identity: id,