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)
PreviousStateRoot() common.Hash
SetPreviousStateRoot(root common.Hash)
GetValidatorActivationChurnLimit() uint64
}
type BeaconStateBasic interface {

View File

@ -315,6 +315,7 @@ type BeaconChainConfig struct {
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.
ChurnLimitQuotient uint64 `yaml:"CHURN_LIMIT_QUOTIENT" spec:"true"` // ChurnLimitQuotient is used to determine the limit of how many validators can rotate per epoch.
MaxPerEpochActivationChurnLimit uint64 `yaml:"MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT" spec:"true"` // MaxPerEpochActivationChurnLimit defines the maximum amount of churn allowed in one epoch from deneb.
ShuffleRoundCount uint64 `yaml:"SHUFFLE_ROUND_COUNT" spec:"true"` // ShuffleRoundCount is used for retrieving the permuted index.
MinGenesisActiveValidatorCount uint64 `yaml:"MIN_GENESIS_ACTIVE_VALIDATOR_COUNT" spec:"true"` // MinGenesisActiveValidatorCount defines how many validator deposits needed to kick off beacon chain.
MinGenesisTime uint64 `yaml:"MIN_GENESIS_TIME" spec:"true"` // MinGenesisTime is the time that needed to pass before kicking off beacon chain.
@ -578,6 +579,7 @@ var MainnetBeaconConfig BeaconChainConfig = BeaconChainConfig{
MaxCommitteesPerSlot: 64,
MinPerEpochChurnLimit: 4,
ChurnLimitQuotient: 1 << 16,
MaxPerEpochActivationChurnLimit: 8,
ShuffleRoundCount: 90,
MinGenesisActiveValidatorCount: 16384,
MinGenesisTime: 1606824000, // Dec 1, 2020, 12pm UTC.

View File

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

View File

@ -171,7 +171,10 @@ func (b *CachingBeaconState) GetAttestationParticipationFlagIndicies(data solid.
if inclusionDelay <= utils.IntegerSquareRoot(b.BeaconConfig().SlotsPerEpoch) {
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)
}
if matchingHead && inclusionDelay == b.BeaconConfig().MinAttestationInclusionDelay {
@ -295,3 +298,11 @@ func (b *CachingBeaconState) GetValidatorChurnLimit() uint64 {
activeIndsCount := uint64(len(b.GetActiveValidatorsIndices(Epoch(b))))
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"
"github.com/Giulio2002/bls"
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cl/cltypes"
"github.com/ledgerwatch/erigon/cl/fork"
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
@ -49,10 +50,18 @@ func (f *ForkChoiceStore) OnVoluntaryExit(signedVoluntaryExit *cltypes.SignedVol
pk := val.PublicKey()
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 {
return err
}
signingRoot, err := fork.ComputeSigningRoot(voluntaryExit, domain)
if err != nil {
return err

View File

@ -3,15 +3,14 @@
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 .
rm -rf consensus-spec-tests
rm -rf tests/minimal
# not needed for now
rm -rf tests/mainnet/eip6110
# will not implement until i see it on a testnet
rm -rf tests/mainnet/deneb
# FIXME: Add fork choice coverage for deneb
rm -rf tests/mainnet/deneb/fork_choice
clean:
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.
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 {
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()) {
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")
}
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
})
activationQueueLength := s.GetValidatorChurnLimit()
activationQueueLength := s.GetValidatorActivationChurnLimit()
if len(activationQueue) > int(activationQueueLength) {
activationQueue = activationQueue[:activationQueueLength]
}