Skip to content

Commit

Permalink
Boonet: fixed Bera token produced at Genesis (#2161)
Browse files Browse the repository at this point in the history
  • Loading branch information
calbera authored Nov 20, 2024
1 parent b23f942 commit cafd14e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
4 changes: 3 additions & 1 deletion mod/node-core/pkg/components/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func ProvideDispatcher[
dp.WithEvent[async.Event[ConsensusSidecars]](async.SidecarsReceived),
dp.WithEvent[async.Event[BeaconBlockT]](async.BeaconBlockVerified),
dp.WithEvent[async.Event[BlobSidecarsT]](async.SidecarsVerified),
dp.WithEvent[async.Event[ConsensusBlockT]](async.FinalBeaconBlockReceived),
dp.WithEvent[async.Event[ConsensusBlockT]](
async.FinalBeaconBlockReceived,
),
dp.WithEvent[async.Event[BlobSidecarsT]](async.FinalSidecarsReceived),
dp.WithEvent[ValidatorUpdateEvent](
async.FinalValidatorUpdatesProcessed,
Expand Down
27 changes: 26 additions & 1 deletion mod/state-transition/pkg/core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ import (
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
)

const (
// EVMMintingSlot is the slot at which we force a single withdrawal to
// mint EVMMintingAmount EVM tokens to EVMMintingAddress. No other
// withdrawals are inserted at this slot.
EVMMintingSlot uint64 = 69420

// EVMMintingAddress is the address at which we mint EVM tokens to.
EVMMintingAddress = "0x8a73D1380345942F1cb32541F1b19C40D8e6C94B"

// EVMMintingAmount is the amount of EVM tokens to mint.
EVMMintingAmount uint64 = 530000000000000000
)

// StateDB is the underlying struct behind the BeaconState interface.
//
//nolint:revive // todo fix somehow
Expand Down Expand Up @@ -187,7 +200,7 @@ func (s *StateDB[
// ExpectedWithdrawals as defined in the Ethereum 2.0 Specification:
// https://github.com/ethereum/consensus-specs/blob/dev/specs/capella/beacon-chain.md#new-get_expected_withdrawals
//
//nolint:lll
//nolint:lll,funlen
func (s *StateDB[
_, _, _, _, _, _, ValidatorT, _, WithdrawalT, _,
]) ExpectedWithdrawals() ([]WithdrawalT, error) {
Expand All @@ -203,6 +216,18 @@ func (s *StateDB[
return nil, err
}

// Slot used to mint EVM tokens.
if slot.Unwrap() == EVMMintingSlot {
var withdrawal WithdrawalT
withdrawals = append(withdrawals, withdrawal.New(
0, // NOT USED
0, // NOT USED
common.NewExecutionAddressFromHex(EVMMintingAddress),
math.Gwei(EVMMintingAmount),
))
return withdrawals, nil
}

epoch := math.Epoch(slot.Unwrap() / s.cs.SlotsPerEpoch())

withdrawalIndex, err := s.GetNextWithdrawalIndex()
Expand Down
2 changes: 1 addition & 1 deletion mod/state-transition/pkg/core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (sp *StateProcessor[
return err
}

if err := sp.processWithdrawals(st, blk.GetBody()); err != nil {
if err := sp.processWithdrawals(st, blk); err != nil {
return err
}

Expand Down
23 changes: 21 additions & 2 deletions mod/state-transition/pkg/core/state_processor_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
"github.com/berachain/beacon-kit/mod/primitives/pkg/version"
"github.com/berachain/beacon-kit/mod/state-transition/pkg/core/state"
"github.com/davecgh/go-spew/spew"
)

Expand Down Expand Up @@ -227,11 +228,13 @@ func (sp *StateProcessor[
//
//nolint:lll
func (sp *StateProcessor[
_, BeaconBlockBodyT, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _, _, _,
BeaconBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) processWithdrawals(
st BeaconStateT,
body BeaconBlockBodyT,
blk BeaconBlockT,
) error {
body := blk.GetBody()

// Dequeue and verify the logs.
var (
nextValidatorIndex math.ValidatorIndex
Expand All @@ -255,6 +258,22 @@ func (sp *StateProcessor[
)
}

// Slot used to mint EVM tokens.
slot := blk.GetSlot()
if slot.Unwrap() == state.EVMMintingSlot {
// Sanity check.
wd := expectedWithdrawals[0]
if !wd.Equals(payloadWithdrawals[0]) {
return fmt.Errorf(
"minting withdrawal does not match expected %s, got %s",
spew.Sdump(wd), spew.Sdump(payloadWithdrawals[0]),
)
}

// No processing needed.
return nil
}

// Compare and process each withdrawal.
for i, wd := range expectedWithdrawals {
// Ensure the withdrawals match the local state.
Expand Down

0 comments on commit cafd14e

Please sign in to comment.