Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Allow decoding of internal function pointers in viaIR compilations (in Solidity 0.8.20) #6050

Merged
merged 20 commits into from Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3c203bc
Write debugger code to determine new internal functions table
haltman-at Sep 30, 2022
aff59ef
Update types for new internal function pointer format
haltman-at Oct 1, 2022
9cb1727
Update internal function pointer decoding to handle both formats
haltman-at Oct 3, 2022
1b4fe9b
Put internal function raw type in own file
haltman-at Oct 3, 2022
4f3fd6e
Update inspectors/exporters for internal function changes
haltman-at Oct 4, 2022
55bdff8
Remove unneeded index/loose type
haltman-at May 16, 2023
2c807be
Rewrite functionsByIndex selector to use internalFunctionIDs
haltman-at May 17, 2023
6e8261c
Add code to set up new-style table from decoder
haltman-at May 17, 2023
103f9e5
Set decoder tests to use 0.8.20 and viaIR
haltman-at May 17, 2023
8658fe2
Up timeouts on decoder test setup
haltman-at May 17, 2023
7677790
Update internal function degradation test to remove more info
haltman-at May 17, 2023
a20ac59
Add components for new types
haltman-at Jun 16, 2023
261b068
Update packages/codec-components/src/react/components/codec/format.er…
haltman-at Jun 21, 2023
25d2590
Update components per Cliff's suggestion
haltman-at Jun 21, 2023
8723fcd
Revert "Set decoder tests to use 0.8.20 and viaIR"
haltman-at Jun 22, 2023
ebbcaf7
Revert "Up timeouts on decoder test setup"
haltman-at Jun 22, 2023
d864008
Revert "Update internal function degradation test to remove more info"
haltman-at Jun 22, 2023
9f9ce14
Increase Solidity version in Decoder tests to 0.8.20
haltman-at Jun 22, 2023
74118cb
Re-add viaIR decoding tests, now in separate directory
haltman-at Jun 22, 2023
75c62b3
Update ENS tests to 0.8.20
haltman-at Jun 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -2,12 +2,18 @@ import React from "react";
import type { Format } from "@truffle/codec";
import { createCodecComponent } from "../../utils/create-codec-component";
import { CodecError } from "../common/codec-error";
import { FunctionInternalRawInfoPcPair } from "./format.values.function-internal-raw-info-pc-pair";

