-
Notifications
You must be signed in to change notification settings - Fork 716
Add flag to disable ArbOwner outside on-chain execution #4591
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
base: master
Are you sure you want to change the base?
Changes from all commits
d626876
8f346ce
8503d01
dce1326
a12d4d6
d7f2e7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ### Configuration | ||
| - Add `--execution.disable-offchain-arbowner` flag to disable ArbOwner precompile calls outside on-chain execution |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,13 +10,22 @@ import ( | |
| "github.com/ethereum/go-ethereum/arbitrum/multigas" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/core" | ||
| "github.com/ethereum/go-ethereum/core/types" | ||
| "github.com/ethereum/go-ethereum/core/vm" | ||
| "github.com/ethereum/go-ethereum/log" | ||
|
|
||
| "github.com/offchainlabs/nitro/arbos" | ||
| "github.com/offchainlabs/nitro/precompiles" | ||
| ) | ||
|
|
||
| // arbOwnerPrecompile holds the *OwnerPrecompile retrieved from the precompile map during init(). | ||
| // ExecutionNode.Initialize() configures it later when the node config is available. | ||
| var arbOwnerPrecompile *precompiles.OwnerPrecompile | ||
|
|
||
| func GetOwnerPrecompile() *precompiles.OwnerPrecompile { | ||
| return arbOwnerPrecompile | ||
| } | ||
|
|
||
|
Comment on lines
+23
to
+28
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Precompile instances are created during
all the above were all strictly worse. The unexported var with an exported getter is the smallest surface: set exactly once in In more detail:
The gap: the instance is created in step 1, the config arrives in step 3, and there's no object that naturally carries the pointer from 1 to 3. Hence the global |
||
| type ArbosPrecompileWrapper struct { | ||
| inner precompiles.ArbosPrecompile | ||
| } | ||
|
|
@@ -59,7 +68,13 @@ func init() { | |
|
|
||
| // process arbos precompiles | ||
| precompileErrors := make(map[[4]byte]abi.Error) | ||
| for addr, precompile := range precompiles.Precompiles() { | ||
| arbosPrecompiles := precompiles.Precompiles() | ||
| if ownerPC, ok := arbosPrecompiles[types.ArbOwnerAddress].(*precompiles.OwnerPrecompile); ok { | ||
| arbOwnerPrecompile = ownerPC | ||
| } else { | ||
| log.Error("ArbOwner precompile is not an *OwnerPrecompile, disable-offchain-arbowner flag will not work") | ||
| } | ||
| for addr, precompile := range arbosPrecompiles { | ||
| for _, errABI := range precompile.Precompile().GetErrorABIs() { | ||
| precompileErrors[[4]byte(errABI.ID.Bytes())] = errABI | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import ( | |
| "github.com/ethereum/go-ethereum/log" | ||
| "github.com/ethereum/go-ethereum/params" | ||
|
|
||
| "github.com/offchainlabs/nitro/arbos" | ||
| "github.com/offchainlabs/nitro/arbos/arbosState" | ||
| "github.com/offchainlabs/nitro/arbos/util" | ||
| ) | ||
|
|
@@ -61,8 +62,9 @@ func (wrapper *DebugPrecompile) Name() string { | |
|
|
||
| // OwnerPrecompile is a precompile wrapper for those only chain owners may use | ||
| type OwnerPrecompile struct { | ||
| precompile ArbosPrecompile | ||
| emitSuccess func(mech, bytes4, addr, []byte) error | ||
| precompile ArbosPrecompile | ||
| emitSuccess func(mech, bytes4, addr, []byte) error | ||
| disableOffchain bool | ||
| } | ||
|
|
||
| func ownerOnly(address addr, impl ArbosPrecompile, emit func(mech, bytes4, addr, []byte) error) (addr, ArbosPrecompile) { | ||
|
|
@@ -72,6 +74,10 @@ func ownerOnly(address addr, impl ArbosPrecompile, emit func(mech, bytes4, addr, | |
| } | ||
| } | ||
|
|
||
| func (wrapper *OwnerPrecompile) SetDisableOffchain(disable bool) { | ||
| wrapper.disableOffchain = disable | ||
| } | ||
|
|
||
| func (wrapper *OwnerPrecompile) Address() common.Address { | ||
| return wrapper.precompile.Address() | ||
| } | ||
|
|
@@ -85,6 +91,13 @@ func (wrapper *OwnerPrecompile) Call( | |
| gasSupplied uint64, | ||
| evm *vm.EVM, | ||
| ) ([]byte, uint64, multigas.MultiGas, error) { | ||
| if wrapper.disableOffchain { | ||
| txProcessor, ok := evm.ProcessingHook.(*arbos.TxProcessor) | ||
| if !ok || !txProcessor.RunContext().IsExecutedOnChain() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The task mentions to use IsExecutedOnChain. If not possible then split this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. related to #4591 (comment) |
||
| return nil, gasSupplied, multigas.ZeroGas(), errors.New("ArbOwner precompile is disabled outside on-chain execution") | ||
| } | ||
| } | ||
|
|
||
| con := wrapper.precompile | ||
|
|
||
| burner := &Context{ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you check MessageRunContext, you are going to see that NonMutating happens to be the negation of ExecutedOnChain.
So using non mutating here can be more appropriate than using offchain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah and furthermore
IsNonMutating()and!IsExecutedOnChain()are equivalent:@joshuacolvin0 please advice if you had any other plans for
DisableOffchainArbOwneras usingIsNonMutatingseems to be doing exactly whatDisableOffchainArbOwner. If we went withIsNonMutatingthen the following check:would turn into something like: