Skip to content

Commit

Permalink
feat: Add Support for Zero Fee Addresses (#53)
Browse files Browse the repository at this point in the history
* feat: adds zero-fee addresses

* feat: uses command line flag for zerofeeaddress

* chore: cleanup

* chore: remove comment
  • Loading branch information
ckartik authored Nov 25, 2024
1 parent a9bcf58 commit dd8d982
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
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()) {
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

0 comments on commit dd8d982

Please sign in to comment.