Skip to content

Commit

Permalink
Merge branch 'master' into monorepo/remove-isTruthy-isFalsy
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrocheleau authored Aug 30, 2022
2 parents 70bdc5a + 2d60261 commit f721b7b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
8 changes: 3 additions & 5 deletions packages/evm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,19 @@ Note that this package atm cannot be run in a standalone mode but needs to be ex

```typescript
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { Blockchain } from '@ethereumjs/blockchain'
import { EEI } from '@ethereumjs/vm'
import { EVM } from '@ethereumjs/evm'
import { DefaultStateManager } from '@ethereumjs/statemanager'

// Note: in a future release there will be an EEI default implementation
// which will ease standalone initialization
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })
const blockchain = await Blockchain.create({ common })
const stateManager = new DefaultStateManager({ common })
const eei = new EEI(stateManager, common, blockchain)

const evm = new EVM({
common,
blockchain,
eei,
eei
})

const STOP = '00'
Expand All @@ -62,7 +59,8 @@ evm
})
.then((results) => {
console.log(`Returned: ${results.returnValue.toString('hex')}`)
console.log(`gasUsed : ${results.gasUsed.toString()}`)
console.log(gasUsed: ${result.executionGasUsed.toString()})

})
.catch(console.error)
```
Expand Down
10 changes: 9 additions & 1 deletion packages/evm/src/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ export class EVM implements EVMInterface {
if (this.DEBUG) {
debug(`Not enough gas or code size not allowed (>= Homestead)`)
}
result = { ...result, ...OOGResult(message.gasLimit) }
result = { ...result, ...CodesizeExceedsMaximumError(message.gasLimit) }
} else {
// we are in Frontier
if (this.DEBUG) {
Expand Down Expand Up @@ -1021,6 +1021,14 @@ export function INVALID_EOF_RESULT(gasLimit: bigint): ExecResult {
}
}

export function CodesizeExceedsMaximumError(gasUsed: bigint): ExecResult {
return {
returnValue: Buffer.alloc(0),
executionGasUsed: gasUsed,
exceptionError: new EvmError(ERROR.CODESIZE_EXCEEDS_MAXIMUM),
}
}

export function EvmErrorResult(error: EvmError, gasUsed: bigint): ExecResult {
return {
returnValue: Buffer.alloc(0),
Expand Down
1 change: 1 addition & 0 deletions packages/evm/src/exceptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum ERROR {
OUT_OF_GAS = 'out of gas',
CODESTORE_OUT_OF_GAS = 'code store out of gas',
CODESIZE_EXCEEDS_MAXIMUM = 'code size to deposit exceeds maximum code size',
STACK_UNDERFLOW = 'stack underflow',
STACK_OVERFLOW = 'stack overflow',
INVALID_JUMP = 'invalid JUMP',
Expand Down
26 changes: 26 additions & 0 deletions packages/evm/tests/runCall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,29 @@ tape('runCall() -> skipBalance behavior', async (t) => {
'runCall reverts when insufficient sender balance and skipBalance is false'
)
})

tape('runCall() => allows to detect for max code size deposit errors', async (t) => {
// setup the accounts for this test
const caller = new Address(Buffer.from('00000000000000000000000000000000000000ee', 'hex')) // caller addres
// setup the evm
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul })
const eei = await getEEI()
const evm = await EVM.create({ common, eei })

// setup the call arguments
const runCallArgs = {
caller, // call address
gasLimit: BigInt(0xffffffffff), // ensure we pass a lot of gas, so we do not run out of gas
// Simple test, PUSH <big number> PUSH 0 RETURN
// It tries to deploy a contract too large, where the code is all zeros
// (since memory which is not allocated/resized to yet is always defaulted to 0)
data: Buffer.from('62FFFFFF6000F3', 'hex'),
}

const result = await evm.runCall(runCallArgs)
t.equal(
result.execResult.exceptionError?.error,
ERROR.CODESIZE_EXCEEDS_MAXIMUM,
'reported error is correct'
)
})

0 comments on commit f721b7b

Please sign in to comment.