Skip to content

Commit

Permalink
Merge pull request #3153 from NomicFoundation/upgrade-ethereumjs-fork
Browse files Browse the repository at this point in the history
Upgrade ethereumjs fork
  • Loading branch information
alcuadrado authored Sep 14, 2022
2 parents d377c39 + 191c8eb commit 34e8416
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 143 deletions.
5 changes: 5 additions & 0 deletions .changeset/weak-suns-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hardhat": patch
---

Improved the way we detect errors related to deploying contracts with a code that is too large.
20 changes: 10 additions & 10 deletions packages/hardhat-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@
"dependencies": {
"@ethersproject/abi": "^5.1.2",
"@metamask/eth-sig-util": "^4.0.0",
"@nomicfoundation/ethereumjs-block": "^4.0.0-rc.3",
"@nomicfoundation/ethereumjs-blockchain": "^6.0.0-rc.3",
"@nomicfoundation/ethereumjs-common": "^3.0.0-rc.3",
"@nomicfoundation/ethereumjs-evm": "^1.0.0-rc.3",
"@nomicfoundation/ethereumjs-rlp": "^4.0.0-rc.3",
"@nomicfoundation/ethereumjs-statemanager": "^1.0.0-rc.3",
"@nomicfoundation/ethereumjs-trie": "^5.0.0-rc.3",
"@nomicfoundation/ethereumjs-tx": "^4.0.0-rc.3",
"@nomicfoundation/ethereumjs-util": "^8.0.0-rc.3",
"@nomicfoundation/ethereumjs-vm": "^6.0.0-rc.3",
"@nomicfoundation/ethereumjs-block": "^4.0.0",
"@nomicfoundation/ethereumjs-blockchain": "^6.0.0",
"@nomicfoundation/ethereumjs-common": "^3.0.0",
"@nomicfoundation/ethereumjs-evm": "^1.0.0",
"@nomicfoundation/ethereumjs-rlp": "^4.0.0",
"@nomicfoundation/ethereumjs-statemanager": "^1.0.0",
"@nomicfoundation/ethereumjs-trie": "^5.0.0",
"@nomicfoundation/ethereumjs-tx": "^4.0.0",
"@nomicfoundation/ethereumjs-util": "^8.0.0",
"@nomicfoundation/ethereumjs-vm": "^6.0.0",
"@nomicfoundation/solidity-analyzer": "^0.0.3",
"@sentry/node": "^5.18.1",
"@types/bn.js": "^5.1.0",
Expand Down
28 changes: 10 additions & 18 deletions packages/hardhat-core/src/internal/hardhat-network/provider/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ import {
encodeSolidityStackTrace,
SolidityError,
} from "../stack-traces/solidity-errors";
import {
SolidityStackTrace,
StackTraceEntryType,
} from "../stack-traces/solidity-stack-trace";
import { SolidityStackTrace } from "../stack-traces/solidity-stack-trace";
import { SolidityTracer } from "../stack-traces/solidityTracer";
import { VMDebugTracer } from "../stack-traces/vm-debug-tracer";
import { VmTraceDecoder } from "../stack-traces/vm-trace-decoder";
Expand Down Expand Up @@ -1821,7 +1818,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
receipts,
stateRoot: block.header.stateRoot,
logsBloom: block.header.logsBloom,
receiptRoot: block.header.receiptTrie,
receiptsRoot: block.header.receiptTrie,
gasUsed: block.header.gasUsed,
},
traces,
Expand Down Expand Up @@ -1947,11 +1944,8 @@ Hardhat Network's forking functionality only works with blocks from at least spu
throw error;
}

