Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change network to interface in SimpleSigner #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading