Skip to content

Commit

Permalink
[VM] TangerineWhistle: fix some SELFDESTRUCT tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Jul 9, 2020
1 parent 6bb93d8 commit f09a36b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
11 changes: 8 additions & 3 deletions packages/vm/lib/evm/opFns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,19 +663,24 @@ export const handlers: { [k: string]: OpHandler } = {

subMemUsage(runState, inOffset, inLength)
subMemUsage(runState, outOffset, outLength)
if (!value.isZero()) {

if (!value.isZero()){
runState.eei.useGas(new BN(runState._common.param('gasPrices', 'callValueTransfer')))
}
gasLimit = maxCallGas(gasLimit, runState.eei.getGasLeft())

let data = Buffer.alloc(0)
if (!inLength.isZero()) {
data = runState.memory.read(inOffset.toNumber(), inLength.toNumber())
}

const empty = await runState.eei.isAccountEmpty(toAddressBuf)
const forkGteSpuriousDragon = runState._common.gteHardfork('spuriousDragon')

if (empty) {
if (!value.isZero()) {
if (!forkGteSpuriousDragon) {
runState.eei.useGas(new BN(runState._common.param('gasPrices', 'callNewAccount')))
} else if (!value.isZero()) {
runState.eei.useGas(new BN(runState._common.param('gasPrices', 'callNewAccount')))
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/lib/runTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
if (results.execResult.selfdestruct) {
const keys = Object.keys(results.execResult.selfdestruct)
for (const k of keys) {
await state.putAccount(Buffer.from(k, 'hex'), new Account())
await state.deleteAccount(Buffer.from(k, 'hex'))
}
}
await state.cleanupTouchedAccounts()
Expand Down
3 changes: 2 additions & 1 deletion packages/vm/lib/state/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export interface StorageDump {
export interface StateManager {
copy(): StateManager
getAccount(address: Buffer): Promise<Account>
putAccount(address: Buffer, account: Account): Promise<void>
putAccount(address: Buffer, account: Account | null): Promise<void>
deleteAccount(address: Buffer): Promise<void>
touchAccount(address: Buffer): void
putContractCode(address: Buffer, value: Buffer): Promise<void>
getContractCode(address: Buffer): Promise<Buffer>
Expand Down
9 changes: 7 additions & 2 deletions packages/vm/lib/state/stateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ export default class DefaultStateManager implements StateManager {
// if they have money or a non-zero nonce or code, then write to tree
this._cache.put(address, account)
this.touchAccount(address)
// this._trie.put(addressHex, account.serialize(), cb)
}

async deleteAccount(address: Buffer) {
this._cache.del(address)
this.touchAccount(address)
}

/**
Expand Down Expand Up @@ -475,6 +479,7 @@ export default class DefaultStateManager implements StateManager {
*/
async accountIsEmpty(address: Buffer): Promise<boolean> {
const account = await this.getAccount(address)
console.log(account.isEmpty())
return account.isEmpty()
}

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

Expand Down

0 comments on commit f09a36b

Please sign in to comment.