Skip to content

Commit f09a36b

Browse files
[VM] TangerineWhistle: fix some SELFDESTRUCT tests
1 parent 6bb93d8 commit f09a36b

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

packages/vm/lib/evm/opFns.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,19 +663,24 @@ export const handlers: { [k: string]: OpHandler } = {
663663

664664
subMemUsage(runState, inOffset, inLength)
665665
subMemUsage(runState, outOffset, outLength)
666-
if (!value.isZero()) {
666+
667+
if (!value.isZero()){
667668
runState.eei.useGas(new BN(runState._common.param('gasPrices', 'callValueTransfer')))
668669
}
669670
gasLimit = maxCallGas(gasLimit, runState.eei.getGasLeft())
670-
671+
671672
let data = Buffer.alloc(0)
672673
if (!inLength.isZero()) {
673674
data = runState.memory.read(inOffset.toNumber(), inLength.toNumber())
674675
}
675676

676677
const empty = await runState.eei.isAccountEmpty(toAddressBuf)
678+
const forkGteSpuriousDragon = runState._common.gteHardfork('spuriousDragon')
679+
677680
if (empty) {
678-
if (!value.isZero()) {
681+
if (!forkGteSpuriousDragon) {
682+
runState.eei.useGas(new BN(runState._common.param('gasPrices', 'callNewAccount')))
683+
} else if (!value.isZero()) {
679684
runState.eei.useGas(new BN(runState._common.param('gasPrices', 'callNewAccount')))
680685
}
681686
}

packages/vm/lib/runTx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
184184
if (results.execResult.selfdestruct) {
185185
const keys = Object.keys(results.execResult.selfdestruct)
186186
for (const k of keys) {
187-
await state.putAccount(Buffer.from(k, 'hex'), new Account())
187+
await state.deleteAccount(Buffer.from(k, 'hex'))
188188
}
189189
}
190190
await state.cleanupTouchedAccounts()

packages/vm/lib/state/interface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export interface StorageDump {
1010
export interface StateManager {
1111
copy(): StateManager
1212
getAccount(address: Buffer): Promise<Account>
13-
putAccount(address: Buffer, account: Account): Promise<void>
13+
putAccount(address: Buffer, account: Account | null): Promise<void>
14+
deleteAccount(address: Buffer): Promise<void>
1415
touchAccount(address: Buffer): void
1516
putContractCode(address: Buffer, value: Buffer): Promise<void>
1617
getContractCode(address: Buffer): Promise<Buffer>

packages/vm/lib/state/stateManager.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ export default class DefaultStateManager implements StateManager {
8787
// if they have money or a non-zero nonce or code, then write to tree
8888
this._cache.put(address, account)
8989
this.touchAccount(address)
90-
// this._trie.put(addressHex, account.serialize(), cb)
90+
}
91+
92+
async deleteAccount(address: Buffer) {
93+
this._cache.del(address)
94+
this.touchAccount(address)
9195
}
9296

9397
/**
@@ -475,6 +479,7 @@ export default class DefaultStateManager implements StateManager {
475479
*/
476480
async accountIsEmpty(address: Buffer): Promise<boolean> {
477481
const account = await this.getAccount(address)
482+
console.log(account.isEmpty())
478483
return account.isEmpty()
479484
}
480485

@@ -484,7 +489,7 @@ export default class DefaultStateManager implements StateManager {
484489
* @param address - Address of the `account` to check
485490
*/
486491
async accountExists(address: Buffer): Promise<boolean> {
487-
const account = await this._cache.getOrLoad(address, false)
492+
const account = await this._trie.get(address)
488493
return account ? true : false
489494
}
490495

0 commit comments

Comments
 (0)