diff --git a/packages/statemanager/src/stateManager.ts b/packages/statemanager/src/stateManager.ts index a3a63791a6..0f4292521f 100644 --- a/packages/statemanager/src/stateManager.ts +++ b/packages/statemanager/src/stateManager.ts @@ -356,9 +356,6 @@ export class DefaultStateManager implements EVMStateManagerInterface { async putContractCode(address: Address, value: Uint8Array): Promise { 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}`) diff --git a/packages/statemanager/test/stateManager.code.spec.ts b/packages/statemanager/test/stateManager.code.spec.ts index b6b128359c..fd5dca0faf 100644 --- a/packages/statemanager/test/stateManager.code.spec.ts +++ b/packages/statemanager/test/stateManager.code.spec.ts @@ -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()) + }) } }) diff --git a/packages/vm/src/runTx.ts b/packages/vm/src/runTx.ts index ccbb5103b7..11c9ccc1f7 100644 --- a/packages/vm/src/runTx.ts +++ b/packages/vm/src/runTx.ts @@ -680,10 +680,6 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise { 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) {