Skip to content

Commit

Permalink
Change network to interface in SimpleSigner
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Feb 9, 2024
1 parent eca3b4b commit 05531dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 2 additions & 4 deletions signer/far_future_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ import (
"time"

"github.com/attestantio/go-eth2-client/spec/phase0"

"github.com/bloxapp/eth2-key-manager/core"
)

// FarFutureMaxValidEpoch is the max epoch of far future signing
var FarFutureMaxValidEpoch = int64(time.Minute.Seconds() * 20)

// IsValidFarFutureEpoch prevents far into the future signing request, verify a slot is within the current epoch
// https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/validator.md#protection-best-practices
func IsValidFarFutureEpoch(network core.Network, epoch phase0.Epoch) bool {
func IsValidFarFutureEpoch(network network, epoch phase0.Epoch) bool {
maxValidEpoch := network.EstimatedEpochAtSlot(network.EstimatedSlotAtTime(time.Now().Unix() + FarFutureMaxValidEpoch))
return epoch <= maxValidEpoch
}

// IsValidFarFutureSlot returns true if the given slot is valid
func IsValidFarFutureSlot(network core.Network, slot phase0.Slot) bool {
func IsValidFarFutureSlot(network network, slot phase0.Slot) bool {
maxValidSlot := network.EstimatedSlotAtTime(time.Now().Unix() + FarFutureMaxValidEpoch)
return slot <= maxValidSlot
}
9 changes: 7 additions & 2 deletions signer/validator_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,22 @@ type ValidatorSigner interface {
SignBLSToExecutionChange(blsToExecutionChange *capella.BLSToExecutionChange, domain phase0.Domain, pubKey []byte) (sig []byte, root []byte, err error)
}

type network interface {
EstimatedEpochAtSlot(slot phase0.Slot) phase0.Epoch
EstimatedSlotAtTime(time int64) phase0.Slot
}

// SimpleSigner implements ValidatorSigner interface
type SimpleSigner struct {
wallet core.Wallet
slashingProtector core.SlashingProtector
network core.Network
network network
signLocks map[string]*sync.RWMutex
mapLock *sync.RWMutex
}

// NewSimpleSigner is the constructor of SimpleSigner
func NewSimpleSigner(wallet core.Wallet, slashingProtector core.SlashingProtector, network core.Network) *SimpleSigner {
func NewSimpleSigner(wallet core.Wallet, slashingProtector core.SlashingProtector, network network) *SimpleSigner {
return &SimpleSigner{
wallet: wallet,
slashingProtector: slashingProtector,
Expand Down

0 comments on commit 05531dc

Please sign in to comment.