Skip to content

Commit

Permalink
Update chain configs, kyb phase logic
Browse files Browse the repository at this point in the history
  • Loading branch information
evlekht committed Aug 7, 2024
1 parent fd62dac commit d5c0924
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 123 deletions.
8 changes: 5 additions & 3 deletions eth/ethadmin/camino_ethadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ func (a *AdminController) GetFixedBaseFee(head *types.Header, state admin.StateD
}

func (a *AdminController) KycVerified(head *types.Header, state admin.StateDB, addr common.Address) bool {
if a.cfg.IsSunrisePhase0(big.NewInt(int64(head.Time))) {
timestamp := big.NewInt(int64(head.Time))
if a.cfg.IsSunrisePhase0(timestamp) {
// Get the KYC states
kycStates := new(big.Int).SetBytes(state.GetState(contractAddr, kycStoragePosition(addr)).Bytes()).Uint64()
// Return true if KYC flag is set
return (kycStates & VERIFIED) != 0
// Return true if KYC or KYB flag is set (KYB after Berlin phase)
return !a.cfg.IsBerlin(timestamp) && (kycStates&KYC_VERIFIED) != 0 ||
a.cfg.IsBerlin(timestamp) && (kycStates&VERIFIED) != 0
}
return true
}
Expand Down
71 changes: 61 additions & 10 deletions eth/ethadmin/camino_ethadmin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,101 @@ import (

func TestKycVerified(t *testing.T) {
address := common.Address{1}
sunriseTimestamp := uint64(1000)
sunriseTimestampBig := big.NewInt(0).SetUint64(sunriseTimestamp)
sunriseTimestamp := big.NewInt(1000)
sunriseActiveHeader := &types.Header{
Time: sunriseTimestamp,
Time: sunriseTimestamp.Uint64(),
}

adminCtrl := NewController(nil, &params.ChainConfig{
SunrisePhase0BlockTimestamp: sunriseTimestampBig,
})

tests := map[string]struct {
stateDB func(c *gomock.Controller) *admin.MockStateDB
config *params.ChainConfig
header *types.Header
address common.Address
expectedResult bool
}{
"Not verified": {
"Not verified: Before Berlin": {
stateDB: func(c *gomock.Controller) *admin.MockStateDB {
stateDB := admin.NewMockStateDB(c)
stateDB.EXPECT().GetState(contractAddr, kycStoragePosition(address)).
Return(common.BigToHash(big.NewInt(NOT_VERIFIED)))
return stateDB
},
config: &params.ChainConfig{
SunrisePhase0BlockTimestamp: sunriseTimestamp,
},
header: sunriseActiveHeader,
address: address,
expectedResult: false,
},
"KYC verified": {
"Not verified: After Berlin": {
stateDB: func(c *gomock.Controller) *admin.MockStateDB {
stateDB := admin.NewMockStateDB(c)
stateDB.EXPECT().GetState(contractAddr, kycStoragePosition(address)).
Return(common.BigToHash(big.NewInt(NOT_VERIFIED)))
return stateDB
},
config: &params.ChainConfig{
SunrisePhase0BlockTimestamp: sunriseTimestamp,
BerlinBlockTimestamp: sunriseTimestamp,
},
header: sunriseActiveHeader,
address: address,
expectedResult: false,
},
"KYC verified: Before Berlin": {
stateDB: func(c *gomock.Controller) *admin.MockStateDB {
stateDB := admin.NewMockStateDB(c)
stateDB.EXPECT().GetState(contractAddr, kycStoragePosition(address)).
Return(common.BigToHash(big.NewInt(KYC_VERIFIED)))
return stateDB
},
config: &params.ChainConfig{
SunrisePhase0BlockTimestamp: sunriseTimestamp,
},
header: sunriseActiveHeader,
address: address,
expectedResult: true,
},
"KYB verified": {
"KYC verified: After Berlin": {
stateDB: func(c *gomock.Controller) *admin.MockStateDB {
stateDB := admin.NewMockStateDB(c)
stateDB.EXPECT().GetState(contractAddr, kycStoragePosition(address)).
Return(common.BigToHash(big.NewInt(KYC_VERIFIED)))
return stateDB
},
config: &params.ChainConfig{
SunrisePhase0BlockTimestamp: sunriseTimestamp,
BerlinBlockTimestamp: sunriseTimestamp,
},
header: sunriseActiveHeader,
address: address,
expectedResult: true,
},
"KYB verified: Before Berlin": {
stateDB: func(c *gomock.Controller) *admin.MockStateDB {
stateDB := admin.NewMockStateDB(c)
stateDB.EXPECT().GetState(contractAddr, kycStoragePosition(address)).
Return(common.BigToHash(big.NewInt(KYB_VERIFIED)))
return stateDB
},
config: &params.ChainConfig{
SunrisePhase0BlockTimestamp: sunriseTimestamp,
},
header: sunriseActiveHeader,
address: address,
expectedResult: false,
},
"KYB verified: After Berlin": {
stateDB: func(c *gomock.Controller) *admin.MockStateDB {
stateDB := admin.NewMockStateDB(c)
stateDB.EXPECT().GetState(contractAddr, kycStoragePosition(address)).
Return(common.BigToHash(big.NewInt(KYB_VERIFIED)))
return stateDB
},
config: &params.ChainConfig{
SunrisePhase0BlockTimestamp: sunriseTimestamp,
BerlinBlockTimestamp: sunriseTimestamp,
},
header: sunriseActiveHeader,
address: address,
expectedResult: true,
Expand All @@ -68,6 +118,7 @@ func TestKycVerified(t *testing.T) {
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
c := gomock.NewController(t)
adminCtrl := NewController(nil, tt.config)
result := adminCtrl.KycVerified(tt.header, tt.stateDB(c), tt.address)
require.Equal(t, tt.expectedResult, result)
})
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ require (
)

require (
github.com/DataDog/zstd v1.5.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/btcutil v1.1.3 // indirect
Expand Down Expand Up @@ -125,6 +126,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/ava-labs/avalanchego => github.com/chain4travel/caminogo v1.0.0-rc1
replace github.com/ava-labs/avalanchego => github.com/chain4travel/caminogo v1.10.1-0.20240807152048-883774be4b8e

replace github.com/ava-labs/avalanche-ledger-go => github.com/chain4travel/camino-ledger-go v0.0.13-c4t
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8=
github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/VictoriaMetrics/fastcache v1.10.0 h1:5hDJnLsKLpnUEToub7ETuRu8RCkb40woBZAUiKonXzY=
github.com/VictoriaMetrics/fastcache v1.10.0/go.mod h1:tjiYeEfYXCqacuvYw/7UoDIeJaNxq6132xHICNP77w8=
Expand Down Expand Up @@ -100,8 +102,8 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chain4travel/caminogo v1.0.0-rc1 h1:mWNp3d4/Wm1jwpsuSOz9EQRCyTL+qspZYbW7G8VBa/8=
github.com/chain4travel/caminogo v1.0.0-rc1/go.mod h1:q1rl0Dh8bmdUw9KKLEYxlJqGFPlbvTPPTAJLV/JgoR4=
github.com/chain4travel/caminogo v1.10.1-0.20240807152048-883774be4b8e h1:oI5WL3i59HDQa7lx3bpDkT89mSVrH8Foq2u9CJ6RRBM=
github.com/chain4travel/caminogo v1.10.1-0.20240807152048-883774be4b8e/go.mod h1:ERqKUtzxe5H8G2wCNRZxQja/FFIkxbc1jKoo17neiWc=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
Expand Down
116 changes: 38 additions & 78 deletions params/camino_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ package params
import (
"math/big"

"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/version"
"github.com/ava-labs/coreth/utils"
"github.com/ethereum/go-ethereum/common"
)

Expand All @@ -15,92 +18,37 @@ const (
SunrisePhase0BaseFee uint64 = 200_000_000_000
)

// Camino ChainIDs
var (
// CaminoChainID ...
CaminoChainID = big.NewInt(500)
// CaminoChainID ...
ColumbusChainID = big.NewInt(501)
// KopernikusChainID ...
KopernikusChainID = big.NewInt(502)
)

var (
// CaminoChainConfig is the configuration for Camino Main Network
CaminoChainConfig = &ChainConfig{
ChainID: CaminoChainID,
HomesteadBlock: common.Big0,
DAOForkBlock: common.Big0,
DAOForkSupport: true,
EIP150Block: common.Big0,
EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"),
EIP155Block: common.Big0,
EIP158Block: common.Big0,
ByzantiumBlock: common.Big0,
ConstantinopleBlock: common.Big0,
PetersburgBlock: common.Big0,
IstanbulBlock: common.Big0,
MuirGlacierBlock: common.Big0,
ApricotPhase1BlockTimestamp: common.Big0,
ApricotPhase2BlockTimestamp: common.Big0,
ApricotPhase3BlockTimestamp: common.Big0,
ApricotPhase4BlockTimestamp: common.Big0,
ApricotPhase5BlockTimestamp: common.Big0,
SunrisePhase0BlockTimestamp: common.Big0,
ApricotPhasePre6BlockTimestamp: common.Big0,
ApricotPhase6BlockTimestamp: common.Big0,
ApricotPhasePost6BlockTimestamp: common.Big0,
BanffBlockTimestamp: common.Big0,
// TODO Add Cortina timestamps
}
CaminoChainConfig = getCaminoChainConfig(constants.CaminoID, CaminoChainID)

// ColumbusChainConfig is the configuration for Columbus Test Network
ColumbusChainConfig = &ChainConfig{
ChainID: ColumbusChainID,
HomesteadBlock: common.Big0,
DAOForkBlock: common.Big0,
DAOForkSupport: true,
EIP150Block: common.Big0,
EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"),
EIP155Block: common.Big0,
EIP158Block: common.Big0,
ByzantiumBlock: common.Big0,
ConstantinopleBlock: common.Big0,
PetersburgBlock: common.Big0,
IstanbulBlock: common.Big0,
MuirGlacierBlock: common.Big0,
ApricotPhase1BlockTimestamp: common.Big0,
ApricotPhase2BlockTimestamp: common.Big0,
ApricotPhase3BlockTimestamp: common.Big0,
ApricotPhase4BlockTimestamp: common.Big0,
ApricotPhase5BlockTimestamp: common.Big0,
SunrisePhase0BlockTimestamp: common.Big0,
ApricotPhasePre6BlockTimestamp: common.Big0,
ApricotPhase6BlockTimestamp: common.Big0,
ApricotPhasePost6BlockTimestamp: common.Big0,
BanffBlockTimestamp: common.Big0,
// TODO Add Cortina timestamps
}
ColumbusChainConfig = getCaminoChainConfig(constants.ColumbusID, ColumbusChainID)

// KopernikusChainConfig is the configuration for Kopernikus Dev Network
KopernikusChainConfig = &ChainConfig{
ChainID: KopernikusChainID,
HomesteadBlock: common.Big0,
DAOForkBlock: common.Big0,
DAOForkSupport: true,
EIP150Block: common.Big0,
EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"),
EIP155Block: common.Big0,
EIP158Block: common.Big0,
ByzantiumBlock: common.Big0,
ConstantinopleBlock: common.Big0,
PetersburgBlock: common.Big0,
IstanbulBlock: common.Big0,
MuirGlacierBlock: common.Big0,
ApricotPhase1BlockTimestamp: common.Big0,
ApricotPhase2BlockTimestamp: common.Big0,
ApricotPhase3BlockTimestamp: common.Big0,
ApricotPhase4BlockTimestamp: common.Big0,
ApricotPhase5BlockTimestamp: common.Big0,
SunrisePhase0BlockTimestamp: common.Big0,
ApricotPhasePre6BlockTimestamp: common.Big0,
ApricotPhase6BlockTimestamp: common.Big0,
ApricotPhasePost6BlockTimestamp: common.Big0,
BanffBlockTimestamp: common.Big0,
// TODO Add Cortina timestamps
}
KopernikusChainConfig = getCaminoChainConfig(constants.KopernikusID, KopernikusChainID)

TestCaminoChainConfig = &ChainConfig{AvalancheContext{common.Hash{1}}, big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0)}
)

func getCaminoChainConfig(networkID uint32, chainID *big.Int) *ChainConfig {
chainConfig := getChainConfig(networkID, chainID)
chainConfig.EIP150Hash = common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0")
chainConfig.SunrisePhase0BlockTimestamp = getUpgradeTime(networkID, version.SunrisePhase0Times)
chainConfig.BerlinBlockTimestamp = getUpgradeTime(networkID, version.BerlinPhaseTimes)
return chainConfig
}

// CaminoRules returns the Camino modified rules to support Camino
// network upgrades
func (c *ChainConfig) CaminoRules(blockNum, blockTimestamp *big.Int) Rules {
Expand All @@ -109,3 +57,15 @@ func (c *ChainConfig) CaminoRules(blockNum, blockTimestamp *big.Int) Rules {
rules.IsSunrisePhase0 = c.IsSunrisePhase0(blockTimestamp)
return rules
}

// IsSunrisePhase0 returns whether [blockTimestamp] represents a block
// with a timestamp after the Sunrise Phase 0 upgrade time.
func (c *ChainConfig) IsSunrisePhase0(time *big.Int) bool {
return utils.IsForked(c.SunrisePhase0BlockTimestamp, time)
}

// IsBerlin returns whether [time] represents a block
// with a timestamp after the Berlin upgrade time.
func (c *ChainConfig) IsBerlin(time *big.Int) bool {
return utils.IsForked(c.BerlinBlockTimestamp, time)
}
Loading

0 comments on commit d5c0924

Please sign in to comment.