-
Notifications
You must be signed in to change notification settings - Fork 726
add debug block injection to prefund devwallet #3697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
magicxyyz
wants to merge
75
commits into
master
Choose a base branch
from
debug-block
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 69 commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
d21b735
add draft of debug block
magicxyyz 55880e4
Merge branch 'master' into debug-block
magicxyyz dc79489
set chain config in debug block
magicxyyz 0fa4d20
cleanup sequencer config
magicxyyz 94f58b2
open arbosstate for writing chain config in debug block
magicxyyz b7583c5
use chainConfig.ArbitrumChainParams.DebugAddress in debug block
magicxyyz 9664d99
update geth pin
magicxyyz 28a48ba
Merge branch 'master' into debug-block
magicxyyz 0089af3
use build tag to guard debug block injection
magicxyyz f591e5a
add dangerous config for debugblock, guard impl with build tag
magicxyyz b6deb16
publish debug tx to trigger next block
magicxyyz 8f96031
update geth pin
magicxyyz f0d4fd9
Merge branch 'master' into debug-block
magicxyyz 45039a6
fix returning error from stubbed debugblock.ConfigAddOptions
magicxyyz c55d177
use hardcoded account to trigger debug block
magicxyyz 0e1dd84
add system test for debug block injection
magicxyyz 4352417
expand trigger account comment
magicxyyz 01a3e3c
test that debug block injection doesn't affect prod build
magicxyyz 7c10a57
rename debug block test file
magicxyyz e737880
fix challenge test build
magicxyyz 967954d
update geth pin
magicxyyz efdc491
Merge branch 'master' into debug-block
magicxyyz f1434ef
Merge branch 'master' into debug-block
magicxyyz 3fcbad7
add experimental tooling tests to ci workflow
magicxyyz 6d32415
execute only TestExperimental tests in experimental ci step
magicxyyz 6a4986c
add nitro-node-experimental to Dockerfile
magicxyyz 2668155
Merge branch 'master' into debug-block
magicxyyz a989d74
copy debugblock package into wasm-bin-builder
magicxyyz 4e34dce
Merge branch 'master' into debug-block
magicxyyz 229410c
Merge branch 'master' into debug-block
magicxyyz 009dbb1
use DebugAddress as pointer
magicxyyz 1d954f8
update geth pin
magicxyyz 1979462
add BenchSequencer
magicxyyz 373946d
add missing newline
magicxyyz d7d885a
Merge branch 'master' into debug-block
magicxyyz 1dbc550
add bench sequencer system tests
magicxyyz e53f1a4
Merge branch 'debug-block' into bench-sequencer
magicxyyz 1c6308a
remove unnecessery BenchSequencer.StopAndWait
magicxyyz ae315ef
remove unused config param from NewBenchSequencer
magicxyyz 547bad7
update geth pin
magicxyyz 15200f6
Merge branch 'master' into debug-block
magicxyyz 64466d8
update geth pin
magicxyyz faf8fc6
Merge branch 'master' into debug-block
magicxyyz d46410c
fix debug block test param
magicxyyz c7ff5df
fix missing chain config overwrite in common_test
magicxyyz 0dcd27f
Merge branch 'debug-block' into bench-sequencer
magicxyyz fca5848
apply lint format
magicxyyz e8ddbe5
update debug block tx warning message
magicxyyz c9a6fa5
add missing copyright comments
magicxyyz 3516227
fix challange test build
magicxyyz 0333e8a
Merge branch 'debug-block' into bench-sequencer
magicxyyz 341aca2
add benchseq rpc returning retry queue length
magicxyyz 67f607a
Merge pull request #3806 from OffchainLabs/bench-sequencer
joshuacolvin0 ec34f2e
update geth pin
magicxyyz c2f5f47
Merge branch 'master' into debug-block
magicxyyz 1bf903c
improve debug block accounts prefunding
magicxyyz 6a011ef
fix debug block prefund
magicxyyz ff84586
update geth pin
magicxyyz 528c9c7
Merge branch 'master' into debug-block
magicxyyz 6caeb5e
Merge branch 'master' into debug-block
magicxyyz 006e790
update pin
KolbyML 1e7bfa0
Merge remote-tracking branch 'origin/master' into debug-block
KolbyML c840a64
fix conflicts 1
KolbyML 0299c9f
revert broken submodules for git merge
KolbyML 82886ed
Merge remote-tracking branch 'origin/master' into debug-block
KolbyML 47870ac
fix code cov issue
KolbyML 2f6cf8a
Remove benchmark code from debug code
KolbyML 014c5b5
Merge remote-tracking branch 'origin/master' into debug-block
KolbyML 92d5666
Merge remote-tracking branch 'origin/master' into debug-block
KolbyML 6651500
try to resolve Gabriel concerns
KolbyML 1a76626
Merge branch 'master' into debug-block
KolbyML 4122fc5
fix debug-block build against pinned geth
KolbyML f279b48
fix debug-block build and restart test
KolbyML bd94b4f
pin merged geth debug-block and drop compat shims
KolbyML def158e
remove unrelated util test
KolbyML File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Copyright 2025, Offchain Labs, Inc. | ||
| // For license information, see https://github.com/offchainlabs/nitro/blob/master/LICENSE.md | ||
|
|
||
| // DANGER! this file is included in all builds | ||
|
magicxyyz marked this conversation as resolved.
|
||
| // DANGER! do not place any of the experimental logic and features here | ||
|
|
||
| package debugblock | ||
|
|
||
| type Config struct { | ||
| OverwriteChainConfig bool `koanf:"overwrite-chain-config"` | ||
| DebugAddress string `koanf:"debug-address"` | ||
| DebugBlockNum uint64 `koanf:"debug-blocknum"` | ||
| } | ||
|
|
||
| var ConfigDefault = Config{ | ||
| OverwriteChainConfig: false, | ||
| DebugAddress: "", | ||
| DebugBlockNum: 0, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // Copyright 2025, Offchain Labs, Inc. | ||
| // For license information, see https://github.com/offchainlabs/nitro/blob/master/LICENSE.md | ||
|
|
||
| //go:build debugblock | ||
|
|
||
| package debugblock | ||
|
|
||
| import ( | ||
| "crypto/ecdsa" | ||
| "encoding/json" | ||
| "errors" | ||
| "math/big" | ||
|
|
||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/core/state" | ||
| "github.com/ethereum/go-ethereum/core/tracing" | ||
| "github.com/ethereum/go-ethereum/core/types" | ||
| "github.com/ethereum/go-ethereum/crypto" | ||
| "github.com/ethereum/go-ethereum/log" | ||
| "github.com/ethereum/go-ethereum/params" | ||
| "github.com/holiman/uint256" | ||
| "github.com/offchainlabs/nitro/arbos/arbosState" | ||
| "github.com/offchainlabs/nitro/util" | ||
| "github.com/offchainlabs/nitro/util/arbmath" | ||
| "github.com/spf13/pflag" | ||
| ) | ||
|
|
||
| func ConfigAddOptions(prefix string, f *pflag.FlagSet) { | ||
| f.Bool(prefix+".overwrite-chain-config", ConfigDefault.OverwriteChainConfig, "DANGEROUS! overwrites chain when opening existing database; chain debug mode will be enabled") | ||
| f.String(prefix+".debug-address", ConfigDefault.DebugAddress, "DANGEROUS! address of debug account to be pre-funded") | ||
| f.Uint64(prefix+".debug-blocknum", ConfigDefault.DebugBlockNum, "DANGEROUS! block number of injected debug block") | ||
| } | ||
|
|
||
| func (c *Config) Validate() error { | ||
| if c.OverwriteChainConfig { | ||
| log.Warn("DANGER! overwrite-chain-config set, chain config will be over-written") | ||
| } | ||
| if c.DebugAddress != "" && !common.IsHexAddress(c.DebugAddress) { | ||
| return errors.New("invalid debug-address, hex address expected") | ||
| } | ||
| if c.DebugBlockNum != 0 { | ||
| log.Warn("DANGER! debug-blocknum set", "blocknum", c.DebugBlockNum) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (c *Config) Apply(chainConfig *params.ChainConfig) { | ||
| if c.OverwriteChainConfig { | ||
| chainConfig.ArbitrumChainParams.AllowDebugPrecompiles = true | ||
| chainConfig.ArbitrumChainParams.DebugBlock = c.DebugBlockNum | ||
| debugAddress := common.HexToAddress(c.DebugAddress) | ||
| chainConfig.ArbitrumChainParams.DebugAddress = &debugAddress | ||
| } | ||
| } | ||
|
|
||
| // private key and address of account to be used by PrepareDebugTransaction | ||
| func triggerPrivateKeyAndAddress() (*ecdsa.PrivateKey, common.Address, error) { | ||
| key, err := crypto.HexToECDSA("acb2d96fc54f5db4530d6c5a6adfd10964b1b62222d875e08b68b72cc9b9935c") | ||
| if err != nil { | ||
| return nil, common.Address{}, err | ||
| } | ||
| return key, crypto.PubkeyToAddress(key.PublicKey), nil | ||
| } | ||
|
|
||
| // prepares transaction used to trigger debug block creation | ||
| // the transaction needs pre-funding within DebugBlockStateUpdate (executed in the begging of debug block, before the trigger transaction) | ||
| func PrepareDebugTransaction(chainConfig *params.ChainConfig, lastHeader *types.Header) *types.Transaction { | ||
| if !chainConfig.DebugMode() { | ||
| return nil | ||
| } | ||
| privateKey, address, err := triggerPrivateKeyAndAddress() | ||
| if err != nil { | ||
| log.Error("debug block: failed to get hardcoded private key and address", "err", err) | ||
| return nil | ||
| } | ||
| transferGas := util.NormalizeL2GasForL1GasInitial(800_000, params.GWei) // include room for L1 costs | ||
| txData := &types.DynamicFeeTx{ | ||
| To: &address, | ||
| Gas: transferGas, | ||
| GasTipCap: big.NewInt(0), | ||
| GasFeeCap: big.NewInt(params.GWei), | ||
| Value: big.NewInt(0), | ||
| Nonce: 0, | ||
| Data: nil, | ||
| } | ||
| nextHeaderNumber := arbmath.BigAdd(lastHeader.Number, common.Big1) | ||
| arbosVersion := types.DeserializeHeaderExtraInformation(lastHeader).ArbOSFormatVersion | ||
| signer := types.MakeSigner(chainConfig, nextHeaderNumber, lastHeader.Time, arbosVersion) | ||
| tx := types.NewTx(txData) | ||
| tx, err = types.SignTx(tx, signer, privateKey) | ||
| if err != nil { | ||
| log.Error("debug block: failed to sign trigger tx", "address", address, "err", err) | ||
| return nil | ||
| } | ||
| return tx | ||
| } | ||
|
|
||
| func DebugBlockStateUpdate(statedb *state.StateDB, expectedBalanceDelta *big.Int, chainConfig *params.ChainConfig) { | ||
| // fund trigger account - used to send the transaction that triggered this block and needs pre-funding to succeed (at least one successful tx is required for the block to be appended to the chain) | ||
| transferGas := util.NormalizeL2GasForL1GasInitial(800_000, 100*params.GWei) // include room for L1 costs | ||
| triggerCost := uint256.MustFromBig(new(big.Int).Mul(big.NewInt(int64(transferGas)), big.NewInt(100*params.GWei))) | ||
| _, triggerAddress, err := triggerPrivateKeyAndAddress() | ||
| if err != nil { | ||
| log.Error("debug block: failed to get hardcoded address", "err", err) | ||
| return | ||
| } | ||
| statedb.AddBalance(triggerAddress, triggerCost, tracing.BalanceChangeUnspecified) | ||
| expectedBalanceDelta.Add(expectedBalanceDelta, triggerCost.ToBig()) | ||
|
|
||
| // fund debug account | ||
| if chainConfig.ArbitrumChainParams.DebugAddress != nil { | ||
| balance := uint256.MustFromBig(new(big.Int).Lsh(big.NewInt(1), 254)) | ||
| statedb.AddBalance(*chainConfig.ArbitrumChainParams.DebugAddress, balance, tracing.BalanceChangeUnspecified) | ||
| expectedBalanceDelta.Add(expectedBalanceDelta, balance.ToBig()) | ||
| log.Warn("DANGER! debug block: funding debug account", "debugAddress", chainConfig.ArbitrumChainParams.DebugAddress) | ||
| } | ||
|
|
||
| // save current chain config to arbos state in case it was changed to enable debug mode and debug block | ||
| // replay binary reads chain config from arbos state, that will enable successful validation of future blocks | ||
| // (debug block will still fail validation if chain config was changed off-chain) | ||
| if serializedChainConfig, err := json.Marshal(chainConfig); err != nil { | ||
| log.Error("debug block: failed to marshal chain config", "err", err) | ||
| } else if arbStateWrite, err := arbosState.OpenSystemArbosState(statedb, nil, false); err != nil { | ||
| log.Error("debug block: failed to open arbos state for writing", "err", err) | ||
| } else if err = arbStateWrite.SetChainConfig(serializedChainConfig); err != nil { | ||
| log.Error("debug block: failed to set chain config in arbos state", "err", err) | ||
| } | ||
| log.Warn("DANGER! debug block: state update applied") | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.