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

Take advantage of fixed contract addresses #26

Merged
merged 3 commits into from
Oct 27, 2023
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: 14 additions & 0 deletions contracts/celo/addresses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package contracts

import "github.com/ethereum/go-ethereum/common"

var (
RegistryAddress = common.HexToAddress("0x000000000000000000000000000000000000ce10")
GoldTokenAddress = common.HexToAddress("0x471ece3750da237f93b8e339c536989b8978a438")
FeeHandlerAddress = common.HexToAddress("0xcd437749e43a154c07f3553504c68fbfd56b8778")
FeeCurrencyWhitelistAddress = common.HexToAddress("0xbb024e9cdcb2f9e34d893630d19611b8a5381b3c")
MentoFeeHandlerSellerAddress = common.HexToAddress("0x4efa274b7e33476c961065000d58ee09f7921a74")
UniswapFeeHandlerSellerAddress = common.HexToAddress("0xd3aee28548dbb65df03981f0dc0713bfcbd10a97")
SortedOraclesAddress = common.HexToAddress("0xefb84935239dacdecf7c5ba76d8de40b077b7b33")
AddressSortedLinkedListWithMedianAddress = common.HexToAddress("0xED477A99035d0c1e11369F1D7A4e587893cc002B")
)
37 changes: 0 additions & 37 deletions contracts/config/registry_ids.go

This file was deleted.

29 changes: 6 additions & 23 deletions core/celo_evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
contracts "github.com/ethereum/go-ethereum/contracts/celo"
"github.com/ethereum/go-ethereum/contracts/celo/abigen"
contracts_config "github.com/ethereum/go-ethereum/contracts/config"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
Expand All @@ -16,21 +16,13 @@ import (
)

