Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add statefulVerkleStateManager #3628

Merged
merged 44 commits into from
Sep 10, 2024
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a847f86
scaffolding
acolytec3 Aug 28, 2024
107c883
broken WIP
acolytec3 Aug 28, 2024
78f1990
partial implementations
acolytec3 Aug 29, 2024
9cf5af7
fix getAccount
acolytec3 Aug 29, 2024
1419c9d
add todo
acolytec3 Aug 29, 2024
bb25fea
make trie.get accept suffixes
acolytec3 Aug 29, 2024
8c0605c
clean up reference
acolytec3 Aug 30, 2024
ef37d62
Add reserved bytes to encodeBasicData function
acolytec3 Aug 31, 2024
adad631
FIx encoding again
acolytec3 Sep 3, 2024
e69001c
spelling [no ci]
acolytec3 Sep 3, 2024
053fdea
change param to account [no ci]
acolytec3 Sep 3, 2024
762a694
Add support for basic account delete
acolytec3 Sep 3, 2024
293c86a
implement chunkify code
acolytec3 Sep 3, 2024
f6bbd1f
Add putCode
acolytec3 Sep 3, 2024
1d148ed
Move code to helpers
acolytec3 Sep 3, 2024
daa5faf
getCode and getCodeSize
acolytec3 Sep 4, 2024
036fa67
Start work on tests
acolytec3 Sep 4, 2024
d4e10dd
Update magic numbers to constants
acolytec3 Sep 4, 2024
e006237
Make get/putCode work
acolytec3 Sep 4, 2024
680ec51
Fix various get/putCode bugs
acolytec3 Sep 4, 2024
c7047fd
add get/putstorage
acolytec3 Sep 4, 2024
9161e02
export SFVKSM [no ci]
acolytec3 Sep 5, 2024
31fa232
Merge remote-tracking branch 'origin/master' into statefulVerkleState…
acolytec3 Sep 5, 2024
15e1d76
add commit/flush/revert
acolytec3 Sep 5, 2024
78ba172
Tests for caching
acolytec3 Sep 5, 2024
1f5e39f
make cspell happy
acolytec3 Sep 5, 2024
95b51e3
lint
acolytec3 Sep 5, 2024
04be4c6
add back missing method from interface
acolytec3 Sep 5, 2024
8b7d4b1
Merge remote-tracking branch 'origin/master' into statefulVerkleState…
acolytec3 Sep 6, 2024
3dc9346
Update packages/util/test/verkle.spec.ts
gabrocheleau Sep 8, 2024
f9d0825
Apply suggestions from code review
gabrocheleau Sep 8, 2024
1a8bd79
address some feedback
acolytec3 Sep 8, 2024
76316cb
Merge remote-tracking branch 'origin/master' into statefulVerkleState…
acolytec3 Sep 8, 2024
54c30c5
Update types and add test
acolytec3 Sep 6, 2024
f6e89ec
FIx commitment format
acolytec3 Sep 6, 2024
f4922c3
Update verkle crypto and add proof test
acolytec3 Sep 9, 2024
9f94d7d
add max chunks constant
acolytec3 Sep 9, 2024
36ac903
delete account in put if no account
acolytec3 Sep 9, 2024
6af9a3f
spelling
acolytec3 Sep 9, 2024
0133cc1
fix basic data encoding offsets
acolytec3 Sep 9, 2024
7c346df
remove console log
acolytec3 Sep 9, 2024
b97e813
Fix suffix logic
acolytec3 Sep 9, 2024
6a810fc
Merge remote-tracking branch 'origin/master' into statefulVerkleState…
acolytec3 Sep 10, 2024
48ba734
Apply feedback
acolytec3 Sep 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add commit/flush/revert
Rate limit · GitHub

Access has been restricted

You have triggered a rate limit.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

