Skip to content

Commit

Permalink
"function call to a non-contract account" heuristic should include t…
Browse files Browse the repository at this point in the history
…he address #3771
  • Loading branch information
ZainGulbaz committed Apr 19, 2023
1 parent b80801f commit 9343035
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
StackTraceEntryType,
UnmappedSolc063RevertErrorStackTraceEntry,
} from "./solidity-stack-trace";
import { getNonContractAccountAddress } from "./model";

const FIRST_SOLC_VERSION_CREATE_PARAMS_VALIDATION = "0.5.9";
const FIRST_SOLC_VERSION_RECEIVE_FUNCTION = "0.6.0";
Expand Down Expand Up @@ -680,9 +681,11 @@ export class ErrorInferrer {
"Expected source reference to be defined"
);

let address = getNonContractAccountAddress(trace);
const nonContractCalledFrame: SolidityStackTraceEntry = {
type: StackTraceEntryType.NONCONTRACT_ACCOUNT_CALLED_ERROR,
sourceReference,
address,
};

return [...stacktrace, nonContractCalledFrame];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
StackTraceEntryType,
} from "./solidity-stack-trace";

import { getNonContractAccountAddress } from "./model";

const FIRST_SOLC_VERSION_WITH_MAPPED_SMALL_INTERNAL_FUNCTIONS = "0.6.9";

export function stackTraceMayRequireAdjustments(
Expand Down Expand Up @@ -63,11 +65,13 @@ export function adjustStackTrace(
const [revert] = stackTrace.slice(-1);

if (isNonContractAccountCalledError(decodedTrace)) {
let address = getNonContractAccountAddress(decodedTrace);
return [
...start,
{
type: StackTraceEntryType.NONCONTRACT_ACCOUNT_CALLED_ERROR,
sourceReference: revert.sourceReference!,
address,
},
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface BaseEvmMessageTrace extends BaseMessageTrace {
code: Buffer;
value: bigint;
returnData: Buffer;
calldata?: Buffer;
error?: EvmError;
steps: MessageTraceStep[];
bytecode?: Bytecode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { bufferToHex } from "@nomicfoundation/ethereumjs-util";

import { AbiHelpers } from "../../util/abi-helpers";

import { DecodedEvmMessageTrace } from "./message-trace";

import { Opcode } from "./opcodes";

/* eslint-disable @nomiclabs/hardhat-internal-rules/only-hardhat-error */
Expand Down Expand Up @@ -35,6 +37,13 @@ export enum ContractFunctionVisibility {
EXTERNAL,
}

export function getNonContractAccountAddress(
decodedTrace: DecodedEvmMessageTrace
): Buffer {
let callDataBuffer = decodedTrace.calldata?.toString("hex");
return Buffer.from("0x" + callDataBuffer?.slice(32), "utf-8");
}

export class SourceFile {
public readonly contracts: Contract[] = [];
public readonly functions: ContractFunction[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function getMessageFromLastStackTraceEntry(
return `Transaction reverted: function returned an unexpected amount of data`;

case StackTraceEntryType.NONCONTRACT_ACCOUNT_CALLED_ERROR:
return `Transaction reverted: function call to a non-contract account`;
return `Transaction reverted: function call to a non-contract account ${stackTraceEntry.address}`;

case StackTraceEntryType.CALL_FAILED_ERROR:
return `Transaction reverted: function call failed to execute`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ReturnData } from "../provider/return-data";

import { ContractFunctionType } from "./model";



export enum StackTraceEntryType {
CALLSTACK_ENTRY,
UNRECOGNIZED_CREATE_CALLSTACK_ENTRY,
Expand Down Expand Up @@ -137,6 +139,7 @@ export interface ReturndataSizeErrorStackTraceEntry {
export interface NonContractAccountCalledErrorStackTraceEntry {
type: StackTraceEntryType.NONCONTRACT_ACCOUNT_CALLED_ERROR;
sourceReference: SourceReference;
address:Buffer;
}

export interface CallFailedErrorStackTraceEntry {
Expand Down

0 comments on commit 9343035

Please sign in to comment.