Skip to content

Commit

Permalink
[[FIX]] add format eth address fork
Browse files Browse the repository at this point in the history
  • Loading branch information
bysomeone authored and vipwzw committed Apr 12, 2024
1 parent 5de6bc4 commit ee8af86
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ func TestAccountKey(t *testing.T) {

acc := NewCoinsAccount(types.NewChain33Config(types.GetDefaultCfgstring()))
addr := "0x6c0d7BE0d2C8350042890a77393158181716b0d6"
addr1 := address.ToLower(addr)
addr1 := address.FormatEthAddress(addr)
accKey := acc.accountReadKey(addr)
require.Equal(t, accKey, acc.AccountKey(addr))
require.Equal(t, accKey, acc.AccountKey(addr1))
Expand Down
1 change: 1 addition & 0 deletions cmd/chain33/chain33.fork.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ForkCacheDriver=2580000
ForkTicketFundAddrV1=3350000
ForkRootHash=4500000
ForkFormatAddressKey=0
ForkEthAddressFormat=0
ForkCheckEthTxSort=0
ForkProxyExec=0
ForkMaxTxFeeV1=0
Expand Down
3 changes: 2 additions & 1 deletion cmd/chain33/chain33.system.fork.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ForkCacheDriver=2580000
ForkTicketFundAddrV1=3350000
ForkRootHash=4500000
ForkFormatAddressKey=0
ForkEthAddressFormat=0
ForkCheckEthTxSort=0
ForkProxyExec=0
ForkMaxTxFeeV1=0
ForkMaxTxFeeV1=0
7 changes: 5 additions & 2 deletions common/address/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import (
// ForkFormatAddressKey 地址key格式化分叉名称,主要针对eth地址
const ForkFormatAddressKey = "ForkFormatAddressKey"

// ForkEthAddressFormat eth地址统一格式化
const ForkEthAddressFormat = "ForkEthAddressFormat"

// IsEthAddress verifies whether a string can represent
// a valid hex-encoded eth address
func IsEthAddress(addr string) bool {
return common.IsHexAddress(addr)
}

// ToLower to lower case string
func ToLower(addr string) string {
// FormatEthAddress eth地址格式化
func FormatEthAddress(addr string) string {
return strings.ToLower(addr)
}

Expand Down
2 changes: 1 addition & 1 deletion common/address/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestFormatAddrKey(t *testing.T) {
addrKey1 := fmt.Sprintf("%s:%s", "addrKey:", FormatAddrKey(addr1))
addrKey2 := fmt.Sprintf("%s:%s", "addrKey:", FormatAddrKey(addr2))

expect := fmt.Sprintf("%s:%s", "addrKey:", string(FormatAddrKey(ToLower(addr1))))
expect := fmt.Sprintf("%s:%s", "addrKey:", string(FormatAddrKey(FormatEthAddress(addr1))))

require.Equal(t, expect, addrKey1)
require.Equal(t, expect, addrKey2)
Expand Down
3 changes: 1 addition & 2 deletions system/address/eth/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package eth

import (
"errors"

"github.com/33cn/chain33/common/crypto/client"

"github.com/33cn/chain33/common/address"
Expand Down Expand Up @@ -82,7 +81,7 @@ func (e *eth) FormatAddr(addr string) string {
func formatAddr(addr string) string {
ctx := client.GetCryptoContext()
if ctx.API == nil || ctx.API.GetConfig().IsFork(ctx.CurrBlockHeight, address.ForkFormatAddressKey) {
return address.ToLower(addr)
return address.FormatEthAddress(addr)
}
return addr
}
Expand Down
2 changes: 1 addition & 1 deletion system/address/eth/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestFormatEthAddr(t *testing.T) {
err = ethDriver.ValidateAddr(ethAddr)
require.Nil(t, err)
addr := ethDriver.PubKeyToAddr(chain33Priv.PubKey().Bytes())
require.Equal(t, address.ToLower(ethAddr), addr)
require.Equal(t, address.FormatEthAddress(ethAddr), addr)
}
require.Equal(t, eth.Name, ethDriver.GetName())
}
Expand Down
2 changes: 1 addition & 1 deletion system/dapp/manage/executor/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *Manage) Exec_Modify(manageAction *types.ModifyConfig, tx *types.Transac
}
}
action := newAction(c, tx, int32(index))
if !IsSuperManager(cfg, action.fromaddr) {
if !IsSuperManager(cfg, action.fromaddr, c.GetHeight()) {
return nil, mty.ErrNoPrivilege
}
return action.modifyConfig(manageAction)
Expand Down
6 changes: 5 additions & 1 deletion system/dapp/manage/executor/manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package executor

import (
"github.com/33cn/chain33/common/address"
log "github.com/33cn/chain33/common/log/log15"
drivers "github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
Expand Down Expand Up @@ -57,9 +58,12 @@ func (c *Manage) CheckTx(tx *types.Transaction, index int) error {
}

// IsSuperManager is supper manager or not
func IsSuperManager(cfg *types.Chain33Config, addr string) bool {
func IsSuperManager(cfg *types.Chain33Config, addr string, height int64) bool {
conf := types.ConfSub(cfg, driverName)
for _, m := range conf.GStrList("superManager") {
if address.IsEthAddress(m) && cfg.IsFork(height, address.ForkEthAddressFormat) {
m = address.FormatEthAddress(addr)
}
if addr == m {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (c *Chain33Config) chain33CfgInit(cfg *Config) {
if c.forks == nil {
c.forks = &Forks{}
}
c.forks.SetTestNetFork()
c.forks.RegisterSystemFork()

if cfg != nil {
if c.isLocal() {
Expand Down
8 changes: 4 additions & 4 deletions types/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
package types

import (
"strings"

"github.com/33cn/chain33/common/address"
"strings"
)

/*
Expand Down Expand Up @@ -115,8 +114,8 @@ func (f *Forks) IsDappFork(height int64, dapp, fork string) bool {
return f.IsFork(height, dapp+"."+fork)
}

// SetTestNetFork bityuan test net fork
func (f *Forks) SetTestNetFork() {
// RegisterSystemFork 注册系统分叉, 部分分叉高度设为测试网分叉值
func (f *Forks) RegisterSystemFork() {
f.SetFork("ForkChainParamV1", 110000)
f.SetFork("ForkChainParamV2", 1692674)
f.SetFork("ForkCheckTxDup", 75260)
Expand All @@ -142,6 +141,7 @@ func (f *Forks) SetTestNetFork() {
f.SetFork("ForkTicketFundAddrV1", 3350000)
f.SetFork("ForkRootHash", 4500000)
f.SetFork(address.ForkFormatAddressKey, 0)
f.SetFork(address.ForkEthAddressFormat, 0)
f.setFork("ForkCheckEthTxSort", 0)
f.setFork("ForkProxyExec", 0)
f.setFork("ForkMaxTxFeeV1", 0)
Expand Down

0 comments on commit ee8af86

Please sign in to comment.