Skip to content

Commit b461297

Browse files
authored
Merge branch 'main' into simulate-v1
2 parents 78dee23 + d21fd2b commit b461297

47 files changed

Lines changed: 476 additions & 787 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
-----BEGIN PGP PUBLIC KEY BLOCK-----
22

3-
mDMEaDb6PxYJKwYBBAHaRw8BAQdA7NN0qrz+Cx5UriSUojsPYXyJepimw7xvUovE
4-
IixEb9S0IGFiZWFyIChyaykgPGFiZWFyQGJlcmFjaGFpbi5jb20+iJkEExYKAEEW
5-
IQQf3314kw4MJOZjm/rg+kk9+5MtfAUCaDb6PwIbAwUJAE8aAAULCQgHAgIiAgYV
6-
CgkICwIEFgIDAQIeBwIXgAAKCRDg+kk9+5MtfOkAAP9OCSa3BqCCfGO7mI/VT3lB
7-
0PhZyybfb0HUK9qEmxfODgEA62CbwYctgI/vkm/oUO0MhEQCLXYUYOiJRurOtLhY
8-
9QO4OARoNvo/EgorBgEEAZdVAQUBAQdAK0aEIOzG8JjfiDZ3vRjHfgDWKTh1OiGW
9-
dCB1lnAG+iUDAQgHiH4EGBYKACYWIQQf3314kw4MJOZjm/rg+kk9+5MtfAUCaDb6
10-
PwIbDAUJAE8aAAAKCRDg+kk9+5MtfEnwAQCymHAHWt9LWAQdIggPPP6pMBuGD7Dr
11-
pkXMsTK+HaG/dAD/U561NglvR7K2NcLUTqS5dSb2ibGgSEO5hbhXR5/W/Qg=
12-
=X5VL
3+
mDMEaIky1hYJKwYBBAHaRw8BAQdAnxP3mNWC+miF0OKvOg4+BzzswbrTWLbluSJU
4+
+NBib3q0H2NhbGJlcmEgPGNhbGJlcmFAYmVyYWNoYWluLmNvbT6ImQQTFgoAQRYh
5+
BPzFjSePGuMIYGS4P/GUiPGD4kvxBQJoiTLWAhsDBQkAdqcABQsJCAcCAiICBhUK
6+
CQgLAgQWAgMBAh4HAheAAAoJEPGUiPGD4kvxA9oBANZQa+Q6UlhDPLOOhchdPSi7
7+
lmBE+za+5u5Q3bA7ZO8rAP46R+a1AxHqeLrShhkTvJwTG+qGvfS/LtHfNYLHqOQw
8+
Bbg4BGiJMtYSCisGAQQBl1UBBQEBB0A6onCspxjhXI7X13LHlUYQxYVyzUDamgVP
9+
hXYTLZ1QEAMBCAeIfgQYFgoAJhYhBPzFjSePGuMIYGS4P/GUiPGD4kvxBQJoiTLW
10+
AhsMBQkAdqcAAAoJEPGUiPGD4kvxWOAA/0IedfbPuCJU/IWo+gxCZMl9Fb7oVA4L
11+
v9lMBtnspGsxAQDRX3fFP/Bv96wHlUWQHg01TSaWNyTQa5dTpjEcLxnXCQ==
12+
=L8oL
1313
-----END PGP PUBLIC KEY BLOCK-----