export const { DeployedFunctionInConstructorError } = createCodecComponent(
"DeployedFunctionInConstructorError",
({ kind, context }: Format.Errors.DeployedFunctionInConstructorError) => (
({
kind,
context,
rawInformation
}: Format.Errors.DeployedFunctionInConstructorError) => (
<CodecError kind={kind}>
Deployed-style pointer in {context.typeName} constructor
Deployed-style pointer in {context.typeName} constructor&nbsp;
<FunctionInternalRawInfoPcPair data={rawInformation} />
cliffoo marked this conversation as resolved.
Show resolved Hide resolved
</CodecError>
)
);
Expand Up @@ -2,17 +2,18 @@ import React from "react";
import type { Format } from "@truffle/codec";
import { createCodecComponent } from "../../utils/create-codec-component";
import { CodecError } from "../common/codec-error";
import { FunctionInternalRawInfoPcPair } from "./format.values.function-internal-raw-info-pc-pair";

export const { MalformedInternalFunctionError } = createCodecComponent(
"MalformedInternalFunctionError",
({
kind,
context,
constructorProgramCounter
rawInformation
}: Format.Errors.MalformedInternalFunctionError) => (
<CodecError kind={kind}>
{context.typeName} constructor program counter is nonzero (
{constructorProgramCounter})
{context.typeName} pointer has zero deployed program counter&nbsp;
<FunctionInternalRawInfoPcPair data={rawInformation} />
</CodecError>
)
);
Expand Up @@ -2,19 +2,19 @@ import React from "react";
import type { Format } from "@truffle/codec";
import { createCodecComponent } from "../../utils/create-codec-component";
import { CodecError } from "../common/codec-error";
import { FunctionInternalRawInfo } from "./format.values.function-internal-raw-info";

export const { NoSuchInternalFunctionError } = createCodecComponent(
"NoSuchInternalFunctionError",
({
kind,
context,
constructorProgramCounter,
deployedProgramCounter
rawInformation
}: Format.Errors.NoSuchInternalFunctionError) => (
<CodecError kind={kind}>
{context.typeName} function pointer does not point to a valid function
(constructor program counter: {constructorProgramCounter}, deployed
program counter: {deployedProgramCounter})
{context.typeName} function pointer does not point to a valid
function&nbsp;
<FunctionInternalRawInfo data={rawInformation} />
cliffoo marked this conversation as resolved.
Show resolved Hide resolved
</CodecError>
)
);
@@ -0,0 +1,11 @@
import React from "react";
import type { Format } from "@truffle/codec";
import { createCodecComponent } from "../../utils/create-codec-component";
import { Code } from "../common/code";

export const { FunctionInternalRawInfoIndex } = createCodecComponent(
"FunctionInternalRawInfoIndex",
({ functionIndex }: Format.Values.FunctionInternalRawInfoIndex) => {
return <Code>(Function index: {functionIndex})</Code>;
}
);
@@ -0,0 +1,19 @@
import React from "react";
import type { Format } from "@truffle/codec";
import { createCodecComponent } from "../../utils/create-codec-component";
import { Code } from "../common/code";

export const { FunctionInternalRawInfoPcPair } = createCodecComponent(
"FunctionInternalRawInfoPcPair",
({
deployedProgramCounter,
constructorProgramCounter
}: Format.Values.FunctionInternalRawInfoPcPair) => {
return (
<Code>
(constructor: {constructorProgramCounter}, deployed:{" "}
{deployedProgramCounter})
</Code>
);
}
);
@@ -0,0 +1,16 @@
import React from "react";
import type { Format } from "@truffle/codec";
import { createCodecComponent } from "../../utils/create-codec-component";
import { FunctionInternalRawInfoPcPair } from "./format.values.function-internal-raw-info-pc-pair";
import { FunctionInternalRawInfoIndex } from "./format.values.function-internal-raw-info-index";
import { isFunctionInternalRawInfoPcPair } from "../../../utils";

export const { FunctionInternalRawInfo } = createCodecComponent(
"FunctionInternalRawInfo",
(data: Format.Values.FunctionInternalRawInfo) =>
isFunctionInternalRawInfoPcPair(data) ? (
<FunctionInternalRawInfoPcPair data={data} />
) : (
<FunctionInternalRawInfoIndex data={data} />
)
);
Expand Up @@ -3,10 +3,14 @@ import type { Format } from "@truffle/codec";
import { createCodecComponent } from "../../utils/create-codec-component";
import { useInjectedNode } from "../../contexts/injected-node";
import { Code } from "../common/code";
import { FunctionInternalRawInfo } from "./format.values.function-internal-raw-info";

export const { FunctionInternalValueInfoUnknown } = createCodecComponent(
"FunctionInternalValueInfoUnknown",
({ context }: Format.Values.FunctionInternalValueInfoUnknown) => {
({
context,
rawInformation
}: Format.Values.FunctionInternalValueInfoUnknown) => {
const { prefix, content } = useInjectedNode();
return (
<Code>
Expand All @@ -15,7 +19,7 @@ export const { FunctionInternalValueInfoUnknown } = createCodecComponent(
{context.typeName}
</Code>
<Code type="period">.</Code>
<Code type="function">?</Code>
<FunctionInternalRawInfo data={rawInformation} />
haltman-at marked this conversation as resolved.
Show resolved Hide resolved
{content?.suffix}
</Code>
);
Expand Down
Expand Up @@ -147,6 +147,9 @@ export interface CustomComponentsContextValue {
FunctionExternalValueInfoUnknown: Codec.Format.Values.FunctionExternalValueInfoUnknown;
FunctionExternalValueInfo: Codec.Format.Values.FunctionExternalValueInfo;
FunctionExternalValue: Codec.Format.Values.FunctionExternalValue;
FunctionInternalRawInfo: Codec.Format.Values.FunctionInternalRawInfo;
FunctionInternalRawInfoPcPair: Codec.Format.Values.FunctionInternalRawInfoPcPair;
FunctionInternalRawInfoIndex: Codec.Format.Values.FunctionInternalRawInfoIndex;
FunctionInternalResult: Codec.Format.Values.FunctionInternalResult;
FunctionInternalValueInfoException: Codec.Format.Values.FunctionInternalValueInfoException;
FunctionInternalValueInfoKnown: Codec.Format.Values.FunctionInternalValueInfoKnown;
Expand Down
3 changes: 3 additions & 0 deletions packages/codec-components/src/react/index.ts
Expand Up @@ -129,6 +129,9 @@ export * from "./components/codec/format.values.function-external-value-info-kno
export * from "./components/codec/format.values.function-external-value-info";
export * from "./components/codec/format.values.function-external-value-info-unknown";
export * from "./components/codec/format.values.function-external-value";
export * from "./components/codec/format.values.function-internal-raw-info";
export * from "./components/codec/format.values.function-internal-raw-info-pc-pair";
export * from "./components/codec/format.values.function-internal-raw-info-index";
export * from "./components/codec/format.values.function-internal-result";
export * from "./components/codec/format.values.function-internal-value-info-exception";
export * from "./components/codec/format.values.function-internal-value-info-known";
Expand Down
3 changes: 3 additions & 0 deletions packages/codec-components/src/utils/index.ts
Expand Up @@ -87,6 +87,9 @@ export * from "./type-guards/other/function-external-value-info-invalid";
export * from "./type-guards/other/function-external-value-info-known";
export * from "./type-guards/other/function-external-value-info-unknown";
export * from "./type-guards/other/function-external-value-info";
export * from "./type-guards/other/function-internal-raw-info-pc-pair";
export * from "./type-guards/other/function-internal-raw-info-index";
export * from "./type-guards/other/function-internal-raw-info";
export * from "./type-guards/other/function-internal-value-info-exception";
export * from "./type-guards/other/function-internal-value-info-known";
export * from "./type-guards/other/function-internal-value-info-unknown";
Expand Down
@@ -0,0 +1,5 @@
import type { Format } from "@truffle/codec";

export const isFunctionInternalRawInfoIndex = (
data: Format.Values.FunctionInternalRawInfo
): data is Format.Values.FunctionInternalRawInfoIndex => data.kind === "index";
@@ -0,0 +1,6 @@
import type { Format } from "@truffle/codec";

export const isFunctionInternalRawInfoPcPair = (
data: Format.Values.FunctionInternalRawInfo
): data is Format.Values.FunctionInternalRawInfoPcPair =>
data.kind === "pcpair";
@@ -0,0 +1,2 @@
// No type guard for FunctionInternalRawInfo
export {};
3 changes: 3 additions & 0 deletions packages/codec/lib/ast/types.ts
Expand Up @@ -12,6 +12,9 @@ export interface AstNode {
name: string;
canonicalName?: string;
linearizedBaseContracts?: number[];
internalFunctionIDs?: {
[nodeId: string]: number; //note the strings are numeric
};
members?: AstNode[];
underlyingType?: AstNode;
nodes?: AstNode[];
Expand Down