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: Add Support for Zero Fee Addresses #53

Merged
merged 4 commits into from
Nov 25, 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
14 changes: 13 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,12 @@ var (
Category: flags.VMCategory,
}

ZeroFeeAddressesFlag = &cli.StringFlag{
Name: "zeroofeeaddresses",
Usage: "Comma separated list of addresses that are allowed to send transactions with zero fees",
Value: "",
Category: flags.VMCategory,
}
// API options.
RPCGlobalGasCapFlag = &cli.Uint64Flag{
Name: "rpc.gascap",
Expand Down Expand Up @@ -2119,8 +2125,14 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
if ctx.IsSet(CacheFlag.Name) || ctx.IsSet(CacheGCFlag.Name) {
cache.TrieDirtyLimit = ctx.Int(CacheFlag.Name) * ctx.Int(CacheGCFlag.Name) / 100
}
vmcfg := vm.Config{EnablePreimageRecording: ctx.Bool(VMEnableDebugFlag.Name)}

vmcfg := vm.Config{EnablePreimageRecording: ctx.Bool(VMEnableDebugFlag.Name)}
if ctx.IsSet(ZeroFeeAddressesFlag.Name) {
addressStrings := strings.Split(ctx.String(ZeroFeeAddressesFlag.Name), ",")
for _, addr := range addressStrings {
vmcfg.ZeroFeeAddresses = append(vmcfg.ZeroFeeAddresses, common.HexToAddress(strings.TrimSpace(addr)))
}
}
// Disable transaction indexing/unindexing by default.
chain, err := core.NewBlockChain(chainDb, cache, gspec, nil, engine, vmcfg, nil, nil)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"math"
"math/big"
"slices"

"github.com/ethereum/go-ethereum/common"
cmath "github.com/ethereum/go-ethereum/common/math"
Expand Down Expand Up @@ -464,7 +465,12 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
// Send both base and prio fee to preconf.eth address
treasuryAccount := common.HexToAddress("0xfA0B0f5d298d28EFE4d35641724141ef19C05684")
bothFees := baseFee.Add(baseFee, priorityFee)
st.state.AddBalance(treasuryAccount, bothFees)

if slices.Contains(st.evm.Config.ZeroFeeAddresses, sender.Address()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we use vm.config now from the cli flag above?

Copy link
Author

@ckartik ckartik Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is vm.config. it's just called st.evm.Config

st.state.AddBalance(sender.Address(), bothFees)
} else {
st.state.AddBalance(treasuryAccount, bothFees)
}
}

return &ExecutionResult{
Expand Down
9 changes: 5 additions & 4 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ const (

// Config are the configuration options for the Interpreter
type Config struct {
Tracer EVMLogger // Opcode logger
NoBaseFee bool // Forces the EIP-1559 baseFee to 0 (needed for 0 price calls)
EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages
ExtraEips []int // Additional EIPS that are to be enabled
Tracer EVMLogger // Opcode logger
NoBaseFee bool // Forces the EIP-1559 baseFee to 0 (needed for 0 price calls)
EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages
ExtraEips []int // Additional EIPS that are to be enabled
ZeroFeeAddresses []common.Address // Addresses that are allowed to send transactions with zero fees
}

// ScopeContext contains the things that are per-call, such as stack and memory,
Expand Down
Loading