Skip to content

Commit

Permalink
Fix statemanager empty code bug (#3483)
Browse files Browse the repository at this point in the history
* common/tx: implement EIP7702

* tx: add 7702 cap and update authority checks

* vm: add 7702 support

* tx: add 7702 tests

* client: fix build

* evm: support 7702

* vm: add basic 7702 test and fix decoding auth list

* vm: add specific eip-161 test

* vm: bump 7702 test coverage with one passing test

* vm: add more 7702 tests

* vm: add extra 7702 tests

* tx: address feedback

* vm: address review

* vm: add 7702 test to check for empty code (fails)

* vm: fix 7702 empty code clearing

* add 7702 type to tx factory constructors

* add 7702 test to runBlock test

* vm: comment 7702 test

* stateManager: fix bug by putting empty code on an existing account

* vm: 7702: remove modifyAccountFields

* vm: remove .only from runBlock test

* vm: remove runBlock .only

---------

Co-authored-by: acolytec3 <17355484+acolytec3@users.noreply.github.com>
Co-authored-by: Scotty <66335769+ScottyPoi@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 4, 2024
1 parent 8d5bca0 commit 3171920
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 0 additions & 3 deletions packages/statemanager/src/stateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,6 @@ export class DefaultStateManager implements EVMStateManagerInterface {
async putContractCode(address: Address, value: Uint8Array): Promise<void> {
this._codeCache?.put(address, value)
const codeHash = this.keccakFunction(value)
if (equalsBytes(codeHash, KECCAK256_NULL)) {
return
}

if (this.DEBUG) {
this._debug(`Update codeHash (-> ${short(codeHash)}) for account ${address}`)
Expand Down
10 changes: 10 additions & 0 deletions packages/statemanager/test/stateManager.code.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,15 @@ describe('StateManager -> Code', () => {
assert.ok(true, 'successfully threw')
}
})

it('putContractCode with empty code on existing address should correctly propagate', async () => {
const stateManager = new DefaultStateManager()
const address = Address.zero()
await stateManager.putContractCode(address, new Uint8Array([1]))
await stateManager.putContractCode(address, new Uint8Array())
const account = await stateManager.getAccount(address)
assert.ok(account !== undefined)
assert.ok(account?.isEmpty())
})
}
})
4 changes: 0 additions & 4 deletions packages/vm/src/runTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,6 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
for (const str of writtenAddresses) {
const address = Address.fromString(str)
await this.stateManager.putContractCode(address, new Uint8Array())
// TODO verify if this is necessary
// `putContractCode` will not `modifyAccountFields` if one tries to put empty code
// So explicitly add this here - does this have side effects?
await this.stateManager.modifyAccountFields(address, { codeHash: KECCAK256_NULL })
}

if (enableProfiler) {
Expand Down

0 comments on commit 3171920

Please sign in to comment.