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 Jul 29, 2024
1 parent 0b59cbd commit 5e69357
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 220 deletions.
2 changes: 1 addition & 1 deletion accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2184,7 +2184,7 @@ func golangBindings(t *testing.T, overload bool) {
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
}
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ava-labs/avalanchego@v0.0.0", "-replace", "github.com/ava-labs/avalanchego=github.com/chain4travel/caminogo@v1.1.15-rc1") // Repo root
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ava-labs/avalanchego@v0.0.0", "-replace", "github.com/ava-labs/avalanchego=github.com/chain4travel/caminogo@v1.1.15-3") // Repo root
replacer.Dir = pkg
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
Expand Down
4 changes: 3 additions & 1 deletion eth/ethadmin/camino_ethadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ func (a *AdminController) KycVerified(head *types.Header, state admin.StateDB, a
// 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 (kycStates & VERIFIED) != 0
return !a.cfg.IsBerlin(head.Time) && (kycStates&KYC_VERIFIED) != 0 ||
a.cfg.IsBerlin(head.Time) && (kycStates&VERIFIED) != 0
}
return true
}
Expand Down
66 changes: 59 additions & 7 deletions eth/ethadmin/camino_ethadmin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,96 @@ func TestKycVerified(t *testing.T) {
Time: sunriseTimestamp,
}

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

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 @@ -67,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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,6 @@ require (
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ava-labs/avalanchego => github.com/chain4travel/caminogo v1.1.15-rc2
replace github.com/ava-labs/avalanchego => github.com/chain4travel/caminogo v1.1.15-rc3

replace github.com/ava-labs/avalanche-ledger-go => github.com/chain4travel/camino-ledger-go v0.0.13-c4t
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chain4travel/caminogo v1.1.15-rc2 h1:QzxhXDa2Ozq/klfslb6SGkzM4BvgPaepyEHa0TsMHjA=
github.com/chain4travel/caminogo v1.1.15-rc2/go.mod h1:YWdA9uLuJhl52XZidSITIYaSuzJi1xvDCp2IAQIzt+U=
github.com/chain4travel/caminogo v1.1.15-rc3 h1:UctQ0lswixwnFhAllFYR5deWkMvNEVAq0fS+6bNQoQ8=
github.com/chain4travel/caminogo v1.1.15-rc3/go.mod h1:YWdA9uLuJhl52XZidSITIYaSuzJi1xvDCp2IAQIzt+U=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
Expand Down
99 changes: 44 additions & 55 deletions params/camino_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ 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"
)

// Gas Price
Expand All @@ -15,67 +18,32 @@ 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: big.NewInt(0),
DAOForkBlock: big.NewInt(0),
DAOForkSupport: true,
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
ApricotPhase1BlockTimestamp: utils.NewUint64(0),
ApricotPhase2BlockTimestamp: utils.NewUint64(0),
ApricotPhase3BlockTimestamp: utils.NewUint64(0),
ApricotPhase4BlockTimestamp: utils.NewUint64(0),
ApricotPhase5BlockTimestamp: utils.NewUint64(0),
SunrisePhase0BlockTimestamp: utils.NewUint64(0),
ApricotPhasePre6BlockTimestamp: utils.NewUint64(0),
ApricotPhase6BlockTimestamp: utils.NewUint64(0),
ApricotPhasePost6BlockTimestamp: utils.NewUint64(0),
BanffBlockTimestamp: utils.NewUint64(0),
// TODO Add Cortina timestamps
}
CaminoChainConfig = getCaminoChainConfig(constants.CaminoID, CaminoChainID)

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

// KopernikusChainConfig is the configuration for Kopernikus Dev Network
KopernikusChainConfig = &ChainConfig{
ChainID: KopernikusChainID,
KopernikusChainConfig = getCaminoChainConfig(constants.KopernikusID, KopernikusChainID)

TestCaminoChainConfig = &ChainConfig{
AvalancheContext: AvalancheContext{common.Hash{1}},
ChainID: big.NewInt(1),
HomesteadBlock: big.NewInt(0),
DAOForkBlock: big.NewInt(0),
DAOForkSupport: true,
DAOForkBlock: nil,
DAOForkSupport: false,
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
Expand All @@ -94,10 +62,19 @@ var (
ApricotPhase6BlockTimestamp: utils.NewUint64(0),
ApricotPhasePost6BlockTimestamp: utils.NewUint64(0),
BanffBlockTimestamp: utils.NewUint64(0),
// TODO Add Cortina timestamps
CortinaBlockTimestamp: utils.NewUint64(0),
BerlinBlockTimestamp: utils.NewUint64(0),
DUpgradeBlockTimestamp: nil,
}
)

func getCaminoChainConfig(networkID uint32, chainID *big.Int) *ChainConfig {
chainConfig := getChainConfig(networkID, chainID)
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 *big.Int, blockTimestamp uint64) Rules {
Expand All @@ -106,3 +83,15 @@ func (c *ChainConfig) CaminoRules(blockNum *big.Int, blockTimestamp uint64) Rule
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 uint64) bool {
return utils.IsTimestampForked(c.SunrisePhase0BlockTimestamp, time)
}

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

0 comments on commit 5e69357

Please sign in to comment.