acolytec3 committed Sep 5, 2024
commit 15e1d7647adf05e0f407f988e74e92568803c9f7
19 changes: 16 additions & 3 deletions packages/evm/test/verkle.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import { AccessWitness, StatefulVerkleStateManager } from '@ethereumjs/statemanager'
import { createAccount, createAddressFromString, hexToBytes } from '@ethereumjs/util'
import {
bigIntToBytes,
createAccount,
createAddressFromString,
hexToBytes,
setLengthLeft,
} from '@ethereumjs/util'
import { createVerkleTree } from '@ethereumjs/verkle'
import { loadVerkleCrypto } from 'verkle-cryptography-wasm'
import { assert, beforeAll, describe, it } from 'vitest'
@@ -24,7 +30,14 @@ describe('verkle tests', () => {
const evm = await createEVM({ common, stateManager: sm })
const code = hexToBytes('0x6001600255')
const accessWitness = new AccessWitness({ verkleCrypto })
const res = await evm.runCall({ code, caller: address, accessWitness })
assert.equal(res.execResult.returnValue, new Uint8Array())
const res = await evm.runCall({
code,
caller: address,
accessWitness,
to: createAddressFromString(address.toString()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
to: createAddressFromString(address.toString()),
to: address,

})
assert.deepEqual(res.execResult.returnValue, new Uint8Array())
const retrievedValue = await sm.getStorage(address, setLengthLeft(bigIntToBytes(2n), 32))
assert.deepEqual(retrievedValue, bigIntToBytes(1n))
})
})
70 changes: 66 additions & 4 deletions packages/statemanager/src/statefulVerkleStateManager.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import {
bytesToBigInt,
chunkifyCode,
createAccountFromRLP,
createAddressFromString,
createPartialAccount,
decodeVerkleLeafBasicData,
encodeVerkleLeafBasicData,
@@ -23,6 +24,7 @@ import {
hexToBytes,
short,
unpadBytes,
unprefixedHexToBytes,
} from '@ethereumjs/util'
import { VerkleTree } from '@ethereumjs/verkle'
import debugDefault from 'debug'
@@ -364,12 +366,72 @@ export class StatefulVerkleStateManager implements StateManagerInterface {
this._caches?.checkpoint()
this._checkpointCount++
}
commit(): Promise<void> {
throw new Error('Method not implemented.')
commit = async (): Promise<void> => {
await this._trie.commit()
this._caches?.commit()
this._checkpointCount--

if (this._checkpointCount === 0) {
await this.flush()
this.originalStorageCache.clear()
}

if (this.DEBUG) {
this._debug(`state checkpoint committed`)
}
}
revert(): Promise<void> {
throw new Error('Method not implemented.')
revert = async (): Promise<void> => {
await this._trie.revert()
this._caches?.revert()

this._checkpointCount--

if (this._checkpointCount === 0) {
await this.flush()
this.originalStorageCache.clear()
}
}

flush = async (): Promise<void> => {
const codeItems = this._caches?.code?.flush() ?? []
for (const item of codeItems) {
const addr = createAddressFromString(`0x${item[0]}`)

const code = item[1].code
if (code === undefined) {
continue
}

await this.putCode(addr, code)
}

const storageItems = this._caches?.storage?.flush() ?? []
for (const item of storageItems) {
const address = createAddressFromString(`0x${item[0]}`)
const keyHex = item[1]
const keyBytes = unprefixedHexToBytes(keyHex)
const value = item[2]

const decoded = RLP.decode(value ?? new Uint8Array(0)) as Uint8Array
const account = await this.getAccount(address)
if (account) {
await this.putStorage(address, keyBytes, decoded)
}
}

const accountItems = this._caches?.account?.flush() ?? []
for (const item of accountItems) {
const address = createAddressFromString(item[0])
const elem = item[1]
if (elem.accountRLP === undefined) {
await this.deleteAccount(address)
} else {
const account = createAccountFromRLP(elem.accountRLP)
await this.putAccount(address, account)
}
}
}

getStateRoot(): Promise<Uint8Array> {
throw new Error('Method not implemented.')
}