if (error.error === ERROR.OUT_OF_GAS) {
if (
stackTrace !== undefined &&
this._isContractTooLargeStackTrace(stackTrace)
) {
if (error.error === ERROR.CODESIZE_EXCEEDS_MAXIMUM) {
if (stackTrace !== undefined) {
return encodeSolidityStackTrace(
"Transaction ran out of gas",
stackTrace
Expand All @@ -1961,6 +1955,12 @@ Hardhat Network's forking functionality only works with blocks from at least spu
return new TransactionExecutionError("Transaction ran out of gas");
}

if (error.error === ERROR.OUT_OF_GAS) {
// if the error is an out of gas, we ignore the inferred error in the
// trace
return new TransactionExecutionError("Transaction ran out of gas");
}

const returnData = new ReturnData(vmResult.returnValue);

let returnDataExplanation;
Expand Down Expand Up @@ -1997,14 +1997,6 @@ Hardhat Network's forking functionality only works with blocks from at least spu
);
}

private _isContractTooLargeStackTrace(stackTrace: SolidityStackTrace) {
return (
stackTrace.length > 0 &&
stackTrace[stackTrace.length - 1].type ===
StackTraceEntryType.CONTRACT_TOO_LARGE_ERROR
);
}

private _calculateTimestampAndOffset(
timestamp?: bigint
): [bigint, boolean, bigint] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ const FIRST_SOLC_VERSION_CREATE_PARAMS_VALIDATION = "0.5.9";
const FIRST_SOLC_VERSION_RECEIVE_FUNCTION = "0.6.0";
const FIRST_SOLC_VERSION_WITH_UNMAPPED_REVERTS = "0.6.3";

const EIP170_BYTECODE_SIZE_INCLUSIVE_LIMIT = 0x6000;

export interface SubmessageData {
messageTrace: MessageTrace;
stacktrace: SolidityStackTrace;
Expand Down Expand Up @@ -1376,34 +1374,7 @@ export class ErrorInferrer {
}

private _isContractTooLargeError(trace: DecodedCreateMessageTrace) {
if (trace.error === undefined || trace.error.error !== ERROR.OUT_OF_GAS) {
return false;
}

// This error doesn't come from solidity, but actually from the VM.
// The deployment code executes correctly, but it OOGs.
const lastStep = trace.steps[trace.steps.length - 1];
if (!isEvmStep(lastStep)) {
return false;
}

const lastInst = trace.bytecode.getInstruction(lastStep.pc);
if (lastInst.opcode !== Opcode.RETURN) {
return false;
}

// TODO: This is an over approximation, as we should be comparing the
// runtime bytecode.
if (
trace.bytecode.normalizedCode.length <=
EIP170_BYTECODE_SIZE_INCLUSIVE_LIMIT
) {
return false;
}

// TODO: What happens if it's an actual out of gas that OOGs at the return?
// maybe traces should have gasLimit and gasUsed.
return true;
return trace.error?.error === ERROR.CODESIZE_EXCEEDS_MAXIMUM;
}

private _solidity063CorrectLineNumber(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ function encodeStackTraceEntry(
case StackTraceEntryType.CALL_FAILED_ERROR:
case StackTraceEntryType.DIRECT_LIBRARY_CALL_ERROR:
case StackTraceEntryType.UNMAPPED_SOLC_0_6_3_REVERT_ERROR:
case StackTraceEntryType.CONTRACT_TOO_LARGE_ERROR:
return sourceReferenceToSolidityCallsite(stackTraceEntry.sourceReference);

case StackTraceEntryType.UNRECOGNIZED_CREATE_CALLSTACK_ENTRY:
Expand Down Expand Up @@ -188,6 +187,7 @@ function encodeStackTraceEntry(
);

case StackTraceEntryType.OTHER_EXECUTION_ERROR:
case StackTraceEntryType.CONTRACT_TOO_LARGE_ERROR:
if (stackTraceEntry.sourceReference === undefined) {
return new SolidityCallSite(
undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export interface OtherExecutionErrorStackTraceEntry {

export interface ContractTooLargeErrorStackTraceEntry {
type: StackTraceEntryType.CONTRACT_TOO_LARGE_ERROR;
sourceReference: SourceReference;
sourceReference?: SourceReference;
}

export interface InternalFunctionCallStackEntry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ export class SolidityTracer {
}
}

if (trace.error?.error === ERROR.CODESIZE_EXCEEDS_MAXIMUM) {
return [
{
type: StackTraceEntryType.CONTRACT_TOO_LARGE_ERROR,
},
];
}

const isInvalidOpcodeError = trace.error?.error === ERROR.INVALID_OPCODE;

if (isCreateTrace(trace)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("Hardhat Network special options", function () {
data: CONTRACT_BYTECODE,
},
]),
/out of gas/
/trying to deploy a contract whose code is too large/
);
});
});
Expand Down
Loading

0 comments on commit 34e8416

Please sign in to comment.