forked from cerc-io/plugeth
core/state, light, les: make signature of ContractCode hash-independent (#27209)
* core/state, light, les: make signature of ContractCode hash-independent * push current state for feedback * les: fix unit test * core, les, light: fix les unittests * core/state, trie, les, light: fix state iterator * core, les: address comments * les: fix lint --------- Co-authored-by: Gary Rong <garyrong0905@gmail.com>
This commit is contained in:
co-authored by
Gary Rong
parent
85b8d1c06c
commit
8bbb16b70e
@@ -45,9 +45,9 @@ var (
|
||||
testChainLen = 256
|
||||
testContractCode = common.Hex2Bytes("606060405260cc8060106000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360cd2685146041578063c16431b914606b57603f565b005b6055600480803590602001909190505060a9565b6040518082815260200191505060405180910390f35b60886004808035906020019091908035906020019091905050608a565b005b80600060005083606481101560025790900160005b50819055505b5050565b6000600060005082606481101560025790900160005b5054905060c7565b91905056")
|
||||
|
||||
chain *core.BlockChain
|
||||
addrHashes []common.Hash
|
||||
txHashes []common.Hash
|
||||
chain *core.BlockChain
|
||||
addresses []common.Address
|
||||
txHashes []common.Hash
|
||||
|
||||
chtTrie *trie.Trie
|
||||
bloomTrie *trie.Trie
|
||||
@@ -55,7 +55,7 @@ var (
|
||||
bloomKeys [][]byte
|
||||
)
|
||||
|
||||
func makechain() (bc *core.BlockChain, addrHashes, txHashes []common.Hash) {
|
||||
func makechain() (bc *core.BlockChain, addresses []common.Address, txHashes []common.Hash) {
|
||||
gspec := &core.Genesis{
|
||||
Config: params.TestChainConfig,
|
||||
Alloc: core.GenesisAlloc{bankAddr: {Balance: bankFunds}},
|
||||
@@ -77,7 +77,7 @@ func makechain() (bc *core.BlockChain, addrHashes, txHashes []common.Hash) {
|
||||
tx, _ = types.SignTx(types.NewTransaction(nonce, addr, big.NewInt(10000), params.TxGas, big.NewInt(params.GWei), nil), signer, bankKey)
|
||||
}
|
||||
gen.AddTx(tx)
|
||||
addrHashes = append(addrHashes, crypto.Keccak256Hash(addr[:]))
|
||||
addresses = append(addresses, addr)
|
||||
txHashes = append(txHashes, tx.Hash())
|
||||
})
|
||||
bc, _ = core.NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
|
||||
@@ -107,7 +107,7 @@ func makeTries() (chtTrie *trie.Trie, bloomTrie *trie.Trie, chtKeys, bloomKeys [
|
||||
}
|
||||
|
||||
func init() {
|
||||
chain, addrHashes, txHashes = makechain()
|
||||
chain, addresses, txHashes = makechain()
|
||||
chtTrie, bloomTrie, chtKeys, bloomKeys = makeTries()
|
||||
}
|
||||
|
||||
@@ -116,7 +116,8 @@ type fuzzer struct {
|
||||
pool *txpool.TxPool
|
||||
|
||||
chainLen int
|
||||
addr, txs []common.Hash
|
||||
addresses []common.Address
|
||||
txs []common.Hash
|
||||
nonce uint64
|
||||
|
||||
chtKeys [][]byte
|
||||
@@ -135,7 +136,7 @@ func newFuzzer(input []byte) *fuzzer {
|
||||
return &fuzzer{
|
||||
chain: chain,
|
||||
chainLen: testChainLen,
|
||||
addr: addrHashes,
|
||||
addresses: addresses,
|
||||
txs: txHashes,
|
||||
chtTrie: chtTrie,
|
||||
bloomTrie: bloomTrie,
|
||||
@@ -198,12 +199,12 @@ func (f *fuzzer) randomBlockHash() common.Hash {
|
||||
return common.BytesToHash(f.read(common.HashLength))
|
||||
}
|
||||
|
||||
func (f *fuzzer) randomAddrHash() []byte {
|
||||
i := f.randomInt(3 * len(f.addr))
|
||||
if i < len(f.addr) {
|
||||
return f.addr[i].Bytes()
|
||||
func (f *fuzzer) randomAddress() []byte {
|
||||
i := f.randomInt(3 * len(f.addresses))
|
||||
if i < len(f.addresses) {
|
||||
return f.addresses[i].Bytes()
|
||||
}
|
||||
return f.read(common.HashLength)
|
||||
return f.read(common.AddressLength)
|
||||
}
|
||||
|
||||
func (f *fuzzer) randomCHTTrieKey() []byte {
|
||||
@@ -315,8 +316,8 @@ func Fuzz(input []byte) int {
|
||||
req := &l.GetCodePacket{Reqs: make([]l.CodeReq, f.randomInt(l.MaxCodeFetch+1))}
|
||||
for i := range req.Reqs {
|
||||
req.Reqs[i] = l.CodeReq{
|
||||
BHash: f.randomBlockHash(),
|
||||
AccKey: f.randomAddrHash(),
|
||||
BHash: f.randomBlockHash(),
|
||||
AccountAddress: f.randomAddress(),
|
||||
}
|
||||
}
|
||||
f.doFuzz(l.GetCodeMsg, req)
|
||||
@@ -333,15 +334,15 @@ func Fuzz(input []byte) int {
|
||||
for i := range req.Reqs {
|
||||
if f.randomBool() {
|
||||
req.Reqs[i] = l.ProofReq{
|
||||
BHash: f.randomBlockHash(),
|
||||
AccKey: f.randomAddrHash(),
|
||||
Key: f.randomAddrHash(),
|
||||
FromLevel: uint(f.randomX(3)),
|
||||
BHash: f.randomBlockHash(),
|
||||
AccountAddress: f.randomAddress(),
|
||||
Key: f.randomAddress(),
|
||||
FromLevel: uint(f.randomX(3)),
|
||||
}
|
||||
} else {
|
||||
req.Reqs[i] = l.ProofReq{
|
||||
BHash: f.randomBlockHash(),
|
||||
Key: f.randomAddrHash(),
|
||||
Key: f.randomAddress(),
|
||||
FromLevel: uint(f.randomX(3)),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user