Skip to content
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

feat(txpool): reject s/c deploy (flag) #1000

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ Sequencer specific config:
- `zkevm.executor-urls`: A csv list of the executor URLs. These will be used in a round robbin fashion by the sequencer
- `zkevm.executor-strict`: Defaulted to true, but can be set to false when running the sequencer without verifications (use with extreme caution)
- `zkevm.witness-full`: Defaulted to true. Controls whether the full or partial witness is used with the executor.
- `zkevm.reject-smart-contract-deployments`: Defaulted to false. Controls whether smart contract deployments are rejected by the TxPool.

Resource Utilisation config:
- `zkevm.smt-regenerate-in-memory`: As documented above, allows SMT regeneration in memory if machine has enough RAM, for a speedup in initial sync.
Expand Down
10 changes: 10 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ var (
Usage: "First block to start syncing from on the L1",
Value: 0,
}
L1ContractAddressCheckFlag = cli.BoolFlag{
mandrigin marked this conversation as resolved.
Show resolved Hide resolved
Name: "zkevm.l1-contract-address-check",
Usage: "Check the contract address on the L1",
Value: true,
}
RebuildTreeAfterFlag = cli.Uint64Flag{
Name: "zkevm.rebuild-tree-after",
Usage: "Rebuild the state tree after this many blocks behind",
Expand Down Expand Up @@ -627,6 +632,11 @@ var (
Usage: "The URL of the pool manager. If set, eth_sendRawTransaction will be redirected there.",
Value: "",
}
TxPoolRejectSmartContractDeployments = cli.BoolFlag{
Name: "zkevm.reject-smart-contract-deployments",
Usage: "Reject smart contract deployments",
Value: false,
}
DisableVirtualCounters = cli.BoolFlag{
Name: "zkevm.disable-virtual-counters",
Usage: "Disable the virtual counters. This has an effect on on sequencer node and when external executor is not enabled.",
Expand Down
16 changes: 10 additions & 6 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ import (
zkStages "github.com/ledgerwatch/erigon/zk/stages"
"github.com/ledgerwatch/erigon/zk/syncer"
txpool2 "github.com/ledgerwatch/erigon/zk/txpool"
"github.com/ledgerwatch/erigon/zk/utils"
"github.com/ledgerwatch/erigon/zk/witness"
"github.com/ledgerwatch/erigon/zkevm/etherman"
"github.com/ledgerwatch/erigon/zk/utils"
)

// Config contains the configuration options of the ETH protocol.
Expand Down Expand Up @@ -850,12 +850,16 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
)

// check contract addresses in config against L1
success, err := l1ContractAddressCheck(ctx, cfg.Zk, backend.l1Syncer)
if !success || err != nil {
//log.Warn("Contract address check failed", "success", success, "err", err)
panic("Contract address check failed")
if cfg.Zk.L1ContractAddressCheck {
success, err := l1ContractAddressCheck(ctx, cfg.Zk, backend.l1Syncer)
if !success || err != nil {
//log.Warn("Contract address check failed", "success", success, "err", err)
panic("Contract address check failed")
}
log.Info("Contract address check passed")
} else {
log.Info("Contract address check skipped")
}
log.Info("Contract address check passed")

l1InfoTreeSyncer := syncer.NewL1Syncer(
ctx,
Expand Down
3 changes: 3 additions & 0 deletions eth/ethconfig/config_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Zk struct {
AddressRollup common.Address
AddressZkevm common.Address
AddressGerManager common.Address
L1ContractAddressCheck bool
L1RollupId uint64
L1BlockRange uint64
L1QueryDelay uint64
Expand Down Expand Up @@ -76,6 +77,8 @@ type Zk struct {
DisableVirtualCounters bool
VirtualCountersSmtReduction float64
ExecutorPayloadOutput string

TxPoolRejectSmartContractDeployments bool
}

var DefaultZkConfig = &Zk{}
Expand Down
2 changes: 2 additions & 0 deletions hermezconfig-dev.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ zkevm.data-stream-host: localhost
zkevm.executor-strict: true
zkevm.executor-urls: 51.210.116.237:50071

zkevm.l1-contract-address-check: false

externalcl: true
http.api: [eth, debug, net, trace, web3, erigon, txpool, zkevm]
http.addr: 0.0.0.0
Expand Down
2 changes: 2 additions & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ var DefaultFlags = []cli.Flag{
&utils.L1HighestBlockTypeFlag,
&utils.L1MaticContractAddressFlag,
&utils.L1FirstBlockFlag,
&utils.L1ContractAddressCheckFlag,
&utils.RpcRateLimitsFlag,
&utils.RpcGetBatchWitnessConcurrencyLimitFlag,
&utils.DatastreamVersionFlag,
Expand Down Expand Up @@ -227,6 +228,7 @@ var DefaultFlags = []cli.Flag{
&utils.DebugStep,
&utils.DebugStepAfter,
&utils.PoolManagerUrl,
&utils.TxPoolRejectSmartContractDeployments,
&utils.DisableVirtualCounters,
&utils.DAUrl,
&utils.VirtualCountersSmtReduction,
Expand Down
4 changes: 4 additions & 0 deletions turbo/cli/flags_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
L1HighestBlockType: ctx.String(utils.L1HighestBlockTypeFlag.Name),
L1MaticContractAddress: libcommon.HexToAddress(ctx.String(utils.L1MaticContractAddressFlag.Name)),
L1FirstBlock: ctx.Uint64(utils.L1FirstBlockFlag.Name),
L1ContractAddressCheck: ctx.Bool(utils.L1ContractAddressCheckFlag.Name),
RpcRateLimits: ctx.Int(utils.RpcRateLimitsFlag.Name),
RpcGetBatchWitnessConcurrencyLimit: ctx.Int(utils.RpcGetBatchWitnessConcurrencyLimitFlag.Name),
DatastreamVersion: ctx.Int(utils.DatastreamVersionFlag.Name),
Expand Down Expand Up @@ -158,6 +159,7 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
DebugStep: ctx.Uint64(utils.DebugStep.Name),
DebugStepAfter: ctx.Uint64(utils.DebugStepAfter.Name),
PoolManagerUrl: ctx.String(utils.PoolManagerUrl.Name),
TxPoolRejectSmartContractDeployments: ctx.Bool(utils.TxPoolRejectSmartContractDeployments.Name),
DisableVirtualCounters: ctx.Bool(utils.DisableVirtualCounters.Name),
ExecutorPayloadOutput: ctx.String(utils.ExecutorPayloadOutput.Name),
DAUrl: ctx.String(utils.DAUrl.Name),
Expand Down Expand Up @@ -214,4 +216,6 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
checkFlag(utils.RebuildTreeAfterFlag.Name, cfg.RebuildTreeAfter)
checkFlag(utils.L1BlockRangeFlag.Name, cfg.L1BlockRange)
checkFlag(utils.L1QueryDelayFlag.Name, cfg.L1QueryDelay)
checkFlag(utils.TxPoolRejectSmartContractDeployments.Name, cfg.TxPoolRejectSmartContractDeployments)
checkFlag(utils.L1ContractAddressCheckFlag.Name, cfg.L1ContractAddressCheck)
}
65 changes: 37 additions & 28 deletions zk/txpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,34 +117,35 @@ const (
type DiscardReason uint8

const (
NotSet DiscardReason = 0 // analog of "nil-value", means it will be set in future
Success DiscardReason = 1
AlreadyKnown DiscardReason = 2
Mined DiscardReason = 3
ReplacedByHigherTip DiscardReason = 4
UnderPriced DiscardReason = 5
ReplaceUnderpriced DiscardReason = 6 // if a transaction is attempted to be replaced with a different one without the required price bump.
FeeTooLow DiscardReason = 7
OversizedData DiscardReason = 8
InvalidSender DiscardReason = 9
NegativeValue DiscardReason = 10 // ensure no one is able to specify a transaction with a negative value.
Spammer DiscardReason = 11
PendingPoolOverflow DiscardReason = 12
BaseFeePoolOverflow DiscardReason = 13
QueuedPoolOverflow DiscardReason = 14
GasUintOverflow DiscardReason = 15
IntrinsicGas DiscardReason = 16
RLPTooLong DiscardReason = 17
NonceTooLow DiscardReason = 18
InsufficientFunds DiscardReason = 19
NotReplaced DiscardReason = 20 // There was an existing transaction with the same sender and nonce, not enough price bump to replace
DuplicateHash DiscardReason = 21 // There was an existing transaction with the same hash
InitCodeTooLarge DiscardReason = 22 // EIP-3860 - transaction init code is too large
UnsupportedTx DiscardReason = 23 // unsupported transaction type
OverflowZkCounters DiscardReason = 24 // unsupported transaction type
SenderDisallowedSendTx DiscardReason = 25 // sender is not allowed to send transactions by ACL policy
SenderDisallowedDeploy DiscardReason = 26 // sender is not allowed to deploy contracts by ACL policy
DiscardByLimbo DiscardReason = 27
NotSet DiscardReason = 0 // analog of "nil-value", means it will be set in future
Success DiscardReason = 1
AlreadyKnown DiscardReason = 2
Mined DiscardReason = 3
ReplacedByHigherTip DiscardReason = 4
UnderPriced DiscardReason = 5
ReplaceUnderpriced DiscardReason = 6 // if a transaction is attempted to be replaced with a different one without the required price bump.
FeeTooLow DiscardReason = 7
OversizedData DiscardReason = 8
InvalidSender DiscardReason = 9
NegativeValue DiscardReason = 10 // ensure no one is able to specify a transaction with a negative value.
Spammer DiscardReason = 11
PendingPoolOverflow DiscardReason = 12
BaseFeePoolOverflow DiscardReason = 13
QueuedPoolOverflow DiscardReason = 14
GasUintOverflow DiscardReason = 15
IntrinsicGas DiscardReason = 16
RLPTooLong DiscardReason = 17
NonceTooLow DiscardReason = 18
InsufficientFunds DiscardReason = 19
NotReplaced DiscardReason = 20 // There was an existing transaction with the same sender and nonce, not enough price bump to replace
DuplicateHash DiscardReason = 21 // There was an existing transaction with the same hash
InitCodeTooLarge DiscardReason = 22 // EIP-3860 - transaction init code is too large
UnsupportedTx DiscardReason = 23 // unsupported transaction type
OverflowZkCounters DiscardReason = 24 // unsupported transaction type
SenderDisallowedSendTx DiscardReason = 25 // sender is not allowed to send transactions by ACL policy
SenderDisallowedDeploy DiscardReason = 26 // sender is not allowed to deploy contracts by ACL policy
DiscardByLimbo DiscardReason = 27
SmartContractDeploymentDisabled DiscardReason = 28 // to == null not allowed, config set to block smart contract deployment
)

func (r DiscardReason) String() string {
Expand Down Expand Up @@ -205,6 +206,8 @@ func (r DiscardReason) String() string {
return "sender disallowed to deploy contract by ACL policy"
case DiscardByLimbo:
return "limbo error"
case SmartContractDeploymentDisabled:
return "smart contract deployment disabled"
default:
panic(fmt.Sprintf("discard reason: %d", r))
}
Expand Down Expand Up @@ -706,6 +709,12 @@ func (p *TxPool) validateTx(txn *types.TxSlot, isLocal bool, stateCache kvcache.
}
}

if p.ethCfg.Zk.TxPoolRejectSmartContractDeployments {
if txn.To == (common.Address{}) {
return SmartContractDeploymentDisabled
}
}

isLondon := p.isLondon()
if !isLondon && txn.Type == 0x2 {
return UnsupportedTx
Expand Down
Loading