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
Show file tree
Hide file tree
Changes from 30 commits
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
4 changes: 3 additions & 1 deletion config/cspell-ts.json
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@
"patarapolw",
"nickdodson",
"Kintsugi",
"deauthorization"
"deauthorization",
"PUSHDATA",
"chunkified"
]
}
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/common/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export interface StorageRange {
nextKey: string | null
}

export type AccountFields = Partial<Pick<Account, 'nonce' | 'balance' | 'storageRoot' | 'codeHash'>>
export type AccountFields = Partial<
Pick<Account, 'nonce' | 'balance' | 'storageRoot' | 'codeHash' | 'codeSize'>
>

export type StorageProof = {
key: PrefixedHexString
Expand Down
44 changes: 44 additions & 0 deletions packages/evm/test/verkle.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import { AccessWitness, StatefulVerkleStateManager } from '@ethereumjs/statemanager'
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'

import { createEVM } from '../src/index.js'

import type { VerkleCrypto } from '@ethereumjs/util'

describe('verkle tests', () => {
let verkleCrypto: VerkleCrypto
beforeAll(async () => {
verkleCrypto = await loadVerkleCrypto()
})
it('should execute bytecode and update the state', async () => {
const common = new Common({ chain: Mainnet, eips: [6800], hardfork: Hardfork.Cancun })
const trie = await createVerkleTree()
const sm = new StatefulVerkleStateManager({ trie, verkleCrypto })
const address = createAddressFromString('0x9e5ef720fa2cdfa5291eb7e711cfd2e62196f4b3')
const account = createAccount({ nonce: 3n, balance: 0xffffffffn })
await sm.putAccount(address, account)
const evm = await createEVM({ common, stateManager: sm })
const code = hexToBytes('0x6001600255')
const accessWitness = new AccessWitness({ verkleCrypto })
const res = await evm.runCall({
gabrocheleau marked this conversation as resolved.
Show resolved Hide resolved
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())
console.log(res.execResult.runState?.interpreter._env.accessWitness)
acolytec3 marked this conversation as resolved.
Show resolved Hide resolved
const retrievedValue = await sm.getStorage(address, setLengthLeft(bigIntToBytes(2n), 32))
assert.deepEqual(retrievedValue, bigIntToBytes(1n))
})
})
1 change: 1 addition & 0 deletions packages/statemanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@ethereumjs/rlp": "^5.0.2",
"@ethereumjs/trie": "^6.2.1",
"@ethereumjs/util": "^9.1.0",
"@ethereumjs/verkle": "^0.1.0",
"@js-sdsl/ordered-map": "^4.4.2",
"debug": "^4.3.3",
"ethereum-cryptography": "^2.2.1",
Expand Down
1 change: 1 addition & 0 deletions packages/statemanager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './accessWitness.js'
export * from './cache/index.js'
export * from './rpcStateManager.js'
export * from './simpleStateManager.js'
export * from './statefulVerkleStateManager.js'
export * from './statelessVerkleStateManager.js'
export * from './stateManager.js'
export * from './types.js'
Loading
Loading