forked from ethereum-optimism/op-geth
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from sircoon4/feature-merkel-trie-proof
- Loading branch information
Showing
9 changed files
with
381 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[ | ||
{ | ||
"Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000020979a00921d42d2ca63e98c1c2ac07f0eacbb99e363b8f2f7f8e4d19c854b6c200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6500000000000000000000000000000000000000000000000000000000000000000000004a6c6c313a006c6e75343a30303030656533323a3edb1a2151507f2c3853e1b3a8039ec5768b22e71c268f49d12addbb6806b3f16e6e6e6e6e6e6e6e6e6e6e6e6e6e6c6e75323a303065650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000575323a3030000000000000000000000000000000000000000000000000000000", | ||
"Expected": "0000000000000000000000000000000000000000000000000000000000000001", | ||
"Name": "sample00", | ||
"Gas": 3000 | ||
}, | ||
{ | ||
"Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000020979a00921d42d2ca63e98c1c2ac07f0eacbb99e363b8f2f7f8e4d19c854b6c200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e650000000000000000000000000000000000000000000000000000000000000000000000010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000575323a3031000000000000000000000000000000000000000000000000000000", | ||
"Expected": "0000000000000000000000000000000000000000000000000000000000000001", | ||
"Name": "sample01", | ||
"Gas": 3000 | ||
}, | ||
{ | ||
"Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000020979a00921d42d2ca63e98c1c2ac07f0eacbb99e363b8f2f7f8e4d19c854b6c200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6500000000000000000000000000000000000000000000000000000000000000000000004a6c6c313a006c6e75343a30303030656533323a3edb1a2151507f2c3853e1b3a8039ec5768b22e71c268f49d12addbb6806b3f16e6e6e6e6e6e6e6e6e6e6e6e6e6e6c6e75323a303065650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000775343a3030303000000000000000000000000000000000000000000000000000", | ||
"Expected": "0000000000000000000000000000000000000000000000000000000000000001", | ||
"Name": "sample0000", | ||
"Gas": 3000 | ||
}, | ||
{ | ||
"Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000003c00000000000000000000000000000000000000000000000000000000000000020979a00921d42d2ca63e98c1c2ac07f0eacbb99e363b8f2f7f8e4d19c854b6c20000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6500000000000000000000000000000000000000000000000000000000000000000000004a6c6c313a006c6e75343a30303030656533323a3edb1a2151507f2c3853e1b3a8039ec5768b22e71c268f49d12addbb6806b3f16e6e6e6e6e6e6e6e6e6e6e6e6e6e6c6e75323a303065650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000286c313a0033323ab16b9db1bce3fedf7dd114b02938f2476c21936a3f30fffecc8db14d377d3dd96500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000276c6e7533323a303030303030303030303030303030303030303030303030303030303030313065000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000247533323a303030303030303030303030303030303030303030303030303030303030313000000000000000000000000000000000000000000000000000000000", | ||
"Expected": "0000000000000000000000000000000000000000000000000000000000000001", | ||
"Name": "sample0010", | ||
"Gas": 3000 | ||
}, | ||
{ | ||
"Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000000206cc5c2ca1b7b146268f0d930c58c7e5441b807e72cf16d56f52c869a594b17bf0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6500000000000000000000000000000000000000000000000000000000000000000000004a6c6c313a006c6e75343a30303030656533323a3edb1a2151507f2c3853e1b3a8039ec5768b22e71c268f49d12addbb6806b3f16e6e6e6e6e6e6e6e6e6e6e6e6e6e6c6e75323a303065650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000575323a3030000000000000000000000000000000000000000000000000000000", | ||
"Expected": "0000000000000000000000000000000000000000000000000000000000000000", | ||
"Name": "sampleFalseHash", | ||
"Gas": 3000 | ||
}, | ||
{ | ||
"Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000020979a00921d42d2ca63e98c1c2ac07f0eacbb99e363b8f2f7f8e4d19c854b6c200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6500000000000000000000000000000000000000000000000000000000000000000000004a6c6c313a006c6e75343a30303030656533323a3edb1a2151507f2c3853e1b3a8039ec5768b22e71c268f49d12addbb6806b3f16e6e6e6e6e6e6e6e6e6e6e6e6e6e6c6e75323a303065650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000575323a3031000000000000000000000000000000000000000000000000000000", | ||
"Expected": "0000000000000000000000000000000000000000000000000000000000000000", | ||
"Name": "sampleFalseValue", | ||
"Gas": 3000 | ||
}, | ||
{ | ||
"Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000020979a00921d42d2ca63e98c1c2ac07f0eacbb99e363b8f2f7f8e4d19c854b6c200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6500000000000000000000000000000000000000000000000000000000000000000000004a6c6c313a006c6e75343a30303030656533323a3edb1a2151507f2c3853e1b3a8039ec5768b22e71c268f49d12addbb6806b3f16e6e6e6e6e6e6e6e6e6e6e6e6e6e6c6e75323a303065650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000575323a3030000000000000000000000000000000000000000000000000000000", | ||
"Expected": "0000000000000000000000000000000000000000000000000000000000000000", | ||
"Name": "sampleFalseKey", | ||
"Gas": 3000 | ||
}, | ||
{ | ||
"Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000020979a00921d42d2ca63e98c1c2ac07f0eacbb99e363b8f2f7f8e4d19c854b6c200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6500000000000000000000000000000000000000000000000000000000000000000000004a6c6c313a006c6e75343a30303030656533323a3edb1a2151507f2c3853e1b3a8039ec5768b22e71c268f49d12addbb6806b3f16e6e6e6e6e6e6e6e6e6e6e6e6e6e6c6e75323a303065650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000575323a3031000000000000000000000000000000000000000000000000000000", | ||
"Expected": "0000000000000000000000000000000000000000000000000000000000000000", | ||
"Name": "sampleFalseProof", | ||
"Gas": 3000 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package libplanet | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/sircoon4/bencodex-go" | ||
) | ||
|
||
type node interface { | ||
name() string | ||
} | ||
|
||
type ( | ||
fullNode struct { | ||
Children [17]node | ||
} | ||
shortNode struct { | ||
Key []byte | ||
Value node | ||
} | ||
hashNode []byte // sha256(bencoded) | ||
valueNode []byte // bencoded | ||
) | ||
|
||
func (n *fullNode) name() string { | ||
return "fullNode" | ||
} | ||
func (n *shortNode) name() string { | ||
return "shortNode" | ||
} | ||
func (n hashNode) name() string { | ||
return "hashNode" | ||
} | ||
func (n valueNode) name() string { | ||
return "valueNode" | ||
} | ||
|
||
func (n *fullNode) GetValue() node { | ||
return n.Children[16] | ||
} | ||
func (n *shortNode) GetValue() node { | ||
return n.Value | ||
} | ||
func (n hashNode) GetValue() []byte { | ||
return n | ||
} | ||
func (n valueNode) GetValue() []byte { | ||
return n | ||
} | ||
|
||
func nodeFromProof(proof []byte) (node, error) { | ||
data, err := bencodex.Decode(proof) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return nodeFromData(data) | ||
} | ||
|
||
func nodeFromData(data any) (node, error) { | ||
if data == nil { | ||
return nil, nil | ||
} | ||
|
||
switch data := data.(type) { | ||
case []byte: | ||
return hashNode(data), nil | ||
case []interface{}: | ||
list := data | ||
if len(list) == 2 { | ||
if list[0] == nil { | ||
value, err := bencodex.Encode(list[1]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return valueNode(value), nil | ||
} else { | ||
value, err := nodeFromData(list[1]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &shortNode{ | ||
Key: list[0].([]byte), | ||
Value: value, | ||
}, nil | ||
} | ||
} else if len(list) == 17 { | ||
children := [17]node{} | ||
for i, child := range list { | ||
var err error | ||
children[i], err = nodeFromData(child) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return &fullNode{ | ||
Children: children, | ||
}, nil | ||
} | ||
default: | ||
return nil, fmt.Errorf("invalid node") | ||
} | ||
|
||
return nil, fmt.Errorf("invalid node") | ||
} |
Oops, something went wrong.