Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
[MPTWG] Deadcode round (#1590)
Browse files Browse the repository at this point in the history
### Description

Remove dead code in MPTWG to improve readability.

### Issue Link


### Type of change

Bug fix (non-breaking change which fixes an issue)


(wait CI update in #1591)
  • Loading branch information
ChihChengLiang authored Sep 14, 2023
1 parent f36df6e commit 1bc1eef
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 539 deletions.
6 changes: 2 additions & 4 deletions mpt-witness-generator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ module github.com/privacy-scaling-explorations/mpt-witness-generator
go 1.16

require (
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
github.com/ethereum/go-ethereum v1.10.8 // indirect
github.com/holiman/uint256 v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
github.com/ethereum/go-ethereum v1.10.8
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
)
25 changes: 17 additions & 8 deletions mpt-witness-generator/go.sum

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2079,196 +2079,6 @@ func TestLeafWithMoreNibbles(t *testing.T) {
oracle.PreventHashingInSecureTrie = false
}

// Note: this requires MockProver with config param 11
/*
func TestNonHashedBranchInBranch(t *testing.T) {
blockNum := 0
blockNumberParent := big.NewInt(int64(blockNum))
blockHeaderParent := oracle.PrefetchBlock(blockNumberParent, true, nil)
database := state.NewDatabase(blockHeaderParent)
statedb, _ := state.New(blockHeaderParent.Root, database, nil)
addr := common.HexToAddress("0x50efbf12580138bc623c95757286df4e24eb81c9")
statedb.DisableLoadingRemoteAccounts()
statedb.CreateAccount(addr)
oracle.PreventHashingInSecureTrie = true // to store the unchanged key
val1 := common.BigToHash(big.NewInt(int64(1)))
key1Hex := "0x1000000000000000000000000000000000000000000000000000000000000000"
key2Hex := "0x2000000000000000000000000000000000000000000000000000000000000000"
key1 := common.HexToHash(key1Hex)
key2 := common.HexToHash(key2Hex)
fmt.Println(key2)
statedb.SetState(addr, key2, val1)
iters := 57 // making the last branch shorter than 32 bytes
for i := 0; i < iters; i++ {
fmt.Println("====")
fmt.Println(key1)
statedb.SetState(addr, key1, val1)
if i == iters - 1 {
break
}
key1Hex = replaceAtIndex(key1Hex, 49, i + 3) // 49 is 1, 50 is 2, ...
key1 = common.HexToHash(key1Hex)
}
statedb.IntermediateRoot(false)
val := common.BigToHash(big.NewInt(int64(17)))
trieMod := TrieModification{
Type: StorageChanged,
Key: key1,
Value: val,
Address: addr,
}
trieModifications := []TrieModification{trieMod}
GenerateProof("NonHashedBranchInBranch", trieModifications, statedb)
oracle.PreventHashingInSecureTrie = false
}
func replaceAtIndex(in string, r rune, i int) string {
out := []rune(in)
out[i] = r
return string(out)
}
// Note: this requires MockProver with config param 11
func TestNonHashedExtensionNodeInBranch(t *testing.T) {
blockNum := 0
blockNumberParent := big.NewInt(int64(blockNum))
blockHeaderParent := oracle.PrefetchBlock(blockNumberParent, true, nil)
database := state.NewDatabase(blockHeaderParent)
statedb, _ := state.New(blockHeaderParent.Root, database, nil)
addr := common.HexToAddress("0x50efbf12580138bc623c95757286df4e24eb81c9")
statedb.DisableLoadingRemoteAccounts()
statedb.CreateAccount(addr)
oracle.PreventHashingInSecureTrie = true // to store the unchanged key
val1 := common.BigToHash(big.NewInt(int64(1)))
key1Hex := "0x1000000000000000000000000000000000000000000000000000000000000000"
key2Hex := "0x2000000000000000000000000000000000000000000000000000000000000000"
key1 := common.HexToHash(key1Hex)
key2 := common.HexToHash(key2Hex)
fmt.Println(key2)
statedb.SetState(addr, key2, val1)
iters := 58 // make the extension node shorter than 32
for i := 0; i < iters; i++ {
statedb.SetState(addr, key1, val1)
if i == iters - 1 {
break
}
makeExtension := false
if i == iters - 2 {
makeExtension = true
}
if !makeExtension {
key1Hex = replaceAtIndex(key1Hex, 49, i + 3)
} else {
key1Hex = replaceAtIndex(key1Hex, 49, i + 1 + 3)
}
key1 = common.HexToHash(key1Hex)
}
statedb.IntermediateRoot(false)
val := common.BigToHash(big.NewInt(int64(17)))
trieMod := TrieModification{
Type: StorageChanged,
Key: key1,
Value: val,
Address: addr,
}
trieModifications := []TrieModification{trieMod}
GenerateProof("NonHashedExtensionNodeInBranch", trieModifications, statedb)
oracle.PreventHashingInSecureTrie = false
}
// Note: this requires MockProver with config param 11
func TestNonHashedExtensionNodeInBranchTwoNibbles(t *testing.T) {
blockNum := 0
blockNumberParent := big.NewInt(int64(blockNum))
blockHeaderParent := oracle.PrefetchBlock(blockNumberParent, true, nil)
database := state.NewDatabase(blockHeaderParent)
statedb, _ := state.New(blockHeaderParent.Root, database, nil)
addr := common.HexToAddress("0x50efbf12580138bc623c95757286df4e24eb81c9")
statedb.DisableLoadingRemoteAccounts()
statedb.CreateAccount(addr)
oracle.PreventHashingInSecureTrie = true // to store the unchanged key
val1 := common.BigToHash(big.NewInt(int64(1)))
key1Hex := "0x1000000000000000000000000000000000000000000000000000000000000000"
key2Hex := "0x2000000000000000000000000000000000000000000000000000000000000000"
key1 := common.HexToHash(key1Hex)
key2 := common.HexToHash(key2Hex)
fmt.Println(key2)
statedb.SetState(addr, key2, val1)
iters := 58 // make the extension node shorter than 32
for i := 0; i < iters; i++ {
statedb.SetState(addr, key1, val1)
if i == iters - 1 {
break
}
makeExtension := false
if i == iters - 2 {
makeExtension = true
}
if !makeExtension {
key1Hex = replaceAtIndex(key1Hex, 49, i + 3)
} else {
key1Hex = replaceAtIndex(key1Hex, 49, i + 2 + 3) // +2 to have two nibbles
}
key1 = common.HexToHash(key1Hex)
}
statedb.IntermediateRoot(false)
val := common.BigToHash(big.NewInt(int64(17)))
trieMod := TrieModification{
Type: StorageChanged,
Key: key1,
Value: val,
Address: addr,
}
trieModifications := []TrieModification{trieMod}
GenerateProof("NonHashedExtensionNodeInBranchTwoNibbles", trieModifications, statedb)
oracle.PreventHashingInSecureTrie = false
}
*/

func TestBranchAfterExtNode(t *testing.T) {
blockNum := 0
blockNumberParent := big.NewInt(int64(blockNum))
Expand Down
Loading

0 comments on commit 1bc1eef

Please sign in to comment.