Skip to content

Commit ee8af86

Browse files
bysomeonevipwzw
authored andcommitted
[[FIX]] add format eth address fork
1 parent 5de6bc4 commit ee8af86

File tree

11 files changed

+23
-15
lines changed

11 files changed

+23
-15
lines changed

account/account_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ func TestAccountKey(t *testing.T) {
612612

613613
acc := NewCoinsAccount(types.NewChain33Config(types.GetDefaultCfgstring()))
614614
addr := "0x6c0d7BE0d2C8350042890a77393158181716b0d6"
615-
addr1 := address.ToLower(addr)
615+
addr1 := address.FormatEthAddress(addr)
616616
accKey := acc.accountReadKey(addr)
617617
require.Equal(t, accKey, acc.AccountKey(addr))
618618
require.Equal(t, accKey, acc.AccountKey(addr1))

cmd/chain33/chain33.fork.toml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ForkCacheDriver=2580000
2424
ForkTicketFundAddrV1=3350000
2525
ForkRootHash=4500000
2626
ForkFormatAddressKey=0
27+
ForkEthAddressFormat=0
2728
ForkCheckEthTxSort=0
2829
ForkProxyExec=0
2930
ForkMaxTxFeeV1=0

cmd/chain33/chain33.system.fork.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ForkCacheDriver=2580000
2424
ForkTicketFundAddrV1=3350000
2525
ForkRootHash=4500000
2626
ForkFormatAddressKey=0
27+
ForkEthAddressFormat=0
2728
ForkCheckEthTxSort=0
2829
ForkProxyExec=0
29-
ForkMaxTxFeeV1=0
30+
ForkMaxTxFeeV1=0

common/address/util.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ import (
99
// ForkFormatAddressKey 地址key格式化分叉名称,主要针对eth地址
1010
const ForkFormatAddressKey = "ForkFormatAddressKey"
1111

12+
// ForkEthAddressFormat eth地址统一格式化
13+
const ForkEthAddressFormat = "ForkEthAddressFormat"
14+
1215
// IsEthAddress verifies whether a string can represent
1316
// a valid hex-encoded eth address
1417
func IsEthAddress(addr string) bool {
1518
return common.IsHexAddress(addr)
1619
}
1720

18-
// ToLower to lower case string
19-
func ToLower(addr string) string {
21+
// FormatEthAddress eth地址格式化
22+
func FormatEthAddress(addr string) string {
2023
return strings.ToLower(addr)
2124
}
2225

common/address/util_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestFormatAddrKey(t *testing.T) {
1717
addrKey1 := fmt.Sprintf("%s:%s", "addrKey:", FormatAddrKey(addr1))
1818
addrKey2 := fmt.Sprintf("%s:%s", "addrKey:", FormatAddrKey(addr2))
1919

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

2222
require.Equal(t, expect, addrKey1)
2323
require.Equal(t, expect, addrKey2)

system/address/eth/address.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package eth
22

33
import (
44
"errors"
5-
65
"github.com/33cn/chain33/common/crypto/client"
76

87
"github.com/33cn/chain33/common/address"
@@ -82,7 +81,7 @@ func (e *eth) FormatAddr(addr string) string {
8281
func formatAddr(addr string) string {
8382
ctx := client.GetCryptoContext()
8483
if ctx.API == nil || ctx.API.GetConfig().IsFork(ctx.CurrBlockHeight, address.ForkFormatAddressKey) {
85-
return address.ToLower(addr)
84+
return address.FormatEthAddress(addr)
8685
}
8786
return addr
8887
}

system/address/eth/address_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestFormatEthAddr(t *testing.T) {
2929
err = ethDriver.ValidateAddr(ethAddr)
3030
require.Nil(t, err)
3131
addr := ethDriver.PubKeyToAddr(chain33Priv.PubKey().Bytes())
32-
require.Equal(t, address.ToLower(ethAddr), addr)
32+
require.Equal(t, address.FormatEthAddress(ethAddr), addr)
3333
}
3434
require.Equal(t, eth.Name, ethDriver.GetName())
3535
}

system/dapp/manage/executor/exec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (c *Manage) Exec_Modify(manageAction *types.ModifyConfig, tx *types.Transac
4242
}
4343
}
4444
action := newAction(c, tx, int32(index))
45-
if !IsSuperManager(cfg, action.fromaddr) {
45+
if !IsSuperManager(cfg, action.fromaddr, c.GetHeight()) {
4646
return nil, mty.ErrNoPrivilege
4747
}
4848
return action.modifyConfig(manageAction)

system/dapp/manage/executor/manage.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package executor
77

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

5960
// IsSuperManager is supper manager or not
60-
func IsSuperManager(cfg *types.Chain33Config, addr string) bool {
61+
func IsSuperManager(cfg *types.Chain33Config, addr string, height int64) bool {
6162
conf := types.ConfSub(cfg, driverName)
6263
for _, m := range conf.GStrList("superManager") {
64+
if address.IsEthAddress(m) && cfg.IsFork(height, address.ForkEthAddressFormat) {
65+
m = address.FormatEthAddress(addr)
66+
}
6367
if addr == m {
6468
return true
6569
}

types/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (c *Chain33Config) chain33CfgInit(cfg *Config) {
219219
if c.forks == nil {
220220
c.forks = &Forks{}
221221
}
222-
c.forks.SetTestNetFork()
222+
c.forks.RegisterSystemFork()
223223

224224
if cfg != nil {
225225
if c.isLocal() {

types/fork.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
package types
66

77
import (
8-
"strings"
9-
108
"github.com/33cn/chain33/common/address"
9+
"strings"
1110
)
1211

1312
/*
@@ -115,8 +114,8 @@ func (f *Forks) IsDappFork(height int64, dapp, fork string) bool {
115114
return f.IsFork(height, dapp+"."+fork)
116115
}
117116

118-
// SetTestNetFork bityuan test net fork
119-
func (f *Forks) SetTestNetFork() {
117+
// RegisterSystemFork 注册系统分叉, 部分分叉高度设为测试网分叉值
118+
func (f *Forks) RegisterSystemFork() {
120119
f.SetFork("ForkChainParamV1", 110000)
121120
f.SetFork("ForkChainParamV2", 1692674)
122121
f.SetFork("ForkCheckTxDup", 75260)
@@ -142,6 +141,7 @@ func (f *Forks) SetTestNetFork() {
142141
f.SetFork("ForkTicketFundAddrV1", 3350000)
143142
f.SetFork("ForkRootHash", 4500000)
144143
f.SetFork(address.ForkFormatAddressKey, 0)
144+
f.SetFork(address.ForkEthAddressFormat, 0)
145145
f.setFork("ForkCheckEthTxSort", 0)
146146
f.setFork("ForkProxyExec", 0)
147147
f.setFork("ForkMaxTxFeeV1", 0)

0 commit comments

Comments
 (0)