// Returns the exchange rates for all gas currencies from CELO
func getExchangeRates(caller *CeloBackend, registry *abigen.RegistryCaller) (map[common.Address]*big.Rat, error) {
func getExchangeRates(caller *CeloBackend) (map[common.Address]*big.Rat, error) {
exchangeRates := map[common.Address]*big.Rat{}
whitelistAddress, err := registry.GetAddressForOrDie(&bind.CallOpts{}, contracts_config.FeeCurrencyWhitelistRegistryId)
if err != nil {
return exchangeRates, fmt.Errorf("Failed to get address for FeeCurrencyWhitelist: %w", err)
}
whitelist, err := abigen.NewFeeCurrencyWhitelistCaller(whitelistAddress, caller)
whitelist, err := abigen.NewFeeCurrencyWhitelistCaller(contracts.FeeCurrencyWhitelistAddress, caller)
if err != nil {
return exchangeRates, fmt.Errorf("Failed to access FeeCurrencyWhitelist: %w", err)
}
oracleAddress, err := registry.GetAddressForOrDie(&bind.CallOpts{}, contracts_config.SortedOraclesRegistryId)
if err != nil {
return exchangeRates, fmt.Errorf("Failed to get address for SortedOracle: %w", err)
}
oracle, err := abigen.NewSortedOraclesCaller(oracleAddress, caller)
oracle, err := abigen.NewSortedOraclesCaller(contracts.SortedOraclesAddress, caller)
if err != nil {
return exchangeRates, fmt.Errorf("Failed to access SortedOracle: %w", err)
}
Expand Down Expand Up @@ -63,18 +55,9 @@ func setCeloFieldsInBlockContext(blockContext *vm.BlockContext, header *types.He
stateCopy := statedb.Copy()
caller := &CeloBackend{config, stateCopy}

// Set goldTokenAddress
registry, err := abigen.NewRegistryCaller(contracts_config.RegistrySmartContractAddress, caller)
if err != nil {
log.Error("Failed to access registry!", "err", err)
}
blockContext.GoldTokenAddress, err = registry.GetAddressForOrDie(&bind.CallOpts{}, contracts_config.GoldTokenRegistryId)
if err != nil {
log.Error("Failed to get address for GoldToken!", "err", err)
}

// Add fee currency exchange rates
blockContext.ExchangeRates, err = getExchangeRates(caller, registry)
var err error
blockContext.ExchangeRates, err = getExchangeRates(caller)
if err != nil {
log.Error("Error fetching exchange rates!", "err", err)
}
Expand Down
9 changes: 4 additions & 5 deletions core/celo_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/ethereum/go-ethereum/common"
contracts "github.com/ethereum/go-ethereum/contracts/celo"
contracts_config "github.com/ethereum/go-ethereum/contracts/config"
"github.com/ethereum/go-ethereum/crypto"
)

Expand Down Expand Up @@ -81,7 +80,7 @@ func celoGenesisAccounts() map[common.Address]GenesisAccount {
panic("Could not set devBalance!")
}
return map[common.Address]GenesisAccount{
contracts_config.RegistrySmartContractAddress: { // Registry Proxy
contracts.RegistryAddress: { // Registry Proxy
Code: proxyBytecode,
Storage: map[common.Hash]common.Hash{
common.HexToHash("0x0"): DevAddr32, // `_owner` slot in Registry contract
Expand All @@ -94,7 +93,7 @@ func celoGenesisAccounts() map[common.Address]GenesisAccount {
Code: registryBytecode,
Balance: big.NewInt(0),
},
common.HexToAddress("0xce12"): { // GoldToken Proxy
contracts.GoldTokenAddress: { // GoldToken Proxy
Code: proxyBytecode,
Storage: map[common.Hash]common.Hash{
proxy_implementation_slot: common.HexToHash("0xce13"),
Expand All @@ -106,15 +105,15 @@ func celoGenesisAccounts() map[common.Address]GenesisAccount {
Code: goldTokenBytecode,
Balance: big.NewInt(0),
},
common.HexToAddress("0xce14"): {
contracts.FeeCurrencyWhitelistAddress: {
Code: feeCurrencyWhitelistBytecode,
Balance: big.NewInt(0),
Storage: map[common.Hash]common.Hash{
common.HexToHash("0x1"): common.HexToHash("0x1"), // array length 1
crypto.Keccak256Hash(common.HexToHash("0x1").Bytes()): common.HexToHash("0xce16"), // FeeCurrency
},
},
common.HexToAddress("0xce15"): {
contracts.SortedOraclesAddress: {
Code: sortedOraclesBytecode,
Storage: map[common.Hash]common.Hash{
common.HexToHash("0x0"): DevAddr32, // _owner
Expand Down
3 changes: 2 additions & 1 deletion core/vm/celo_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
contracts "github.com/ethereum/go-ethereum/contracts/celo"
"github.com/ethereum/go-ethereum/params"
)

Expand Down Expand Up @@ -45,7 +46,7 @@ func celoPrecompileAddress(index byte) common.Address {
}

func (ctx *celoPrecompileContext) IsCallerGoldToken() (bool, error) {
return ctx.BlockContext.GoldTokenAddress == ctx.caller, nil
return contracts.GoldTokenAddress == ctx.caller, nil
}

// Native transfer contract to make Celo Gold ERC20 compatible.
Expand Down
3 changes: 1 addition & 2 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ type BlockContext struct {
ExcessBlobGas *uint64 // ExcessBlobGas field in the header, needed to compute the data

// Celo specific information
GoldTokenAddress common.Address
ExchangeRates map[common.Address]*big.Rat
ExchangeRates map[common.Address]*big.Rat
}

// TxContext provides the EVM with information about a transaction.
Expand Down
6 changes: 3 additions & 3 deletions e2e_test/shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export ETH_RPC_URL=http://127.0.0.1:8545
ACC_ADDR=0x42cf1bbc38BaAA3c4898ce8790e21eD2738c6A4a
ACC_PRIVKEY=0x2771aff413cac48d9f8c114fabddd9195a2129f3c2c436caa07e27bb7f58ead5
REGISTRY_ADDR=0x000000000000000000000000000000000000ce10
TOKEN_ADDR=0x000000000000000000000000000000000000ce12
FEE_CURRENCY_WHITELIST_ADDR=0x000000000000000000000000000000000000ce14
SORTED_ORACLES_ADDR=0x000000000000000000000000000000000000ce15
TOKEN_ADDR=0x471ece3750da237f93b8e339c536989b8978a438
FEE_CURRENCY_WHITELIST_ADDR=0xbb024e9cdcb2f9e34d893630d19611b8a5381b3c
SORTED_ORACLES_ADDR=0xefb84935239dacdecf7c5ba76d8de40b077b7b33
FEE_CURRENCY=0x000000000000000000000000000000000000ce16

FIXIDITY_1=1000000000000000000000000
Expand Down
7 changes: 2 additions & 5 deletions e2e_test/test_fee_currency.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ set -x

source shared.sh

# Register fee currency whitelist and sorted oracles
cast send --private-key $ACC_PRIVKEY $REGISTRY_ADDR 'function setAddressFor(string calldata identifier, address addr) external' FeeCurrencyWhitelist $FEE_CURRENCY_WHITELIST_ADDR
cast send --private-key $ACC_PRIVKEY $REGISTRY_ADDR 'function setAddressFor(string calldata identifier, address addr) external' SortedOracles $SORTED_ORACLES_ADDR
# Add our account as oracle and submit value
cast send --private-key $ACC_PRIVKEY $SORTED_ORACLES_ADDR 'function addOracle(address token, address oracleAddress) external' $FEE_CURRENCY $ACC_ADDR
cast send --private-key $ACC_PRIVKEY $SORTED_ORACLES_ADDR 'function report(address token, uint256 value, address lesserKey, address greaterKey) external' $FEE_CURRENCY $FIXIDITY_1 $ZERO_ADDRESS $ZERO_ADDRESS
cast send --private-key $ACC_PRIVKEY $SORTED_ORACLES_ADDR 'addOracle(address token, address oracleAddress)' $FEE_CURRENCY $ACC_ADDR
cast send --private-key $ACC_PRIVKEY $SORTED_ORACLES_ADDR 'report(address token, uint256 value, address lesserKey, address greaterKey)' $FEE_CURRENCY $FIXIDITY_1 $ZERO_ADDRESS $ZERO_ADDRESS

# Debug suggestions:
# cast call $FEE_CURRENCY_WHITELIST_ADDR 'function getWhitelist() external view returns (address[] memory)'
Expand Down
5 changes: 1 addition & 4 deletions e2e_test/test_token_duality.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ set -eo pipefail

source shared.sh

# Register token
cast send --private-key $ACC_PRIVKEY $REGISTRY_ADDR 'function setAddressFor(string calldata identifier, address addr) external' GoldToken $TOKEN_ADDR

# Send token and check balance
balance_before=$(cast balance 0x000000000000000000000000000000000000dEaD)
cast send --private-key $ACC_PRIVKEY $TOKEN_ADDR 'function transfer(address to, uint256 value) external returns (bool)' 0x000000000000000000000000000000000000dEaD 100
cast send --private-key $ACC_PRIVKEY $TOKEN_ADDR 'transfer(address to, uint256 value) returns (bool)' 0x000000000000000000000000000000000000dEaD 100
balance_after=$(cast balance 0x000000000000000000000000000000000000dEaD)
echo "Balance change: $balance_before -> $balance_after"
[[ $((balance_before + 100)) -eq $balance_after ]] || (echo "Balance did not change as expected"; exit 1)
3 changes: 2 additions & 1 deletion params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
contracts "github.com/ethereum/go-ethereum/contracts/celo"
)

var (
// The base fee portion of the transaction fee accumulates at this predeploy
OptimismBaseFeeRecipient = common.HexToAddress("0x4200000000000000000000000000000000000019")
OptimismBaseFeeRecipient = contracts.FeeHandlerAddress
// The L1 portion of the transaction fee accumulates at this predeploy
OptimismL1FeeRecipient = common.HexToAddress("0x420000000000000000000000000000000000001A")
)
Expand Down