Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
29152875
Commit
29152875
authored
Sep 23, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
the only oracle function is Preimage. the Prefetches are fake
parent
74cec80e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
25 additions
and
57 deletions
+25
-57
database.go
minigeth/core/state/database.go
+4
-2
state_object.go
minigeth/core/state/state_object.go
+2
-3
main.go
minigeth/main.go
+5
-5
proved.go
minigeth/oracle/proved.go
+8
-5
database.go
minigeth/trie/database.go
+2
-36
secure_trie.go
minigeth/trie/secure_trie.go
+4
-4
trie.go
minigeth/trie/trie.go
+0
-2
No files found.
minigeth/core/state/database.go
View file @
29152875
...
...
@@ -27,13 +27,15 @@ func NewDatabase(header types.Header) Database {
// ContractCode retrieves a particular contract's code.
func
(
db
*
Database
)
ContractCode
(
addrHash
common
.
Hash
,
codeHash
common
.
Hash
)
([]
byte
,
error
)
{
code
:=
oracle
.
GetProvedCodeBytes
(
db
.
BlockNumber
,
addrHash
,
codeHash
)
oracle
.
PrefetchCode
(
db
.
BlockNumber
,
addrHash
)
code
:=
oracle
.
Preimage
(
codeHash
)
return
code
,
nil
}
// ContractCodeSize retrieves a particular contracts code's size.
func
(
db
*
Database
)
ContractCodeSize
(
addrHash
common
.
Hash
,
codeHash
common
.
Hash
)
(
int
,
error
)
{
code
:=
oracle
.
GetProvedCodeBytes
(
db
.
BlockNumber
,
addrHash
,
codeHash
)
oracle
.
PrefetchCode
(
db
.
BlockNumber
,
addrHash
)
code
:=
oracle
.
Preimage
(
codeHash
)
return
len
(
code
),
nil
}
...
...
minigeth/core/state/state_object.go
View file @
29152875
...
...
@@ -249,7 +249,6 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
meter
=
&
s
.
db
.
StorageReads
}
oracle
.
PrefetchStorage
(
db
.
BlockNumber
,
s
.
address
,
key
)
fmt
.
Println
(
"get"
,
s
.
address
,
key
)
if
enc
,
err
=
s
.
getTrie
(
db
)
.
TryGet
(
key
.
Bytes
());
err
!=
nil
{
s
.
setError
(
err
)
return
common
.
Hash
{}
...
...
@@ -358,10 +357,10 @@ func (s *stateObject) updateTrie(db Database) Trie {
oracle
.
PrefetchStorage
(
db
.
BlockNumber
,
s
.
address
,
key
)
//oracle.PrefetchStorage(big.NewInt(db.BlockNumber.Int64()+1), s.address, key)
if
(
value
==
common
.
Hash
{})
{
fmt
.
Println
(
"delete"
,
s
.
address
,
key
)
//
fmt.Println("delete", s.address, key)
s
.
setError
(
tr
.
TryDelete
(
key
[
:
]))
}
else
{
fmt
.
Println
(
"update"
,
s
.
address
,
key
,
value
)
//
fmt.Println("update", s.address, key, value)
// Encoding []byte cannot fail, ok to ignore the error.
v
,
_
=
rlp
.
EncodeToBytes
(
common
.
TrimLeftZeroes
(
value
[
:
]))
s
.
setError
(
tr
.
TryUpdate
(
key
[
:
],
v
))
...
...
minigeth/main.go
View file @
29152875
...
...
@@ -66,14 +66,14 @@ func main() {
// if this is correct, the trie is working
// TODO: it's the previous block now
/*if
header.TxHash != block.Header().TxHash {
if
new
header
.
TxHash
!=
block
.
Header
()
.
TxHash
{
panic
(
"wrong transactions for block"
)
}
*/
}
_
,
_
,
_
,
err
:=
processor
.
Process
(
block
,
statedb
,
vmconfig
)
fmt
.
Println
(
err
)
/*outHash, err := statedb.Commit(true
)
fmt.Println(err)*/
if
err
!=
nil
{
panic
(
"processor error"
)
}
fmt
.
Println
(
"process done with hash"
,
header
.
Root
,
"->"
,
block
.
Header
()
.
Root
,
"real"
,
newheader
.
Root
)
}
minigeth/oracle/proved.go
View file @
29152875
...
...
@@ -135,6 +135,12 @@ func PrefetchAddress(blockNumber *big.Int, addr common.Address) {
}
}
func
PrefetchCode
(
blockNumber
*
big
.
Int
,
addrHash
common
.
Hash
)
{
ret
:=
GetProvedCodeBytes
(
blockNumber
,
addrHash
)
hash
:=
crypto
.
Keccak256Hash
(
ret
)
preimages
[
hash
]
=
ret
}
func
GetProofAccount
(
blockNumber
*
big
.
Int
,
addr
common
.
Address
,
skey
common
.
Hash
,
storage
bool
)
[]
string
{
var
key
string
if
storage
{
...
...
@@ -170,10 +176,10 @@ func GetProofAccount(blockNumber *big.Int, addr common.Address, skey common.Hash
return
strings
.
Split
(
string
(
cacheRead
(
key
)),
"
\n
"
)
}
func
GetProvedCodeBytes
(
blockNumber
*
big
.
Int
,
addrHash
common
.
Hash
,
codehash
common
.
Hash
)
[]
byte
{
func
GetProvedCodeBytes
(
blockNumber
*
big
.
Int
,
addrHash
common
.
Hash
)
[]
byte
{
addr
:=
unhash
(
addrHash
)
//fmt.Println("ORACLE GetProvedCodeBytes:", blockNumber, addr, codehash)
key
:=
fmt
.
Sprintf
(
"code_%
s"
,
codehash
)
key
:=
fmt
.
Sprintf
(
"code_%
d_%s"
,
blockNumber
,
addr
)
if
!
cacheExists
(
key
)
{
r
:=
jsonreq
{
Jsonrpc
:
"2.0"
,
Method
:
"eth_getCode"
,
Id
:
1
}
r
.
Params
=
make
([]
interface
{},
2
)
...
...
@@ -197,9 +203,6 @@ func GetProvedCodeBytes(blockNumber *big.Int, addrHash common.Hash, codehash com
ret
,
_
:=
hex
.
DecodeString
(
jr
.
Result
[
2
:
])
//fmt.Println(ret)
if
crypto
.
Keccak256Hash
(
ret
)
!=
codehash
{
panic
(
"wrong code hash"
)
}
cacheWrite
(
key
,
ret
)
}
...
...
minigeth/trie/database.go
View file @
29152875
...
...
@@ -28,37 +28,6 @@ type Database struct {
BlockNumber
*
big
.
Int
Root
common
.
Hash
lock
sync
.
RWMutex
preimages
map
[
common
.
Hash
][]
byte
// Preimages of nodes from the secure trie
preimagesSize
common
.
StorageSize
// Storage size of the preimages cache
}
// insertPreimage writes a new trie node pre-image to the memory database if it's
// yet unknown. The method will NOT make a copy of the slice,
// only use if the preimage will NOT be changed later on.
//
// Note, this method assumes that the database's lock is held!
func
(
db
*
Database
)
insertPreimage
(
hash
common
.
Hash
,
preimage
[]
byte
)
{
// Short circuit if preimage collection is disabled
if
db
.
preimages
==
nil
{
return
}
// Track the preimage if a yet unknown one
if
_
,
ok
:=
db
.
preimages
[
hash
];
ok
{
return
}
db
.
preimages
[
hash
]
=
preimage
db
.
preimagesSize
+=
common
.
StorageSize
(
common
.
HashLength
+
len
(
preimage
))
}
// preimage retrieves a cached trie node pre-image from memory. If it cannot be
// found cached, the method queries the persistent database for the content.
func
(
db
*
Database
)
preimage
(
hash
common
.
Hash
)
[]
byte
{
// Short circuit if preimage collection is disabled
if
db
.
preimages
==
nil
{
return
nil
}
return
db
.
preimages
[
hash
]
}
func
NewDatabase
(
header
types
.
Header
)
Database
{
...
...
@@ -74,9 +43,7 @@ func NewDatabase(header types.Header) Database {
// Node retrieves an encoded cached trie node from memory. If it cannot be found
// cached, the method queries the persistent database for the content.
func
(
db
*
Database
)
Node
(
hash
common
.
Hash
)
([]
byte
,
error
)
{
/*fmt.Println("trie Node", hash)
return []byte{}, nil*/
panic
(
"no Node"
)
panic
(
"no Node function"
)
}
// node retrieves a cached trie node from memory, or returns nil if none can be
...
...
@@ -91,7 +58,6 @@ func (db *Database) node(hash common.Hash) node {
// All nodes inserted by this function will be reference tracked
// and in theory should only used for **trie nodes** insertion.
func
(
db
*
Database
)
insert
(
hash
common
.
Hash
,
size
int
,
node
node
)
{
//panic("insert")
//fmt.Println("insert", hash, size)
// can put things in the oracle here if we care
//fmt.Println("insert", hash, size)
}
minigeth/trie/secure_trie.go
View file @
29152875
...
...
@@ -132,12 +132,12 @@ func (t *SecureTrie) TryDelete(key []byte) error {
// GetKey returns the sha3 preimage of a hashed key that was
// previously used to store a value.
func
(
t
*
SecureTrie
)
GetKey
(
shaKey
[]
byte
)
[]
byte
{
/*
func (t *SecureTrie) GetKey(shaKey []byte) []byte {
if key, ok := t.getSecKeyCache()[string(shaKey)]; ok {
return key
}
return t.trie.db.preimage(common.BytesToHash(shaKey))
}
}
*/
// Commit writes all nodes and the secure hash pre-images to the trie's database.
// Nodes are stored with their sha3 hash as the key.
...
...
@@ -146,7 +146,7 @@ func (t *SecureTrie) GetKey(shaKey []byte) []byte {
// from the database.
func
(
t
*
SecureTrie
)
Commit
(
onleaf
LeafCallback
)
(
root
common
.
Hash
,
err
error
)
{
// Write all the pre-images to the actual disk database
if
len
(
t
.
getSecKeyCache
())
>
0
{
/*
if len(t.getSecKeyCache()) > 0 {
if t.trie.db.preimages != nil { // Ugly direct check but avoids the below write lock
t.trie.db.lock.Lock()
for hk, key := range t.secKeyCache {
...
...
@@ -155,7 +155,7 @@ func (t *SecureTrie) Commit(onleaf LeafCallback) (root common.Hash, err error) {
t.trie.db.lock.Unlock()
}
t.secKeyCache = make(map[string][]byte)
}
}
*/
// Commit the trie to its intermediate node database
return
t
.
trie
.
Commit
(
onleaf
)
}
...
...
minigeth/trie/trie.go
View file @
29152875
...
...
@@ -368,7 +368,6 @@ func (t *Trie) TryDelete(key []byte) error {
func
(
t
*
Trie
)
delete
(
n
node
,
prefix
,
key
[]
byte
)
(
bool
,
node
,
error
)
{
switch
n
:=
n
.
(
type
)
{
case
*
shortNode
:
fmt
.
Println
(
"delete shortNode"
,
prefix
,
key
,
n
.
Key
,
n
.
Val
)
matchlen
:=
prefixLen
(
key
,
n
.
Key
)
if
matchlen
<
len
(
n
.
Key
)
{
return
false
,
n
,
nil
// don't replace n on mismatch
...
...
@@ -398,7 +397,6 @@ func (t *Trie) delete(n node, prefix, key []byte) (bool, node, error) {
}
case
*
fullNode
:
fmt
.
Println
(
"delete fullNode"
,
prefix
,
key
)
dirty
,
nn
,
err
:=
t
.
delete
(
n
.
Children
[
key
[
0
]],
append
(
prefix
,
key
[
0
]),
key
[
1
:
])
if
!
dirty
||
err
!=
nil
{
return
false
,
n
,
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment