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

Rename Whitelist to Allowlist #207

Merged
merged 3 commits into from
Aug 21, 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
2 changes: 1 addition & 1 deletion cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
// for fee-currencies here, since those are dynamically changing
// based on the oracle's exchange rates.
// When a Celo transaction with specified fee-currency is validated with this tool,
// this will thus result in a ErrNonWhitelistedFeeCurrency error for now.
// this will thus result in a ErrUnregisteredFeeCurrency error for now.
msg, err := core.TransactionToMessage(tx, signer, pre.Env.BaseFee, vmContext.FeeCurrencyContext.ExchangeRates)
if err != nil {
log.Warn("rejected tx", "index", i, "hash", tx.Hash(), "error", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/evm/internal/t8ntool/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func Transaction(ctx *cli.Context) error {
// for fee-currencies here, since those are written to the
// FeeCurrencyDirectory contract and are chain-specific.
// When a Celo transaction with specified fee-currency is validated with this tool,
// this will thus result in a ErrNonWhitelistedFeeCurrency error for now.
// this will thus result in a ErrUnregisteredFeeCurrency error for now.
var feeIntrinsic common.IntrinsicGasCosts
if gas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil,
chainConfig.IsHomestead(new(big.Int)), chainConfig.IsIstanbul(new(big.Int)), chainConfig.IsShanghai(new(big.Int), 0), tx.FeeCurrency(), feeIntrinsic); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions common/celo_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func CurrencyIntrinsicGasCost(i IntrinsicGasCosts, feeCurrency *Address) (uint64
return gasCost, true
}

func CurrencyWhitelist(exchangeRates ExchangeRates) []Address {
func CurrencyAllowlist(exchangeRates ExchangeRates) []Address {
addrs := make([]Address, len(exchangeRates))
i := 0
for k := range exchangeRates {
Expand All @@ -51,7 +51,7 @@ func CurrencyWhitelist(exchangeRates ExchangeRates) []Address {
return addrs
}

func IsCurrencyWhitelisted(exchangeRates ExchangeRates, feeCurrency *Address) bool {
func IsCurrencyAllowed(exchangeRates ExchangeRates, feeCurrency *Address) bool {
if feeCurrency == nil {
return true
}
Expand Down
6 changes: 3 additions & 3 deletions common/celo_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var (
}
)

func TestIsWhitelisted(t *testing.T) {
func TestIsCurrencyAllowed(t *testing.T) {
tests := []struct {
name string
feeCurrency *Address
Expand All @@ -39,8 +39,8 @@ func TestIsWhitelisted(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsCurrencyWhitelisted(exchangeRates, tt.feeCurrency); got != tt.want {
t.Errorf("IsWhitelisted() = %v, want %v", got, tt.want)
if got := IsCurrencyAllowed(exchangeRates, tt.feeCurrency); got != tt.want {
t.Errorf("IsCurrencyAllowed() = %v, want %v", got, tt.want)
}
})
}
Expand Down
12 changes: 6 additions & 6 deletions common/exchange/rates.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (

var (
unitRate = big.NewRat(1, 1)
// ErrNonWhitelistedFeeCurrency is returned if the currency specified to use for the fees
// ErrUnregisteredFeeCurrency is returned if the currency specified to use for the fees
// isn't one of the currencies whitelisted for that purpose.
ErrNonWhitelistedFeeCurrency = errors.New("non-whitelisted fee currency address")
ErrUnregisteredFeeCurrency = errors.New("unregistered fee-currency address")
)

// ConvertCurrency does an exchange conversion from currencyFrom to currencyTo of the value given.
Expand All @@ -35,7 +35,7 @@ func ConvertCurrencyToCelo(exchangeRates common.ExchangeRates, currencyAmount *b
}
exchangeRate, ok := exchangeRates[*feeCurrency]
if !ok {
return nil, fmt.Errorf("could not convert from fee currency to native (fee-currency=%s): %w ", feeCurrency, ErrNonWhitelistedFeeCurrency)
return nil, fmt.Errorf("could not convert from fee currency to native (fee-currency=%s): %w ", feeCurrency, ErrUnregisteredFeeCurrency)
}
return new(big.Int).Div(new(big.Int).Mul(currencyAmount, exchangeRate.Denom()), exchangeRate.Num()), nil
}
Expand All @@ -46,7 +46,7 @@ func ConvertCeloToCurrency(exchangeRates common.ExchangeRates, feeCurrency *comm
}
exchangeRate, ok := exchangeRates[*feeCurrency]
if !ok {
return nil, fmt.Errorf("could not convert from native to fee currency (fee-currency=%s): %w ", feeCurrency, ErrNonWhitelistedFeeCurrency)
return nil, fmt.Errorf("could not convert from native to fee currency (fee-currency=%s): %w ", feeCurrency, ErrUnregisteredFeeCurrency)
}
return new(big.Int).Div(new(big.Int).Mul(celoAmount, exchangeRate.Num()), exchangeRate.Denom()), nil
}
Expand Down Expand Up @@ -131,7 +131,7 @@ func (rf *RatesAndFees) GetNativeBaseFee() *big.Int {
}

// GetBaseFeeIn returns the basefee expressed in the specified currency. Returns nil
// if the currency is not whitelisted.
// if the currency is not allowlisted.
func (rf *RatesAndFees) GetBaseFeeIn(currency *common.Address) *big.Int {
// If native currency is being requested, return it
if currency == nil {
Expand All @@ -151,7 +151,7 @@ func (rf *RatesAndFees) GetBaseFeeIn(currency *common.Address) *big.Int {
calculatedBaseFee, err := ConvertCeloToCurrency(rf.Rates, currency, rf.nativeBaseFee)
if err != nil {
// Should never happen: error lvl log line
log.Error("BaseFee requested for non whitelisted currency",
log.Error("BaseFee requested for unregistered currency",
"currency", currency.Hex(),
"exchangeRates", rf.Rates,
"cause", err)
Expand Down
6 changes: 3 additions & 3 deletions contracts/fee_currencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func DebitFees(evm *vm.EVM, feeCurrency *common.Address, address common.Address,

maxIntrinsicGasCost, ok := common.MaxAllowedIntrinsicGasCost(evm.Context.FeeCurrencyContext.IntrinsicGasCosts, feeCurrency)
if !ok {
return 0, exchange.ErrNonWhitelistedFeeCurrency
return 0, exchange.ErrUnregisteredFeeCurrency
}

leftoverGas, err := evm.CallWithABI(
Expand Down Expand Up @@ -93,7 +93,7 @@ func CreditFees(
}
maxAllowedGasForDebitAndCredit, ok := common.MaxAllowedIntrinsicGasCost(evm.Context.FeeCurrencyContext.IntrinsicGasCosts, feeCurrency)
if !ok {
return exchange.ErrNonWhitelistedFeeCurrency
return exchange.ErrUnregisteredFeeCurrency
}

maxAllowedGasForCredit := maxAllowedGasForDebitAndCredit - gasUsedDebit
Expand Down Expand Up @@ -123,7 +123,7 @@ func CreditFees(
intrinsicGas, ok := common.CurrencyIntrinsicGasCost(evm.Context.FeeCurrencyContext.IntrinsicGasCosts, feeCurrency)
if !ok {
// this will never happen
return exchange.ErrNonWhitelistedFeeCurrency
return exchange.ErrUnregisteredFeeCurrency
}
gasUsedForDebitAndCredit := gasUsedDebit + gasUsed
if gasUsedForDebitAndCredit > intrinsicGas {
Expand Down
8 changes: 4 additions & 4 deletions core/celo_multi_gaspool.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ type FeeCurrencyLimitMapping = map[FeeCurrency]float64
// pool for CELO
func NewMultiGasPool(
blockGasLimit uint64,
whitelist []FeeCurrency,
allowlist []FeeCurrency,
defaultLimit float64,
limitsMapping FeeCurrencyLimitMapping,
) *MultiGasPool {
pools := make(map[FeeCurrency]*GasPool, len(whitelist))
pools := make(map[FeeCurrency]*GasPool, len(allowlist))

for i := range whitelist {
currency := whitelist[i]
for i := range allowlist {
currency := allowlist[i]
fraction, ok := limitsMapping[currency]
if !ok {
fraction = defaultLimit
Expand Down
32 changes: 16 additions & 16 deletions core/celo_multi_gaspool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ func TestMultiCurrencyGasPool(t *testing.T) {
testCases := []struct {
name string
feeCurrency *FeeCurrency
whitelist []FeeCurrency
allowlist []FeeCurrency
defaultLimit float64
limits FeeCurrencyLimitMapping
defaultPoolExpected bool
expectedValue uint64
}{
{
name: "Empty whitelist, empty mapping, CELO uses default pool",
name: "Empty allowlist, empty mapping, CELO uses default pool",
feeCurrency: nil,
whitelist: []FeeCurrency{},
allowlist: []FeeCurrency{},
defaultLimit: 0.9,
limits: map[FeeCurrency]float64{},
defaultPoolExpected: true,
expectedValue: 900, // blockGasLimit - subGasAmount
},
{
name: "Non-empty whitelist, non-empty mapping, CELO uses default pool",
name: "Non-empty allowlist, non-empty mapping, CELO uses default pool",
feeCurrency: nil,
whitelist: []FeeCurrency{
allowlist: []FeeCurrency{
cUSDToken,
},
defaultLimit: 0.9,
Expand All @@ -45,18 +45,18 @@ func TestMultiCurrencyGasPool(t *testing.T) {
expectedValue: 900, // blockGasLimit - subGasAmount
},
{
name: "Empty whitelist, empty mapping, non-whitelisted currency fallbacks to the default pool",
name: "Empty allowlist, empty mapping, non-registered currency fallbacks to the default pool",
feeCurrency: &cUSDToken,
whitelist: []FeeCurrency{},
allowlist: []FeeCurrency{},
defaultLimit: 0.9,
limits: map[FeeCurrency]float64{},
defaultPoolExpected: true,
expectedValue: 900, // blockGasLimit - subGasAmount
},
{
name: "Non-empty whitelist, non-empty mapping, non-whitelisted currency uses default pool",
name: "Non-empty allowlist, non-empty mapping, non-registered currency uses default pool",
feeCurrency: &cEURToken,
whitelist: []FeeCurrency{
allowlist: []FeeCurrency{
cUSDToken,
},
defaultLimit: 0.9,
Expand All @@ -67,9 +67,9 @@ func TestMultiCurrencyGasPool(t *testing.T) {
expectedValue: 900, // blockGasLimit - subGasAmount
},
{
name: "Non-empty whitelist, empty mapping, whitelisted currency uses default limit",
name: "Non-empty allowlist, empty mapping, registered currency uses default limit",
feeCurrency: &cUSDToken,
whitelist: []FeeCurrency{
allowlist: []FeeCurrency{
cUSDToken,
},
defaultLimit: 0.9,
Expand All @@ -78,9 +78,9 @@ func TestMultiCurrencyGasPool(t *testing.T) {
expectedValue: 800, // blockGasLimit * defaultLimit - subGasAmount
},
{
name: "Non-empty whitelist, non-empty mapping, configured whitelisted currency uses configured limits",
name: "Non-empty allowlist, non-empty mapping, configured registered currency uses configured limits",
feeCurrency: &cUSDToken,
whitelist: []FeeCurrency{
allowlist: []FeeCurrency{
cUSDToken,
},
defaultLimit: 0.9,
Expand All @@ -91,9 +91,9 @@ func TestMultiCurrencyGasPool(t *testing.T) {
expectedValue: 400, // blockGasLimit * 0.5 - subGasAmount
},
{
name: "Non-empty whitelist, non-empty mapping, unconfigured whitelisted currency uses default limit",
name: "Non-empty allowlist, non-empty mapping, unconfigured registered currency uses default limit",
feeCurrency: &cEURToken,
whitelist: []FeeCurrency{
allowlist: []FeeCurrency{
cUSDToken,
cEURToken,
},
Expand All @@ -110,7 +110,7 @@ func TestMultiCurrencyGasPool(t *testing.T) {
t.Run(c.name, func(t *testing.T) {
mgp := NewMultiGasPool(
blockGasLimit,
c.whitelist,
c.allowlist,
c.defaultLimit,
c.limits,
)
Expand Down
11 changes: 5 additions & 6 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation b
if feeCurrency != nil {
intrinsicGasForFeeCurrency, ok := common.CurrencyIntrinsicGasCost(feeIntrinsicGas, feeCurrency)
if !ok {
return 0, exchange.ErrNonWhitelistedFeeCurrency
return 0, exchange.ErrUnregisteredFeeCurrency
}
if (math.MaxUint64 - gas) < intrinsicGasForFeeCurrency {
return 0, ErrGasUintOverflow
Expand Down Expand Up @@ -430,15 +430,14 @@ func (st *StateTransition) preCheck() error {
}
}

// Verify that fee currency is whitelisted
// Verify that fee currency is registered
if msg.FeeCurrency != nil {
if !st.evm.ChainConfig().IsCel2(st.evm.Context.Time) {
return ErrCel2NotEnabled
} else {
isWhiteListed := common.IsCurrencyWhitelisted(st.evm.Context.FeeCurrencyContext.ExchangeRates, msg.FeeCurrency)
if !isWhiteListed {
log.Trace("fee currency not whitelisted", "fee currency address", msg.FeeCurrency)
return exchange.ErrNonWhitelistedFeeCurrency
if !common.IsCurrencyAllowed(st.evm.Context.FeeCurrencyContext.ExchangeRates, msg.FeeCurrency) {
log.Trace("fee currency not allowed", "fee currency address", msg.FeeCurrency)
return exchange.ErrUnregisteredFeeCurrency
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/txpool/celo_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func CeloValidateTransaction(tx *types.Transaction, head *types.Header,
if err := ValidateTransaction(tx, head, signer, opts, currencyCtx); err != nil {
return err
}
if !common.IsCurrencyWhitelisted(currencyCtx.ExchangeRates, tx.FeeCurrency()) {
return exchange.ErrNonWhitelistedFeeCurrency
if !common.IsCurrencyAllowed(currencyCtx.ExchangeRates, tx.FeeCurrency()) {
return exchange.ErrUnregisteredFeeCurrency
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions core/txpool/legacypool/celo_legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
// filter Filters transactions from the given list, according to remaining balance (per currency)
// and gasLimit. Returns drops and invalid txs.
func (pool *LegacyPool) filter(list *list, addr common.Address, gasLimit uint64) (types.Transactions, types.Transactions) {
// CELO: drop all transactions that no longer have a whitelisted currency
dropsWhitelist, invalidsWhitelist := list.FilterWhitelisted(pool.feeCurrencyContext.ExchangeRates)
// CELO: drop all transactions that no longer have a registered currency
dropsAllowlist, invalidsAllowlist := list.FilterAllowlisted(pool.feeCurrencyContext.ExchangeRates)
// Check from which currencies we need to get balances
currenciesInList := list.FeeCurrencies()
drops, invalids := list.Filter(pool.getBalances(addr, currenciesInList), gasLimit)
totalDrops := append(dropsWhitelist, drops...)
totalInvalids := append(invalidsWhitelist, invalids...)
totalDrops := append(dropsAllowlist, drops...)
totalInvalids := append(invalidsAllowlist, invalids...)
return totalDrops, totalInvalids
}

Expand Down
4 changes: 2 additions & 2 deletions core/txpool/legacypool/celo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/holiman/uint256"
)

func (l *list) FilterWhitelisted(rates common.ExchangeRates) (types.Transactions, types.Transactions) {
func (l *list) FilterAllowlisted(rates common.ExchangeRates) (types.Transactions, types.Transactions) {
removed := l.txs.Filter(func(tx *types.Transaction) bool {
return !common.IsCurrencyWhitelisted(rates, tx.FeeCurrency())
return !common.IsCurrencyAllowed(rates, tx.FeeCurrency())
})

if len(removed) == 0 {
Expand Down
8 changes: 4 additions & 4 deletions core/txpool/legacypool/celo_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestListFeeCost(t *testing.T) {
assert.Equal(t, uint64(20000), list.TotalCostFor(&curr1).Uint64())
}

func TestFilterWhitelisted(t *testing.T) {
func TestFilterAllowlisted(t *testing.T) {
curr1 := common.HexToAddress("0002")
curr2 := common.HexToAddress("0004")
curr3 := common.HexToAddress("0006")
Expand All @@ -77,14 +77,14 @@ func TestFilterWhitelisted(t *testing.T) {
list.Add(txC(9, 1, 1, 10000, &curr1), DefaultConfig.PriceBump, nil, rates)
assert.Equal(t, uint64(30000), list.TotalCostFor(&curr2).Uint64())

removed, invalids := list.FilterWhitelisted(common.ExchangeRates{curr1: nil, curr3: nil})
removed, invalids := list.FilterAllowlisted(common.ExchangeRates{curr1: nil, curr3: nil})
assert.Len(t, removed, 1)
assert.Len(t, invalids, 0)
assert.Equal(t, removed[0], toBeRemoved)
assert.Equal(t, uint64(0), list.TotalCostFor(&curr2).Uint64())
}

func TestFilterWhitelistedStrict(t *testing.T) {
func TestFilterAllowlistedStrict(t *testing.T) {
curr1 := common.HexToAddress("0002")
curr2 := common.HexToAddress("0004")
curr3 := common.HexToAddress("0006")
Expand All @@ -101,7 +101,7 @@ func TestFilterWhitelistedStrict(t *testing.T) {
toBeInvalid := txC(9, 1, 1, 10000, &curr3)
list.Add(toBeInvalid, DefaultConfig.PriceBump, nil, rates)

removed, invalids := list.FilterWhitelisted(common.ExchangeRates{curr1: nil, curr3: nil})
removed, invalids := list.FilterAllowlisted(common.ExchangeRates{curr1: nil, curr3: nil})
assert.Len(t, removed, 1)
assert.Len(t, invalids, 1)
assert.Equal(t, removed[0], toBeRemoved)
Expand Down
6 changes: 3 additions & 3 deletions e2e_test/js-tests/test_viem_tx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ describe("viem send tx", () => {
);
}).timeout(10_000);

it("send tx with non-whitelisted fee currency", async () => {
it("send tx with unregistered fee currency", async () => {
const request = await walletClient.prepareTransactionRequest({
account,
to: "0x00000000000000000000000000000000DeaDBeef",
Expand All @@ -260,10 +260,10 @@ describe("viem send tx", () => {
await walletClient.sendRawTransaction({
serializedTransaction: signature,
});
assert.fail("Failed to filter nonwhitelisted feeCurrency");
assert.fail("Failed to filter unregistered feeCurrency");
} catch (err) {
// TODO: find a better way to check the error type
if (err.cause.details == "non-whitelisted fee currency address") {
if (err.cause.details == "unregistered fee-currency address") {
// Test success
} else {
throw err;
Expand Down
Loading