Skip to content

Commit

Permalink
Merge branch 'bold-review' into gligneul/delay-buffer-bold
Browse files Browse the repository at this point in the history
  • Loading branch information
gligneul authored Nov 29, 2024
2 parents 5cffbc3 + 6a0754a commit f2bc708
Show file tree
Hide file tree
Showing 14 changed files with 428 additions and 44 deletions.
4 changes: 2 additions & 2 deletions arbitrator/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ pub unsafe extern "C" fn arbitrator_load_wavm_binary(binary_path: *const c_char)

#[no_mangle]
#[cfg(feature = "native")]
pub unsafe extern "C" fn arbitrator_new_finished() -> *mut Machine {
Box::into_raw(Box::new(Machine::new_finished()))
pub unsafe extern "C" fn arbitrator_new_finished(gs: GlobalState) -> *mut Machine {
Box::into_raw(Box::new(Machine::new_finished(gs)))
}

unsafe fn cstr_to_string(c_str: *const c_char) -> String {
Expand Down
7 changes: 2 additions & 5 deletions arbitrator/prover/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1569,14 +1569,11 @@ impl Machine {
//
// This allows the Mahine to be set up to model the final state of the
// machine at the end of the execution of a block.
//
// Callers should use set_global_state to set the global state of the
// machine to the global state at the end of the block.
pub fn new_finished() -> Machine {
pub fn new_finished(gs: GlobalState) -> Machine {
Machine {
steps: 0,
status: MachineStatus::Finished,
global_state: Default::default(),
global_state: gs,
// The machine is in the Finished state, so nothing else really matters.
// values_stacks and frame_stacks cannot be empty for proof serialization,
// but everything else can just be entirely blank.
Expand Down
1 change: 0 additions & 1 deletion arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ func createNodeImpl(
if dp != nil {
stakerAddr = dp.Sender()
}
log.Info("running as validator", "txSender", stakerAddr, "actingAsWallet", wallet.Address(), "strategy", config.Staker.Strategy)
}

var batchPoster *BatchPoster
Expand Down
2 changes: 1 addition & 1 deletion bold
6 changes: 6 additions & 0 deletions staker/bold/bold_staker.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ func (b *BOLDStaker) Initialize(ctx context.Context) error {
return err
}
walletAddressOrZero := b.wallet.AddressOrZero()
var stakerAddr common.Address
if b.wallet.DataPoster() != nil {
stakerAddr = b.wallet.DataPoster().Sender()
}
log.Info("running as validator", "txSender", stakerAddr, "actingAsWallet", walletAddressOrZero, "mode", b.config.Mode)

if b.blockValidator != nil && b.config.StartValidationFromStaked && !b.blockValidator.Started() {
rollupUserLogic, err := boldrollup.NewRollupUserLogic(b.rollupAddress, b.client)
if err != nil {
Expand Down
26 changes: 10 additions & 16 deletions staker/bold/bold_state_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,26 @@ func NewBOLDStateProvider(
}

// ExecutionStateAfterPreviousState Produces the L2 execution state for the next
// assertion. Returns the state at maxInboxCount or blockChallengeLeafHeight
// assertion. Returns the state at maxSeqInboxCount or blockChallengeLeafHeight
// after the previous state, whichever is earlier. If previousGlobalState is
// nil, defaults to returning the state at maxInboxCount.
// nil, defaults to returning the state at maxSeqInboxCount.
//
// TODO: Check the block validator has validated the execution state we are
// proposing.
func (s *BOLDStateProvider) ExecutionStateAfterPreviousState(
ctx context.Context,
maxInboxCount uint64,
maxSeqInboxCount uint64,
previousGlobalState protocol.GoGlobalState,
) (*protocol.ExecutionState, error) {
if maxInboxCount == 0 {
if maxSeqInboxCount == 0 {
return nil, errors.New("max inbox count cannot be zero")
}
batchIndex := maxInboxCount
batchIndex := maxSeqInboxCount
maxNumberOfBlocks := uint64(s.blockChallengeLeafHeight)
messageCount, err := s.statelessValidator.InboxTracker().GetBatchMessageCount(batchIndex - 1)
if err != nil {
if strings.Contains(err.Error(), "not found") {
return nil, fmt.Errorf("%w: batch count %d", l2stateprovider.ErrChainCatchingUp, maxInboxCount)
return nil, fmt.Errorf("%w: batch count %d", l2stateprovider.ErrChainCatchingUp, maxSeqInboxCount)
}
return nil, err
}
Expand All @@ -100,7 +100,7 @@ func (s *BOLDStateProvider) ExecutionStateAfterPreviousState(
previousMessageCount, err = s.statelessValidator.InboxTracker().GetBatchMessageCount(previousGlobalState.Batch - 1)
if err != nil {
if strings.Contains(err.Error(), "not found") {
return nil, fmt.Errorf("%w: batch count %d", l2stateprovider.ErrChainCatchingUp, maxInboxCount)
return nil, fmt.Errorf("%w: batch count %d", l2stateprovider.ErrChainCatchingUp, maxSeqInboxCount)
}
return nil, err
}
Expand All @@ -126,7 +126,7 @@ func (s *BOLDStateProvider) ExecutionStateAfterPreviousState(
return nil, err
}
if !stateValidatedAndMessageCountPastThreshold {
return nil, fmt.Errorf("%w: batch count %d", l2stateprovider.ErrChainCatchingUp, maxInboxCount)
return nil, fmt.Errorf("%w: batch count %d", l2stateprovider.ErrChainCatchingUp, maxSeqInboxCount)
}

executionState := &protocol.ExecutionState{
Expand Down Expand Up @@ -330,10 +330,7 @@ func (s *BOLDStateProvider) CollectMachineHashes(
return nil, err
}
if vs.IsSome() {
m := server_arb.NewFinishedMachine()
if err := m.SetGlobalState(vs.Unwrap()); err != nil {
return nil, err
}
m := server_arb.NewFinishedMachine(vs.Unwrap())
defer m.Destroy()
return []common.Hash{m.Hash()}, nil
}
Expand Down Expand Up @@ -508,10 +505,7 @@ func (s *BOLDStateProvider) CollectProof(
return nil, err
}
if vs.IsSome() {
m := server_arb.NewFinishedMachine()
if err := m.SetGlobalState(vs.Unwrap()); err != nil {
return nil, err
}
m := server_arb.NewFinishedMachine(vs.Unwrap())
defer m.Destroy()
return m.ProveNextStep(), nil
}
Expand Down
15 changes: 15 additions & 0 deletions staker/legacy/staker.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,21 @@ func (s *Staker) Initialize(ctx context.Context) error {
if walletAddressOrZero != (common.Address{}) {
s.updateStakerBalanceMetric(ctx)
}
var stakerAddr common.Address
if s.L1Validator.wallet.DataPoster() != nil {
stakerAddr = s.L1Validator.wallet.DataPoster().Sender()
}
whiteListed, err := s.isWhitelisted(ctx)
if err != nil {
return fmt.Errorf("error checking if whitelisted: %w", err)
}
log.Info(
"running as validator",
"txSender", stakerAddr,
"actingAsWallet", walletAddressOrZero,
"whitelisted", whiteListed,
"strategy", s.Strategy(),
)
if s.blockValidator != nil && s.config().StartValidationFromStaked {
latestStaked, _, err := s.validatorUtils.LatestStaked(&s.baseCallOpts, s.rollupAddress, walletAddressOrZero)
if err != nil {
Expand Down
17 changes: 15 additions & 2 deletions staker/multi_protocol/multi_protocol_staker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ import (
"github.com/offchainlabs/nitro/util/stopwaiter"
)

const boldArt = `
_______ __ _______
/ \ / | / \
$$$$$$$ | ______ $$ | $$$$$$$ |
$$ |__$$ | / \ $$ | $$ | $$ |
$$ $$< /$$$$$$ |$$ | $$ | $$ |
$$$$$$$ |$$ | $$ |$$ | $$ | $$ |
$$ |__$$ |$$ \__$$ |$$ |_____ $$ |__$$ |
$$ $$/ $$ $$/ $$ |$$ $$/
$$$$$$$/ $$$$$$/ $$$$$$$$/ $$$$$$$/
`

type MultiProtocolStaker struct {
stopwaiter.StopWaiter
bridge *bridgegen.IBridge
Expand Down Expand Up @@ -95,7 +107,8 @@ func (m *MultiProtocolStaker) Initialize(ctx context.Context) error {
return err
}
if boldActive {
log.Info("BOLD protocol is active, initializing BOLD staker")
log.Info("BoLD protocol is active, initializing BoLD staker")
log.Info(boldArt)
boldStaker, err := m.setupBoldStaker(ctx, rollupAddress)
if err != nil {
return err
Expand All @@ -104,7 +117,7 @@ func (m *MultiProtocolStaker) Initialize(ctx context.Context) error {
m.oldStaker = nil
return m.boldStaker.Initialize(ctx)
}
log.Info("BOLD protocol not detected on startup, using old staker until upgrade")
log.Info("BoLD protocol not detected on startup, using old staker until upgrade")
return m.oldStaker.Initialize(ctx)
}

Expand Down
39 changes: 33 additions & 6 deletions system_tests/bold_challenge_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,22 @@ func testChallengeProtocolBOLD(t *testing.T, spawnerOpts ...server_arb.SpawnerOp
ownerBal := big.NewInt(params.Ether)
ownerBal.Mul(ownerBal, big.NewInt(1_000_000))
l2info.GenerateGenesisAccount("Owner", ownerBal)
sconf := setup.RollupStackConfig{
UseMockBridge: false,
UseMockOneStepProver: false,
MinimumAssertionPeriod: 0,
}

_, l2nodeA, _, _, l1info, _, l1client, l1stack, assertionChain, stakeTokenAddr := createTestNodeOnL1ForBoldProtocol(t, ctx, true, nil, l2chainConfig, nil, l2info)
_, l2nodeA, _, _, l1info, _, l1client, l1stack, assertionChain, stakeTokenAddr := createTestNodeOnL1ForBoldProtocol(
t,
ctx,
true,
nil,
l2chainConfig,
nil,
sconf,
l2info,
)
defer requireClose(t, l1stack)
defer l2nodeA.StopAndWait()

Expand All @@ -109,7 +123,18 @@ func testChallengeProtocolBOLD(t *testing.T, spawnerOpts ...server_arb.SpawnerOp
go keepChainMoving(t, ctx, l1info, l1client)

l2nodeConfig := arbnode.ConfigDefaultL1Test()
_, l2nodeB, _ := create2ndNodeWithConfigForBoldProtocol(t, ctx, l2nodeA, l1stack, l1info, &l2info.ArbInitData, l2nodeConfig, nil, stakeTokenAddr)
_, l2nodeB, _ := create2ndNodeWithConfigForBoldProtocol(
t,
ctx,
l2nodeA,
l1stack,
l1info,
&l2info.ArbInitData,
l2nodeConfig,
nil,
sconf,
stakeTokenAddr,
)
defer l2nodeB.StopAndWait()

genesisA, err := l2nodeA.Execution.ResultAtPos(0)
Expand Down Expand Up @@ -494,6 +519,7 @@ func createTestNodeOnL1ForBoldProtocol(
nodeConfig *arbnode.Config,
chainConfig *params.ChainConfig,
_ *node.Config,
rollupStackConf setup.RollupStackConfig,
l2infoIn info,
) (
l2info info, currentNode *arbnode.Node, l2client *ethclient.Client, l2stack *node.Node,
Expand Down Expand Up @@ -554,7 +580,7 @@ func createTestNodeOnL1ForBoldProtocol(
Require(t, err)
l1TransactionOpts.Value = nil

addresses := deployContractsOnly(t, ctx, l1info, l1client, chainConfig.ChainID, stakeToken)
addresses := deployContractsOnly(t, ctx, l1info, l1client, chainConfig.ChainID, rollupStackConf, stakeToken)
rollupUser, err := rollupgen.NewRollupUserLogic(addresses.Rollup, l1client)
Require(t, err)
chalManagerAddr, err := rollupUser.ChallengeManager(&bind.CallOpts{})
Expand Down Expand Up @@ -635,6 +661,7 @@ func deployContractsOnly(
l1info info,
backend *ethclient.Client,
chainId *big.Int,
rollupStackConf setup.RollupStackConfig,
stakeToken common.Address,
) *chaininfo.RollupAddresses {
l1TransactionOpts := l1info.GetDefaultTransactOpts("RollupOwner", ctx)
Expand Down Expand Up @@ -679,8 +706,7 @@ func deployContractsOnly(
&l1TransactionOpts,
l1info.GetAddress("Sequencer"),
cfg,
false, // do not use mock bridge.
false, // do not use a mock one-step prover
rollupStackConf,
)
Require(t, err)

Expand Down Expand Up @@ -747,6 +773,7 @@ func create2ndNodeWithConfigForBoldProtocol(
l2InitData *statetransfer.ArbosInitializationInfo,
nodeConfig *arbnode.Config,
stackConfig *node.Config,
rollupStackConf setup.RollupStackConfig,
stakeTokenAddr common.Address,
) (*ethclient.Client, *arbnode.Node, *solimpl.AssertionChain) {
fatalErrChan := make(chan error, 10)
Expand All @@ -757,7 +784,7 @@ func create2ndNodeWithConfigForBoldProtocol(
Fatal(t, "not geth execution node")
}
chainConfig := firstExec.ArbInterface.BlockChain().Config()
addresses := deployContractsOnly(t, ctx, l1info, l1client, chainConfig.ChainID, stakeTokenAddr)
addresses := deployContractsOnly(t, ctx, l1info, l1client, chainConfig.ChainID, rollupStackConf, stakeTokenAddr)

l1info.SetContract("EvilBridge", addresses.Bridge)
l1info.SetContract("EvilSequencerInbox", addresses.SequencerInbox)
Expand Down
17 changes: 16 additions & 1 deletion system_tests/bold_state_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/offchainlabs/bold/solgen/go/mocksgen"
prefixproofs "github.com/offchainlabs/bold/state-commitments/prefix-proofs"
mockmanager "github.com/offchainlabs/bold/testing/mocks/state-provider"
"github.com/offchainlabs/bold/testing/setup"
)

func TestChallengeProtocolBOLD_Bisections(t *testing.T) {
Expand Down Expand Up @@ -354,8 +355,22 @@ func setupBoldStateProvider(t *testing.T, ctx context.Context, blockChallengeHei
ownerBal := big.NewInt(params.Ether)
ownerBal.Mul(ownerBal, big.NewInt(1_000_000))
l2info.GenerateGenesisAccount("Owner", ownerBal)
sconf := setup.RollupStackConfig{
UseMockBridge: false,
UseMockOneStepProver: false,
MinimumAssertionPeriod: 0,
}

_, l2node, _, _, l1info, _, l1client, l1stack, _, _ := createTestNodeOnL1ForBoldProtocol(t, ctx, false, nil, l2chainConfig, nil, l2info)
_, l2node, _, _, l1info, _, l1client, l1stack, _, _ := createTestNodeOnL1ForBoldProtocol(
t,
ctx,
false,
nil,
l2chainConfig,
nil,
sconf,
l2info,
)

valnode.TestValidationConfig.UseJit = false
_, valStack := createTestValidationNode(t, ctx, &valnode.TestValidationConfig)
Expand Down
7 changes: 5 additions & 2 deletions system_tests/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1368,8 +1368,11 @@ func deployOnParentChain(
&parentChainTransactionOpts,
parentChainInfo.GetAddress("Sequencer"),
cfg,
false, // do not use mock bridge.
false, // do not use a mock one-step prover
setup.RollupStackConfig{
UseMockBridge: false,
UseMockOneStepProver: false,
MinimumAssertionPeriod: 0,
},
)
Require(t, err)
addresses = &chaininfo.RollupAddresses{
Expand Down
Loading

0 comments on commit f2bc708

Please sign in to comment.