Deneb integration to Caplin (#9093)

Pr is ready to review and merge. 

This PR includes implementing and integrating Ethereum Deneb's hard work
with the Caplin Ethereum client.

Changes:

- Full compatibility with Deneb Ethereum hard fork
- Added new EIPs introduced in Deneb. (`EIP-4788`, `EIP-4844`,
`EIP-7044`, `EIP-7045`, `EIP-7514`)
- Tests integration

---------

Co-authored-by: Giulio <giulio.rebuffo@gmail.com>
This commit is contained in:
Bayram Guvanjov 2024-01-12 22:20:26 +09:00 committed by GitHub
parent 574ec8089d
commit a191296f05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 66 additions and 36 deletions

View File

@ -40,6 +40,7 @@ type BeaconStateExtension interface {
ValidatorIndexByPubkey(key [48]byte) (uint64, bool) ValidatorIndexByPubkey(key [48]byte) (uint64, bool)
PreviousStateRoot() common.Hash PreviousStateRoot() common.Hash
SetPreviousStateRoot(root common.Hash) SetPreviousStateRoot(root common.Hash)
GetValidatorActivationChurnLimit() uint64
} }
type BeaconStateBasic interface { type BeaconStateBasic interface {

View File

@ -308,20 +308,21 @@ type BeaconChainConfig struct {
JustificationBitsLength uint64 `yaml:"JUSTIFICATION_BITS_LENGTH"` // JustificationBitsLength defines number of epochs to track when implementing k-finality in Casper FFG. JustificationBitsLength uint64 `yaml:"JUSTIFICATION_BITS_LENGTH"` // JustificationBitsLength defines number of epochs to track when implementing k-finality in Casper FFG.
// Misc constants. // Misc constants.
PresetBase string `yaml:"PRESET_BASE" spec:"true"` // PresetBase represents the underlying spec preset this config is based on. PresetBase string `yaml:"PRESET_BASE" spec:"true"` // PresetBase represents the underlying spec preset this config is based on.
ConfigName string `yaml:"CONFIG_NAME" spec:"true"` // ConfigName for allowing an easy human-readable way of knowing what chain is being used. ConfigName string `yaml:"CONFIG_NAME" spec:"true"` // ConfigName for allowing an easy human-readable way of knowing what chain is being used.
TargetCommitteeSize uint64 `yaml:"TARGET_COMMITTEE_SIZE" spec:"true"` // TargetCommitteeSize is the number of validators in a committee when the chain is healthy. TargetCommitteeSize uint64 `yaml:"TARGET_COMMITTEE_SIZE" spec:"true"` // TargetCommitteeSize is the number of validators in a committee when the chain is healthy.
MaxValidatorsPerCommittee uint64 `yaml:"MAX_VALIDATORS_PER_COMMITTEE" spec:"true"` // MaxValidatorsPerCommittee defines the upper bound of the size of a committee. MaxValidatorsPerCommittee uint64 `yaml:"MAX_VALIDATORS_PER_COMMITTEE" spec:"true"` // MaxValidatorsPerCommittee defines the upper bound of the size of a committee.
MaxCommitteesPerSlot uint64 `yaml:"MAX_COMMITTEES_PER_SLOT" spec:"true"` // MaxCommitteesPerSlot defines the max amount of committee in a single slot. MaxCommitteesPerSlot uint64 `yaml:"MAX_COMMITTEES_PER_SLOT" spec:"true"` // MaxCommitteesPerSlot defines the max amount of committee in a single slot.
MinPerEpochChurnLimit uint64 `yaml:"MIN_PER_EPOCH_CHURN_LIMIT" spec:"true"` // MinPerEpochChurnLimit is the minimum amount of churn allotted for validator rotations. MinPerEpochChurnLimit uint64 `yaml:"MIN_PER_EPOCH_CHURN_LIMIT" spec:"true"` // MinPerEpochChurnLimit is the minimum amount of churn allotted for validator rotations.
ChurnLimitQuotient uint64 `yaml:"CHURN_LIMIT_QUOTIENT" spec:"true"` // ChurnLimitQuotient is used to determine the limit of how many validators can rotate per epoch. ChurnLimitQuotient uint64 `yaml:"CHURN_LIMIT_QUOTIENT" spec:"true"` // ChurnLimitQuotient is used to determine the limit of how many validators can rotate per epoch.
ShuffleRoundCount uint64 `yaml:"SHUFFLE_ROUND_COUNT" spec:"true"` // ShuffleRoundCount is used for retrieving the permuted index. MaxPerEpochActivationChurnLimit uint64 `yaml:"MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT" spec:"true"` // MaxPerEpochActivationChurnLimit defines the maximum amount of churn allowed in one epoch from deneb.
MinGenesisActiveValidatorCount uint64 `yaml:"MIN_GENESIS_ACTIVE_VALIDATOR_COUNT" spec:"true"` // MinGenesisActiveValidatorCount defines how many validator deposits needed to kick off beacon chain. ShuffleRoundCount uint64 `yaml:"SHUFFLE_ROUND_COUNT" spec:"true"` // ShuffleRoundCount is used for retrieving the permuted index.
MinGenesisTime uint64 `yaml:"MIN_GENESIS_TIME" spec:"true"` // MinGenesisTime is the time that needed to pass before kicking off beacon chain. MinGenesisActiveValidatorCount uint64 `yaml:"MIN_GENESIS_ACTIVE_VALIDATOR_COUNT" spec:"true"` // MinGenesisActiveValidatorCount defines how many validator deposits needed to kick off beacon chain.
TargetAggregatorsPerCommittee uint64 `yaml:"TARGET_AGGREGATORS_PER_COMMITTEE" spec:"true"` // TargetAggregatorsPerCommittee defines the number of aggregators inside one committee. MinGenesisTime uint64 `yaml:"MIN_GENESIS_TIME" spec:"true"` // MinGenesisTime is the time that needed to pass before kicking off beacon chain.
HysteresisQuotient uint64 `yaml:"HYSTERESIS_QUOTIENT" spec:"true"` // HysteresisQuotient defines the hysteresis quotient for effective balance calculations. TargetAggregatorsPerCommittee uint64 `yaml:"TARGET_AGGREGATORS_PER_COMMITTEE" spec:"true"` // TargetAggregatorsPerCommittee defines the number of aggregators inside one committee.
HysteresisDownwardMultiplier uint64 `yaml:"HYSTERESIS_DOWNWARD_MULTIPLIER" spec:"true"` // HysteresisDownwardMultiplier defines the hysteresis downward multiplier for effective balance calculations. HysteresisQuotient uint64 `yaml:"HYSTERESIS_QUOTIENT" spec:"true"` // HysteresisQuotient defines the hysteresis quotient for effective balance calculations.
HysteresisUpwardMultiplier uint64 `yaml:"HYSTERESIS_UPWARD_MULTIPLIER" spec:"true"` // HysteresisUpwardMultiplier defines the hysteresis upward multiplier for effective balance calculations. HysteresisDownwardMultiplier uint64 `yaml:"HYSTERESIS_DOWNWARD_MULTIPLIER" spec:"true"` // HysteresisDownwardMultiplier defines the hysteresis downward multiplier for effective balance calculations.
HysteresisUpwardMultiplier uint64 `yaml:"HYSTERESIS_UPWARD_MULTIPLIER" spec:"true"` // HysteresisUpwardMultiplier defines the hysteresis upward multiplier for effective balance calculations.
// Gwei value constants. // Gwei value constants.
MinDepositAmount uint64 `yaml:"MIN_DEPOSIT_AMOUNT" spec:"true"` // MinDepositAmount is the minimum amount of Gwei a validator can send to the deposit contract at once (lower amounts will be reverted). MinDepositAmount uint64 `yaml:"MIN_DEPOSIT_AMOUNT" spec:"true"` // MinDepositAmount is the minimum amount of Gwei a validator can send to the deposit contract at once (lower amounts will be reverted).
@ -573,18 +574,19 @@ var MainnetBeaconConfig BeaconChainConfig = BeaconChainConfig{
GenesisDelay: 604800, // 1 week. GenesisDelay: 604800, // 1 week.
// Misc constant. // Misc constant.
TargetCommitteeSize: 128, TargetCommitteeSize: 128,
MaxValidatorsPerCommittee: 2048, MaxValidatorsPerCommittee: 2048,
MaxCommitteesPerSlot: 64, MaxCommitteesPerSlot: 64,
MinPerEpochChurnLimit: 4, MinPerEpochChurnLimit: 4,
ChurnLimitQuotient: 1 << 16, ChurnLimitQuotient: 1 << 16,
ShuffleRoundCount: 90, MaxPerEpochActivationChurnLimit: 8,
MinGenesisActiveValidatorCount: 16384, ShuffleRoundCount: 90,
MinGenesisTime: 1606824000, // Dec 1, 2020, 12pm UTC. MinGenesisActiveValidatorCount: 16384,
TargetAggregatorsPerCommittee: 16, MinGenesisTime: 1606824000, // Dec 1, 2020, 12pm UTC.
HysteresisQuotient: 4, TargetAggregatorsPerCommittee: 16,
HysteresisDownwardMultiplier: 1, HysteresisQuotient: 4,
HysteresisUpwardMultiplier: 5, HysteresisDownwardMultiplier: 1,
HysteresisUpwardMultiplier: 5,
// Gwei value constants. // Gwei value constants.
MinDepositAmount: 1 * 1e9, MinDepositAmount: 1 * 1e9,

View File

@ -57,7 +57,7 @@ func (e *Eth1Header) Capella() {
e.WithdrawalsRoot = libcommon.Hash{} e.WithdrawalsRoot = libcommon.Hash{}
} }
// Capella converts the header to capella version. // Deneb converts the header to deneb version.
func (e *Eth1Header) Deneb() { func (e *Eth1Header) Deneb() {
e.version = clparams.DenebVersion e.version = clparams.DenebVersion
e.BlobGasUsed = 0 e.BlobGasUsed = 0

View File

@ -171,7 +171,10 @@ func (b *CachingBeaconState) GetAttestationParticipationFlagIndicies(data solid.
if inclusionDelay <= utils.IntegerSquareRoot(b.BeaconConfig().SlotsPerEpoch) { if inclusionDelay <= utils.IntegerSquareRoot(b.BeaconConfig().SlotsPerEpoch) {
participationFlagIndicies = append(participationFlagIndicies, b.BeaconConfig().TimelySourceFlagIndex) participationFlagIndicies = append(participationFlagIndicies, b.BeaconConfig().TimelySourceFlagIndex)
} }
if matchingTarget && inclusionDelay <= b.BeaconConfig().SlotsPerEpoch { if b.Version() < clparams.DenebVersion && matchingTarget && inclusionDelay <= b.BeaconConfig().SlotsPerEpoch {
participationFlagIndicies = append(participationFlagIndicies, b.BeaconConfig().TimelyTargetFlagIndex)
}
if b.Version() >= clparams.DenebVersion && matchingTarget {
participationFlagIndicies = append(participationFlagIndicies, b.BeaconConfig().TimelyTargetFlagIndex) participationFlagIndicies = append(participationFlagIndicies, b.BeaconConfig().TimelyTargetFlagIndex)
} }
if matchingHead && inclusionDelay == b.BeaconConfig().MinAttestationInclusionDelay { if matchingHead && inclusionDelay == b.BeaconConfig().MinAttestationInclusionDelay {
@ -295,3 +298,11 @@ func (b *CachingBeaconState) GetValidatorChurnLimit() uint64 {
activeIndsCount := uint64(len(b.GetActiveValidatorsIndices(Epoch(b)))) activeIndsCount := uint64(len(b.GetActiveValidatorsIndices(Epoch(b))))
return utils.Max64(activeIndsCount/b.BeaconConfig().ChurnLimitQuotient, b.BeaconConfig().MinPerEpochChurnLimit) return utils.Max64(activeIndsCount/b.BeaconConfig().ChurnLimitQuotient, b.BeaconConfig().MinPerEpochChurnLimit)
} }
// https://github.com/ethereum/consensus-specs/blob/dev/specs/deneb/beacon-chain.md#new-get_validator_activation_churn_limit
func (b *CachingBeaconState) GetValidatorActivationChurnLimit() uint64 {
if b.Version() >= clparams.DenebVersion {
return utils.Min64(b.BeaconConfig().MaxPerEpochActivationChurnLimit, b.GetValidatorChurnLimit())
}
return b.GetValidatorChurnLimit()
}

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"github.com/Giulio2002/bls" "github.com/Giulio2002/bls"
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/cltypes"
"github.com/ledgerwatch/erigon/cl/fork" "github.com/ledgerwatch/erigon/cl/fork"
"github.com/ledgerwatch/erigon/cl/phase1/core/state" "github.com/ledgerwatch/erigon/cl/phase1/core/state"
@ -49,10 +50,18 @@ func (f *ForkChoiceStore) OnVoluntaryExit(signedVoluntaryExit *cltypes.SignedVol
pk := val.PublicKey() pk := val.PublicKey()
f.mu.Unlock() f.mu.Unlock()
domain, err := s.GetDomain(s.BeaconConfig().DomainVoluntaryExit, voluntaryExit.Epoch) domainType := f.beaconCfg.DomainVoluntaryExit
var domain []byte
if s.Version() < clparams.DenebVersion {
domain, err = s.GetDomain(domainType, voluntaryExit.Epoch)
} else if s.Version() >= clparams.DenebVersion {
domain, err = fork.ComputeDomain(domainType[:], utils.Uint32ToBytes4(s.BeaconConfig().CapellaForkVersion), s.GenesisValidatorsRoot())
}
if err != nil { if err != nil {
return err return err
} }
signingRoot, err := fork.ComputeSigningRoot(voluntaryExit, domain) signingRoot, err := fork.ComputeSigningRoot(voluntaryExit, domain)
if err != nil { if err != nil {
return err return err

View File

@ -3,15 +3,14 @@
tests: tests:
GIT_LFS_SKIP_SMUDGE=1 git clone https://github.com/ethereum/consensus-spec-tests GIT_LFS_SKIP_SMUDGE=1 git clone https://github.com/ethereum/consensus-spec-tests
cd consensus-spec-tests && git checkout 99549a414c10baa9e69abcb08eb256fc1a8d54f6 && git lfs pull --exclude=tests/general,tests/minimal && cd .. cd consensus-spec-tests && git checkout 080c96fbbf3be58e75947debfeb9ba3b2b7c9748 && git lfs pull --exclude=tests/general,tests/minimal && cd ..
mv consensus-spec-tests/tests . mv consensus-spec-tests/tests .
rm -rf consensus-spec-tests rm -rf consensus-spec-tests
rm -rf tests/minimal rm -rf tests/minimal
# not needed for now # not needed for now
rm -rf tests/mainnet/eip6110 rm -rf tests/mainnet/eip6110
# will not implement until i see it on a testnet # FIXME: Add fork choice coverage for deneb
rm -rf tests/mainnet/deneb rm -rf tests/mainnet/deneb/fork_choice
clean: clean:
rm -rf tests rm -rf tests

View File

@ -217,7 +217,12 @@ func (I *impl) ProcessVoluntaryExit(s abstract.BeaconState, signedVoluntaryExit
// We can skip it in some instances if we want to optimistically sync up. // We can skip it in some instances if we want to optimistically sync up.
if I.FullValidation { if I.FullValidation {
domain, err := s.GetDomain(s.BeaconConfig().DomainVoluntaryExit, voluntaryExit.Epoch) var domain []byte
if s.Version() < clparams.DenebVersion {
domain, err = s.GetDomain(s.BeaconConfig().DomainVoluntaryExit, voluntaryExit.Epoch)
} else if s.Version() >= clparams.DenebVersion {
domain, err = fork.ComputeDomain(s.BeaconConfig().DomainVoluntaryExit[:], utils.Uint32ToBytes4(s.BeaconConfig().CapellaForkVersion), s.GenesisValidatorsRoot())
}
if err != nil { if err != nil {
return err return err
} }
@ -697,7 +702,10 @@ func (I *impl) processAttestation(s abstract.BeaconState, attestation *solid.Att
if (data.Target().Epoch() != currentEpoch && data.Target().Epoch() != previousEpoch) || data.Target().Epoch() != state.GetEpochAtSlot(s.BeaconConfig(), data.Slot()) { if (data.Target().Epoch() != currentEpoch && data.Target().Epoch() != previousEpoch) || data.Target().Epoch() != state.GetEpochAtSlot(s.BeaconConfig(), data.Slot()) {
return nil, errors.New("ProcessAttestation: attestation with invalid epoch") return nil, errors.New("ProcessAttestation: attestation with invalid epoch")
} }
if data.Slot()+beaconConfig.MinAttestationInclusionDelay > stateSlot || stateSlot > data.Slot()+beaconConfig.SlotsPerEpoch { if s.Version() < clparams.DenebVersion && ((data.Slot()+beaconConfig.MinAttestationInclusionDelay > stateSlot) || (stateSlot > data.Slot()+beaconConfig.SlotsPerEpoch)) {
return nil, errors.New("ProcessAttestation: attestation slot not in range")
}
if s.Version() >= clparams.DenebVersion && data.Slot()+beaconConfig.MinAttestationInclusionDelay > stateSlot {
return nil, errors.New("ProcessAttestation: attestation slot not in range") return nil, errors.New("ProcessAttestation: attestation slot not in range")
} }
if data.ValidatorIndex() >= s.CommitteeCount(data.Target().Epoch()) { if data.ValidatorIndex() >= s.CommitteeCount(data.Target().Epoch()) {

View File

@ -62,7 +62,7 @@ func ProcessRegistryUpdates(s abstract.BeaconState) error {
} }
return activationQueue[i].validatorIndex < activationQueue[j].validatorIndex return activationQueue[i].validatorIndex < activationQueue[j].validatorIndex
}) })
activationQueueLength := s.GetValidatorChurnLimit() activationQueueLength := s.GetValidatorActivationChurnLimit()
if len(activationQueue) > int(activationQueueLength) { if len(activationQueue) > int(activationQueueLength) {
activationQueue = activationQueue[:activationQueueLength] activationQueue = activationQueue[:activationQueueLength]
} }