Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evm: add error which triggers if code size deposit exceeds the maximum size #2239

Merged
merged 2 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/evm/src/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,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 @@ -1023,6 +1023,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'
)
})