CLAUDE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,6 @@ func ProvideBlockchainService(
732732

733733
### Build Tags
734734
- `bls12381` - BLS cryptography
735-
- `ckzg` - KZG blob commitments
736735
- `test` - Testing utilities
737736
- `e2e` - End-to-end tests
738737
- `simulated` - Simulation tests

cli/commands/initialize/initialize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func InitCmd(creator clitypes.ChainSpecCreator, mm interface {
215215
appGenesis.InitialHeight = initHeight
216216
appGenesis.Consensus = &types.ConsensusGenesis{
217217
Validators: nil,
218-
Params: cometbft.DefaultConsensusParams(consensusKeyAlgo),
218+
Params: cometbft.DefaultConsensusParams(consensusKeyAlgo, chainSpec),
219219
}
220220

221221
if err = genutil.ExportGenesisFile(appGenesis, genFile); err != nil {

config/spec/testnet.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
package spec
2222

2323
import (
24-
"math"
25-
2624
"github.com/berachain/beacon-kit/chain"
2725
)
2826

@@ -44,8 +42,12 @@ func TestnetChainSpecData() *chain.SpecData {
4442
// Timestamp of the Electra fork on Bepolia.
4543
specData.ElectraForkTime = 1746633600
4644

45+
// Enable stable block time before the Electra1 fork.
46+
specData.Config.ConsensusUpdateHeight = 7_768_334
47+
specData.Config.ConsensusEnableHeight = 7_768_335
48+
4749
// Timestamp of the Electra1 fork on Bepolia.
48-
specData.Electra1ForkTime = math.MaxInt64
50+
specData.Electra1ForkTime = 1754496000
4951

5052
return specData
5153
}

config/template/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ style = "{{.BeaconKit.Logger.Style}}"
6868
trusted-setup-path = "{{.BeaconKit.KZG.TrustedSetupPath}}"
6969
7070
# KZG implementation to use.
71-
# Options are "crate-crypto/go-kzg-4844" or "ethereum/c-kzg-4844".
71+
# Options are "crate-crypto/go-kzg-4844".
7272
implementation = "{{.BeaconKit.KZG.Implementation}}"
7373
7474
[beacon-kit.payload-builder]

consensus/cometbft/service/configs.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"fmt"
2727
"time"
2828

29+
"github.com/berachain/beacon-kit/chain"
2930
"github.com/berachain/beacon-kit/log"
3031
cmtcfg "github.com/cometbft/cometbft/config"
3132
cmttypes "github.com/cometbft/cometbft/types"
@@ -107,7 +108,7 @@ func DefaultConfig() *cmtcfg.Config {
107108
// DefaultConsensusParams returns the default consensus parameters
108109
// shared by every node in the network. Consensus parameters are
109110
// inscripted in genesis.
110-
func DefaultConsensusParams(consensusKeyAlgo string) *cmttypes.ConsensusParams {
111+
func DefaultConsensusParams(consensusKeyAlgo string, cs chain.Spec) *cmttypes.ConsensusParams {
111112
res := cmttypes.DefaultConsensusParams()
112113
res.Validator.PubKeyTypes = []string{consensusKeyAlgo}
113114

@@ -121,9 +122,7 @@ func DefaultConsensusParams(consensusKeyAlgo string) *cmttypes.ConsensusParams {
121122
res.Feature.PbtsEnableHeight = 1
122123
res.Synchrony.Precision = precision
123124
res.Synchrony.MessageDelay = messageDelay
124-
125-
// Activate Stable Block Time (SBT) by default.
126-
res.Feature.SBTEnableHeight = 1
125+
res.Feature.SBTEnableHeight = cs.SbtConsensusEnableHeight()
127126

128127
if err := res.ValidateBasic(); err != nil {
129128
panic(fmt.Errorf("invalid default consensus parameters: %w", err))
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
//
3+
// Copyright (C) 2025, Berachain Foundation. All rights reserved.
4+
// Use of this software is governed by the Business Source License included
5+
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
6+
//
7+
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
8+
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
9+
// VERSIONS OF THE LICENSED WORK.
10+
//
11+
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
12+
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
13+
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
14+
//
15+
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
16+
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
17+
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
18+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
19+
// TITLE.
20+
//
21+
22+
package cometbft_test
23+
24+
import (
25+
"testing"
26+
27+
"github.com/berachain/beacon-kit/chain"
28+
"github.com/berachain/beacon-kit/config/spec"
29+
cometbft "github.com/berachain/beacon-kit/consensus/cometbft/service"
30+
"github.com/berachain/beacon-kit/primitives/crypto"
31+
cmttypes "github.com/cometbft/cometbft/types"
32+
"github.com/stretchr/testify/require"
33+
)
34+
35+
func TestSBTEnableHeightAlignedWithChainSpecs(t *testing.T) {
36+
t.Parallel()
37+
38+
tests := []struct {
39+
name string
40+
getChainSpecs func(t *testing.T) chain.Spec
41+
}{
42+
{
43+
name: "mainnet",
44+
getChainSpecs: func(t *testing.T) chain.Spec {
45+
t.Helper()
46+
cs, err := spec.MainnetChainSpec()
47+
require.NoError(t, err)
48+
return cs
49+
},
50+
},
51+
{
52+
name: "testnet",
53+
getChainSpecs: func(t *testing.T) chain.Spec {
54+
t.Helper()
55+
cs, err := spec.TestnetChainSpec()
56+
require.NoError(t, err)
57+
return cs
58+
},
59+
},
60+
{
61+
name: "devnet",
62+
getChainSpecs: func(t *testing.T) chain.Spec {
63+
t.Helper()
64+
cs, err := spec.DevnetChainSpec()
65+
require.NoError(t, err)
66+
return cs
67+
},
68+
},
69+
}
70+
71+
for _, tt := range tests {
72+
t.Run(tt.name, func(t *testing.T) {
73+
t.Parallel()
74+
75+
cs := tt.getChainSpecs(t)
76+
77+
var cp *cmttypes.ConsensusParams
78+
require.NotPanics(t, func() {
79+
cp = cometbft.DefaultConsensusParams(crypto.CometBLSType, cs)
80+
})
81+
82+
// Make sure that the Enable Height in consensus parameters matches with
83+
// chain spec one. This is relevant to make sure that consensus parameters
84+
// are well set when chain spec is modified and genesis is regenerated.
85+
require.Equal(t, cp.Feature.SBTEnableHeight, cs.SbtConsensusEnableHeight())
86+
})
87+
}
88+
}

consensus/cometbft/service/service.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ func NewService(
156156
panic(fmt.Errorf("failed loading latest version: %w", err))
157157
}
158158

159+
// Make sure that SBT consensus parameters are duly set when the node restart.
160+
// Note that we can't rely on genesis.json having these parameters set right
161+
// because we introduced stable block time post (mainnet) genesis.
162+
lastBlockHeight := s.sm.GetCommitMultiStore().LastCommitID().Version
163+
if lastBlockHeight >= s.delayCfg.SbtConsensusUpdateHeight() {
164+
s.cmtConsensusParams.Feature.SBTEnableHeight = s.delayCfg.SbtConsensusEnableHeight()
165+
}
166+
159167
// Load block delay.
160168
//
161169
// If not found, we will initialize it in FinalizeBlock once SBTEnableHeight

contracts/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# BeaconKit Contracts
2+
3+
## Mock PoL Contracts
4+
5+
Mock Proof-of-Liquidity contracts for testing execution client integration.
6+
7+
### Usage
8+
9+
Generate bytecode for genesis deployment:
10+
11+
```bash
12+
# Build contracts
13+
forge build
14+
15+
# Extract SimplePoLDistributor bytecode
16+
cat out/MockPoL.sol/SimplePoLDistributor.json | jq -r .deployedBytecode.object
17+
18+
# Extract ValidatorRegistry bytecode
19+
cat out/MockValidatorRegistry.sol/ValidatorRegistry.json | jq -r .deployedBytecode.object
20+
```
21+
22+
The same pattern can be used to extract bytecode for other contracts in the
23+
`brip0004/` directory.
24+
25+
### Contracts
26+
27+
- `MockPoL.sol` - Basic PoL distributor with multi-contract state changes
28+
- `MockPoLReverting.sol` - PoL distributor that reverts after 10 distributions
29+
- `MockPoLGasEnforcer.sol` - Gas-constrained PoL distributor for gas limit testing
30+
- `MockValidatorRegistry.sol` - Registry contract for testing cross-contract calls

contracts/src/brip0004/MockPoL.sol

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.26;
3+
4+
import "./MockValidatorRegistry.sol";
5+
6+
/// @title SimplePoLDistributor
7+
/// @notice Mock PoL distributor for testing execution client integration
8+
/// @dev Interacts with ValidatorRegistry to test multi-contract state changes
9+
contract SimplePoLDistributor {
10+
/// @notice System address that can call distributeFor (execution layer client)
11+
address private constant SYSTEM_ADDRESS =
12+
0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE;
13+
14+
/// @notice The validator registry contract address (hardcoded for genesis deployment)
15+
ValidatorRegistry private constant VALIDATOR_REGISTRY =
16+
ValidatorRegistry(0x4200000000000000000000000000000000000043);
17+
18+
/// @notice Event emitted when distributeFor is called
19+
event PoLDistributed(bytes pubkey);
20+
21+
/// @notice Counter for total distributions
22+
uint256 public totalDistributions;
23+
24+
/// @notice Error thrown when caller is not the system address
25+
error NotSystemAddress();
26+
27+
/// @dev Restricts access to system address (execution layer client only)
28+
modifier onlySystemCall() {
29+
if (msg.sender != SYSTEM_ADDRESS) {
30+
revert NotSystemAddress();
31+
}
32+
_;
33+
}
34+
35+
/// @notice Main function called by execution client
36+
/// @param pubkey The validator public key
37+
/// @dev Calls ValidatorRegistry to test multi-contract state changes
38+
// slither-disable-next-line reentrancy-events
39+
function distributeFor(bytes calldata pubkey) external onlySystemCall {
40+
totalDistributions++;
41+
VALIDATOR_REGISTRY.recordValidatorActivity(pubkey);
42+
43+
emit PoLDistributed(pubkey);
44+
}
45+
}

0 commit comments

Comments
 (0)