From 96756d7d4cef4c5d2fdb0e242143b321789bb80c Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:07:23 -0500 Subject: [PATCH 01/19] format: add type label; move base examples --- packages/format/src/types/type/base.ts | 4 +++ packages/format/src/types/type/index.test.ts | 30 ++++++++++++++++++ packages/format/src/types/type/index.ts | 33 ++++++++++++++++++++ schemas/type/base.schema.yaml | 30 ++++++++++++------ schemas/type/complex/alias.schema.yaml | 2 ++ schemas/type/complex/array.schema.yaml | 2 ++ schemas/type/complex/function.schema.yaml | 2 ++ schemas/type/complex/mapping.schema.yaml | 2 ++ schemas/type/complex/struct.schema.yaml | 2 ++ schemas/type/complex/tuple.schema.yaml | 2 ++ schemas/type/elementary/address.schema.yaml | 2 ++ schemas/type/elementary/bool.schema.yaml | 2 ++ schemas/type/elementary/bytes.schema.yaml | 2 ++ schemas/type/elementary/contract.schema.yaml | 2 ++ schemas/type/elementary/enum.schema.yaml | 2 ++ schemas/type/elementary/fixed.schema.yaml | 2 ++ schemas/type/elementary/int.schema.yaml | 2 ++ schemas/type/elementary/string.schema.yaml | 2 ++ schemas/type/elementary/ufixed.schema.yaml | 2 ++ schemas/type/elementary/uint.schema.yaml | 2 ++ 20 files changed, 119 insertions(+), 10 deletions(-) diff --git a/packages/format/src/types/type/base.ts b/packages/format/src/types/type/base.ts index ff0f2d98b5..0ba41731d7 100644 --- a/packages/format/src/types/type/base.ts +++ b/packages/format/src/types/type/base.ts @@ -6,6 +6,7 @@ export const isType = (value: unknown): value is Type => export interface Elementary { class?: "elementary"; kind: string; + label?: string; } export const isElementary = (value: unknown): value is Elementary => @@ -13,12 +14,14 @@ export const isElementary = (value: unknown): value is Elementary => !!value && "kind" in value && typeof value.kind === "string" && + (!("label" in value) || typeof value.label === "string") && (!("class" in value) || value.class === "elementary") && !("contains" in value); export interface Complex { class?: "complex"; kind: string; + label?: string; contains: | Wrapper | Wrapper[] @@ -32,6 +35,7 @@ export const isComplex = (value: unknown): value is Complex => !!value && "kind" in value && typeof value.kind === "string" && + (!("label" in value) || typeof value.label === "string") && (!("class" in value) || value.class === "complex") && "contains" in value && !!value.contains && diff --git a/packages/format/src/types/type/index.test.ts b/packages/format/src/types/type/index.test.ts index 7747395dc7..7e775bb1de 100644 --- a/packages/format/src/types/type/index.test.ts +++ b/packages/format/src/types/type/index.test.ts @@ -152,3 +152,33 @@ describe("Type.Elementary.isContract flag semantics", () => { ); }); }); + +describe("rejected values", () => { + const typeSchema = "schema:ethdebug/format/type"; + + const rejected = [ + { + title: "the removed uint kind", + value: { kind: "uint", bits: 256 }, + }, + { + title: "an unknown complex kind with a removed-kind child", + value: { + class: "complex", + kind: "pair", + contains: [{ type: { kind: "uint", bits: 256 } }], + }, + }, + { + title: "a non-string label", + value: { kind: "bool", label: 7 }, + }, + ] as const; + + for (const { title, value } of rejected) { + it(`rejects ${title}`, async () => { + expect(isType(value)).toBe(false); + await expect(value).not.toValidate({ schema: typeSchema }); + }); + } +}); diff --git a/packages/format/src/types/type/index.ts b/packages/format/src/types/type/index.ts index 71efeb15fe..170a801093 100644 --- a/packages/format/src/types/type/index.ts +++ b/packages/format/src/types/type/index.ts @@ -108,6 +108,7 @@ export namespace Type { export interface Uint { class?: "elementary"; kind: "uint"; + label?: string; bits: number; } @@ -115,6 +116,7 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "elementary") && + mayHaveLabel(value) && hasKind(value, "uint") && "bits" in value && typeof value.bits === "number" && @@ -125,6 +127,7 @@ export namespace Type { export interface Int { class?: "elementary"; kind: "int"; + label?: string; bits: number; } @@ -132,6 +135,7 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "elementary") && + mayHaveLabel(value) && hasKind(value, "int") && "bits" in value && typeof value.bits === "number" && @@ -142,6 +146,7 @@ export namespace Type { export interface Ufixed { class?: "elementary"; kind: "ufixed"; + label?: string; bits: number; places: number; } @@ -150,6 +155,7 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "elementary") && + mayHaveLabel(value) && hasKind(value, "ufixed") && "bits" in value && typeof value.bits === "number" && @@ -164,6 +170,7 @@ export namespace Type { export interface Fixed { class?: "elementary"; kind: "fixed"; + label?: string; bits: number; places: number; } @@ -172,6 +179,7 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "elementary") && + mayHaveLabel(value) && hasKind(value, "fixed") && "bits" in value && typeof value.bits === "number" && @@ -186,17 +194,20 @@ export namespace Type { export interface Bool { class?: "elementary"; kind: "bool"; + label?: string; } export const isBool = (value: unknown): value is Bool => typeof value === "object" && !!value && mayHaveClass(value, "elementary") && + mayHaveLabel(value) && hasKind(value, "bool"); export interface Bytes { class?: "elementary"; kind: "bytes"; + label?: string; size?: Data.Unsigned; } @@ -204,12 +215,14 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "elementary") && + mayHaveLabel(value) && hasKind(value, "bytes") && (!("size" in value) || Data.isUnsigned(value.size)); export interface String { class?: "elementary"; kind: "string"; + label?: string; encoding?: string; } @@ -217,12 +230,14 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "elementary") && + mayHaveLabel(value) && hasKind(value, "string") && (!("encoding" in value) || typeof value.encoding === "string"); export interface Address { class?: "elementary"; kind: "address"; + label?: string; payable?: boolean; } @@ -230,12 +245,14 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "elementary") && + mayHaveLabel(value) && hasKind(value, "address") && (!("payable" in value) || typeof value.payable === "boolean"); export interface Contract { class?: "elementary"; kind: "contract"; + label?: string; payable?: boolean; library?: boolean; interface?: boolean; @@ -246,6 +263,7 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "elementary") && + mayHaveLabel(value) && hasKind(value, "contract") && (!("payable" in value) || typeof value.payable === "boolean") && (!("library" in value) || typeof value.library === "boolean") && @@ -265,6 +283,7 @@ export namespace Type { export interface Enum { class?: "elementary"; kind: "enum"; + label?: string; values: any[]; definition?: Definition; } @@ -273,6 +292,7 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "elementary") && + mayHaveLabel(value) && hasKind(value, "enum") && "values" in value && Array.isArray(value.values) && @@ -318,6 +338,7 @@ export namespace Type { export interface Alias { class?: "complex"; kind: "alias"; + label?: string; contains: Wrapper; definition?: Definition; } @@ -326,6 +347,7 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "complex") && + mayHaveLabel(value) && hasKind(value, "alias") && "contains" in value && isWrapper(value.contains) && @@ -334,6 +356,7 @@ export namespace Type { export interface Tuple { class?: "complex"; kind: "tuple"; + label?: string; contains: (Wrapper & { name?: string })[]; } @@ -341,6 +364,7 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "complex") && + mayHaveLabel(value) && hasKind(value, "tuple") && "contains" in value && Array.isArray(value.contains) && @@ -353,6 +377,7 @@ export namespace Type { export interface Array { class?: "complex"; kind: "array"; + label?: string; contains: Wrapper; } @@ -360,6 +385,7 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "complex") && + mayHaveLabel(value) && hasKind(value, "array") && "contains" in value && isWrapper(value.contains); @@ -367,6 +393,7 @@ export namespace Type { export interface Mapping { class?: "complex"; kind: "mapping"; + label?: string; contains: { key: Wrapper; value: Wrapper; @@ -377,6 +404,7 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "complex") && + mayHaveLabel(value) && hasKind(value, "mapping") && "contains" in value && typeof value.contains === "object" && @@ -389,6 +417,7 @@ export namespace Type { export interface Struct { class?: "complex"; kind: "struct"; + label?: string; contains: (Wrapper & { name?: string })[]; definition?: Definition; } @@ -397,6 +426,7 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "complex") && + mayHaveLabel(value) && hasKind(value, "struct") && "contains" in value && Array.isArray(value.contains) && @@ -428,6 +458,9 @@ export const mayHaveClass = ( ): object is { class: Class } => !("class" in object) || object.class === class_; +export const mayHaveLabel = (object: object): boolean => + !("label" in object) || typeof object.label === "string"; + export const hasKind = ( object: object, kind: Kind, diff --git a/schemas/type/base.schema.yaml b/schemas/type/base.schema.yaml index eeca1e9ceb..c5d2e7c2f1 100644 --- a/schemas/type/base.schema.yaml +++ b/schemas/type/base.schema.yaml @@ -11,6 +11,12 @@ oneOf: - $ref: "#/$defs/ComplexType" $defs: + Label: + title: Type label + description: The type as the source language spells it. For display + only; no standard interpretation uses this field. + type: string + ElementaryType: title: Base elementary type description: Represents an elementary type (one that does not compose other types) @@ -21,6 +27,8 @@ $defs: const: elementary kind: type: string + label: + $ref: "#/$defs/Label" contains: not: description: "Elementary types **must not** specify a `contains` field @@ -28,8 +36,12 @@ $defs: required: - kind examples: - - kind: uint - bits: 256 + - kind: number + - kind: number + signed: true + label: int16 + - kind: address + payable: true ComplexType: title: Base complex type @@ -45,6 +57,8 @@ $defs: kind: type: string description: The specific kind of complex type, e.g., array or struct + label: + $ref: "#/$defs/Label" contains: title: Complex type `contains` field description: @@ -62,18 +76,15 @@ $defs: - kind: array contains: type: - kind: uint - bits: 256 + kind: number - kind: struct contains: - name: x type: - kind: uint - bits: 256 + kind: number - name: y type: - kind: uint - bits: 256 + kind: number - kind: mapping contains: key: @@ -82,8 +93,7 @@ $defs: payable: true value: type: - kind: uint - bits: 256 + kind: number TypeWrapper: title: '{ "type": ... }' diff --git a/schemas/type/complex/alias.schema.yaml b/schemas/type/complex/alias.schema.yaml index 6e68e5eae1..6ace84728f 100644 --- a/schemas/type/complex/alias.schema.yaml +++ b/schemas/type/complex/alias.schema.yaml @@ -6,6 +6,8 @@ description: Schema representing a type alias to another type type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: type: string const: complex diff --git a/schemas/type/complex/array.schema.yaml b/schemas/type/complex/array.schema.yaml index b01d54b1c9..d76688c901 100644 --- a/schemas/type/complex/array.schema.yaml +++ b/schemas/type/complex/array.schema.yaml @@ -9,6 +9,8 @@ description: | type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: type: string const: complex diff --git a/schemas/type/complex/function.schema.yaml b/schemas/type/complex/function.schema.yaml index b6c61c8736..aec103b505 100644 --- a/schemas/type/complex/function.schema.yaml +++ b/schemas/type/complex/function.schema.yaml @@ -17,6 +17,8 @@ description: | type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: type: string const: complex diff --git a/schemas/type/complex/mapping.schema.yaml b/schemas/type/complex/mapping.schema.yaml index 8f1b0c23ed..cf5050ff3e 100644 --- a/schemas/type/complex/mapping.schema.yaml +++ b/schemas/type/complex/mapping.schema.yaml @@ -6,6 +6,8 @@ description: Schema for representing mapping types type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: type: string const: complex diff --git a/schemas/type/complex/struct.schema.yaml b/schemas/type/complex/struct.schema.yaml index 9affcbc291..b99f98b19f 100644 --- a/schemas/type/complex/struct.schema.yaml +++ b/schemas/type/complex/struct.schema.yaml @@ -6,6 +6,8 @@ description: Schema for representing struct types type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: type: string const: complex diff --git a/schemas/type/complex/tuple.schema.yaml b/schemas/type/complex/tuple.schema.yaml index 70c4ed84c2..10cddde48a 100644 --- a/schemas/type/complex/tuple.schema.yaml +++ b/schemas/type/complex/tuple.schema.yaml @@ -6,6 +6,8 @@ description: Schema for representing tuple types type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: type: string const: complex diff --git a/schemas/type/elementary/address.schema.yaml b/schemas/type/elementary/address.schema.yaml index d386940427..10b9d362e7 100644 --- a/schemas/type/elementary/address.schema.yaml +++ b/schemas/type/elementary/address.schema.yaml @@ -6,6 +6,8 @@ description: Schema describing the representation of an address type type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: const: elementary kind: diff --git a/schemas/type/elementary/bool.schema.yaml b/schemas/type/elementary/bool.schema.yaml index 044dea73e7..8f3374b98b 100644 --- a/schemas/type/elementary/bool.schema.yaml +++ b/schemas/type/elementary/bool.schema.yaml @@ -6,6 +6,8 @@ description: Schema describing the representation of the boolean type type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: const: elementary kind: diff --git a/schemas/type/elementary/bytes.schema.yaml b/schemas/type/elementary/bytes.schema.yaml index 5fb217ad4b..c231ff11ec 100644 --- a/schemas/type/elementary/bytes.schema.yaml +++ b/schemas/type/elementary/bytes.schema.yaml @@ -7,6 +7,8 @@ description: Schema describing the representation of a type of bytes string type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: const: elementary kind: diff --git a/schemas/type/elementary/contract.schema.yaml b/schemas/type/elementary/contract.schema.yaml index 48d4eeb47d..3df2da73f4 100644 --- a/schemas/type/elementary/contract.schema.yaml +++ b/schemas/type/elementary/contract.schema.yaml @@ -6,6 +6,8 @@ description: Schema describing the representation of a contract type type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: const: elementary kind: diff --git a/schemas/type/elementary/enum.schema.yaml b/schemas/type/elementary/enum.schema.yaml index f20a4488d5..de247cb4bf 100644 --- a/schemas/type/elementary/enum.schema.yaml +++ b/schemas/type/elementary/enum.schema.yaml @@ -6,6 +6,8 @@ description: Schema describing the representation of an enumerated type type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: const: elementary kind: diff --git a/schemas/type/elementary/fixed.schema.yaml b/schemas/type/elementary/fixed.schema.yaml index 0fe866a2b3..de6dc49b40 100644 --- a/schemas/type/elementary/fixed.schema.yaml +++ b/schemas/type/elementary/fixed.schema.yaml @@ -6,6 +6,8 @@ description: Schema describing the representation of a signed fixed decimal type type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: const: elementary kind: diff --git a/schemas/type/elementary/int.schema.yaml b/schemas/type/elementary/int.schema.yaml index fac0c378a4..f85f730fb7 100644 --- a/schemas/type/elementary/int.schema.yaml +++ b/schemas/type/elementary/int.schema.yaml @@ -6,6 +6,8 @@ description: Schema describing the representation of a signed integer type type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: const: elementary kind: diff --git a/schemas/type/elementary/string.schema.yaml b/schemas/type/elementary/string.schema.yaml index 1eb4566b84..96eba5aebc 100644 --- a/schemas/type/elementary/string.schema.yaml +++ b/schemas/type/elementary/string.schema.yaml @@ -6,6 +6,8 @@ description: Schema describing the representation of a string type type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: const: elementary kind: diff --git a/schemas/type/elementary/ufixed.schema.yaml b/schemas/type/elementary/ufixed.schema.yaml index 3bfb36af30..d30b45e0b8 100644 --- a/schemas/type/elementary/ufixed.schema.yaml +++ b/schemas/type/elementary/ufixed.schema.yaml @@ -6,6 +6,8 @@ description: Schema describing the representation of an unsigned fixed decimal t type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: const: elementary kind: diff --git a/schemas/type/elementary/uint.schema.yaml b/schemas/type/elementary/uint.schema.yaml index 6a913e478a..aa2590329b 100644 --- a/schemas/type/elementary/uint.schema.yaml +++ b/schemas/type/elementary/uint.schema.yaml @@ -6,6 +6,8 @@ description: Schema describing the representation of an unsigned integer type type: object properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: const: elementary kind: From 0505b584b4393829c6ed9f6251e190df975b2b02 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:10:01 -0500 Subject: [PATCH 02/19] format: replace elementary type kinds --- packages/format/src/types/type/index.test.ts | 120 ++++++---- packages/format/src/types/type/index.ts | 232 +++++++------------ schemas/type/complex/alias.schema.yaml | 3 +- schemas/type/complex/array.schema.yaml | 3 +- schemas/type/complex/function.schema.yaml | 15 +- schemas/type/complex/mapping.schema.yaml | 3 +- schemas/type/complex/struct.schema.yaml | 6 +- schemas/type/complex/tuple.schema.yaml | 6 +- schemas/type/elementary.schema.yaml | 39 +--- schemas/type/elementary/address.schema.yaml | 64 ++++- schemas/type/elementary/bool.schema.yaml | 9 +- schemas/type/elementary/bytes.schema.yaml | 20 +- schemas/type/elementary/contract.schema.yaml | 59 ----- schemas/type/elementary/enum.schema.yaml | 23 +- schemas/type/elementary/fixed.schema.yaml | 37 --- schemas/type/elementary/flags.schema.yaml | 46 ++++ schemas/type/elementary/int.schema.yaml | 25 -- schemas/type/elementary/number.schema.yaml | 47 ++++ schemas/type/elementary/string.schema.yaml | 9 +- schemas/type/elementary/ufixed.schema.yaml | 37 --- schemas/type/elementary/uint.schema.yaml | 25 -- schemas/type/specifier.schema.yaml | 3 +- 22 files changed, 370 insertions(+), 461 deletions(-) delete mode 100644 schemas/type/elementary/contract.schema.yaml delete mode 100644 schemas/type/elementary/fixed.schema.yaml create mode 100644 schemas/type/elementary/flags.schema.yaml delete mode 100644 schemas/type/elementary/int.schema.yaml create mode 100644 schemas/type/elementary/number.schema.yaml delete mode 100644 schemas/type/elementary/ufixed.schema.yaml delete mode 100644 schemas/type/elementary/uint.schema.yaml diff --git a/packages/format/src/types/type/index.test.ts b/packages/format/src/types/type/index.test.ts index 7e775bb1de..605dd0d5bd 100644 --- a/packages/format/src/types/type/index.test.ts +++ b/packages/format/src/types/type/index.test.ts @@ -19,24 +19,24 @@ testSchemaGuards("ethdebug/format/type", [ guard: Type.isElementary, }, { - schema: "schema:ethdebug/format/type/elementary/uint", - guard: Type.Elementary.isUint, + schema: "schema:ethdebug/format/type/elementary/number", + guard: Type.Elementary.isNumber, }, { - schema: "schema:ethdebug/format/type/elementary/int", - guard: Type.Elementary.isInt, + schema: "schema:ethdebug/format/type/elementary/address", + guard: Type.Elementary.isAddress, }, { - schema: "schema:ethdebug/format/type/elementary/ufixed", - guard: Type.Elementary.isUfixed, + schema: "schema:ethdebug/format/type/elementary/bool", + guard: Type.Elementary.isBool, }, { - schema: "schema:ethdebug/format/type/elementary/fixed", - guard: Type.Elementary.isFixed, + schema: "schema:ethdebug/format/type/elementary/enum", + guard: Type.Elementary.isEnum, }, { - schema: "schema:ethdebug/format/type/elementary/bool", - guard: Type.Elementary.isBool, + schema: "schema:ethdebug/format/type/elementary/flags", + guard: Type.Elementary.isFlags, }, { schema: "schema:ethdebug/format/type/elementary/bytes", @@ -46,18 +46,6 @@ testSchemaGuards("ethdebug/format/type", [ schema: "schema:ethdebug/format/type/elementary/string", guard: Type.Elementary.isString, }, - { - schema: "schema:ethdebug/format/type/elementary/address", - guard: Type.Elementary.isAddress, - }, - { - schema: "schema:ethdebug/format/type/elementary/contract", - guard: Type.Elementary.isContract, - }, - { - schema: "schema:ethdebug/format/type/elementary/enum", - guard: Type.Elementary.isEnum, - }, // complex types @@ -102,55 +90,67 @@ testSchemaGuards("ethdebug/format/type", [ }, ] as const); -// The contract type's schema uses a oneOf to distinguish normal / +// The address type's schema uses a oneOf to distinguish normal / // library / interface contracts via the `library` and `interface` -// flags. The guard must carry those flags and agree with the schema — -// in particular it must reject a contract that sets both flags true -// (which matches two oneOf branches at once). -describe("Type.Elementary.isContract flag semantics", () => { - const contractSchema = "schema:ethdebug/format/type/elementary/contract"; +// flags of its definition. The guard must agree with the schema, in +// particular it must reject a definition that sets both flags true. +describe("Type.Elementary.isAddress definition flags", () => { + const addressSchema = "schema:ethdebug/format/type/elementary/address"; const legal = [ - { title: "normal (flags omitted)", value: { kind: "contract" } }, + { title: "plain", value: { kind: "address" } }, { - title: "normal (flags explicitly false)", - value: { kind: "contract", library: false, interface: false }, + title: "normal contract", + value: { kind: "address", definition: { name: "T" } }, + }, + { + title: "normal contract (flags explicitly false)", + value: { + kind: "address", + definition: { name: "T", library: false, interface: false }, + }, + }, + { + title: "library", + value: { kind: "address", definition: { name: "T", library: true } }, + }, + { + title: "interface", + value: { kind: "address", definition: { name: "T", interface: true } }, }, - { title: "library", value: { kind: "contract", library: true } }, - { title: "interface", value: { kind: "contract", interface: true } }, ] as const; const illegal = [ { title: "both library and interface true", - value: { kind: "contract", library: true, interface: true }, + value: { + kind: "address", + definition: { name: "T", library: true, interface: true }, + }, + }, + { + title: "a non-boolean library flag", + value: { kind: "address", definition: { name: "T", library: "true" } }, + }, + { + title: "a non-boolean interface flag", + value: { kind: "address", definition: { name: "T", interface: 1 } }, }, ] as const; for (const { title, value } of legal) { - it(`accepts the ${title} contract shape`, async () => { - expect(Type.Elementary.isContract(value)).toBe(true); - // guard agrees with the schema - await expect(value).toValidate({ schema: contractSchema }); + it(`accepts the ${title} address shape`, async () => { + expect(Type.Elementary.isAddress(value)).toBe(true); + await expect(value).toValidate({ schema: addressSchema }); }); } for (const { title, value } of illegal) { - it(`rejects a contract with ${title}`, async () => { - expect(Type.Elementary.isContract(value)).toBe(false); - // guard agrees with the schema - await expect(value).not.toValidate({ schema: contractSchema }); + it(`rejects an address with ${title}`, async () => { + expect(Type.Elementary.isAddress(value)).toBe(false); + await expect(value).not.toValidate({ schema: addressSchema }); }); } - - it("rejects non-boolean flag values", () => { - expect( - Type.Elementary.isContract({ kind: "contract", library: "true" }), - ).toBe(false); - expect(Type.Elementary.isContract({ kind: "contract", interface: 1 })).toBe( - false, - ); - }); }); describe("rejected values", () => { @@ -169,6 +169,24 @@ describe("rejected values", () => { contains: [{ type: { kind: "uint", bits: 256 } }], }, }, + { + title: "a negative number places", + value: { kind: "number", places: -1 }, + }, + { + title: "a non-boolean number signed", + value: { kind: "number", signed: "yes" }, + }, + { title: "an empty enum", value: { kind: "enum", values: [] } }, + { + title: "a repeated enum value", + value: { kind: "enum", values: ["A", "A"] }, + }, + { title: "an empty flags", value: { kind: "flags", values: [] } }, + { + title: "a repeated flags value", + value: { kind: "flags", values: ["A", "A"] }, + }, { title: "a non-string label", value: { kind: "bool", label: 7 }, diff --git a/packages/format/src/types/type/index.ts b/packages/format/src/types/type/index.ts index 170a801093..04fd52f237 100644 --- a/packages/format/src/types/type/index.ts +++ b/packages/format/src/types/type/index.ts @@ -1,4 +1,3 @@ -import { Data } from "#types/data"; import { Materials } from "#types/materials"; import * as _Base from "./base.js"; @@ -57,16 +56,13 @@ export namespace Type { isSpecifier(value.type); export type Elementary = - | Elementary.Uint - | Elementary.Int - | Elementary.Ufixed - | Elementary.Fixed + | Elementary.Number + | Elementary.Address | Elementary.Bool + | Elementary.Enum + | Elementary.Flags | Elementary.Bytes - | Elementary.String - | Elementary.Address - | Elementary.Contract - | Elementary.Enum; + | Elementary.String; export const hasElementaryKind = ( value: unknown, @@ -77,119 +73,77 @@ export namespace Type { !!value && "kind" in value && typeof value.kind === "string" && - [ - "uint", - "int", - "ufixed", - "fixed", - "bool", - "bytes", - "string", - "address", - "contract", - "enum", - ].includes(value.kind); + ["number", "address", "bool", "enum", "flags", "bytes", "string"].includes( + value.kind, + ); export const isElementary = (value: unknown): value is Elementary => [ - Elementary.isUint, - Elementary.isInt, - Elementary.isUfixed, - Elementary.isFixed, + Elementary.isNumber, + Elementary.isAddress, Elementary.isBool, + Elementary.isEnum, + Elementary.isFlags, Elementary.isBytes, Elementary.isString, - Elementary.isAddress, - Elementary.isContract, - Elementary.isEnum, ].some((guard) => guard(value)); export namespace Elementary { - export interface Uint { + export interface Number { class?: "elementary"; - kind: "uint"; + kind: "number"; label?: string; - bits: number; + signed?: boolean; + places?: number; } - export const isUint = (value: unknown): value is Uint => + export const isNumber = (value: unknown): value is Number => typeof value === "object" && !!value && mayHaveClass(value, "elementary") && mayHaveLabel(value) && - hasKind(value, "uint") && - "bits" in value && - typeof value.bits === "number" && - value.bits >= 8 && - value.bits <= 256 && - value.bits % 8 === 0; - - export interface Int { - class?: "elementary"; - kind: "int"; - label?: string; - bits: number; - } + hasKind(value, "number") && + (!("signed" in value) || typeof value.signed === "boolean") && + (!("places" in value) || + (typeof value.places === "number" && + globalThis.Number.isInteger(value.places) && + value.places >= 0)); + + export namespace Address { + export type Definition = Type.Definition & { + library?: boolean; + interface?: boolean; + }; - export const isInt = (value: unknown): value is Int => - typeof value === "object" && - !!value && - mayHaveClass(value, "elementary") && - mayHaveLabel(value) && - hasKind(value, "int") && - "bits" in value && - typeof value.bits === "number" && - value.bits >= 8 && - value.bits <= 256 && - value.bits % 8 === 0; - - export interface Ufixed { - class?: "elementary"; - kind: "ufixed"; - label?: string; - bits: number; - places: number; + export const isDefinition = (value: unknown): value is Definition => + Type.isDefinition(value) && + (!("library" in value) || typeof value.library === "boolean") && + (!("interface" in value) || typeof value.interface === "boolean") && + // the schema's oneOf rejects a type that is both + !( + "library" in value && + value.library === true && + "interface" in value && + value.interface === true + ); } - export const isUfixed = (value: unknown): value is Ufixed => - typeof value === "object" && - !!value && - mayHaveClass(value, "elementary") && - mayHaveLabel(value) && - hasKind(value, "ufixed") && - "bits" in value && - typeof value.bits === "number" && - value.bits >= 8 && - value.bits <= 256 && - value.bits % 8 === 0 && - "places" in value && - typeof value.places === "number" && - value.places >= 0 && - value.places <= 80; - - export interface Fixed { + export interface Address { class?: "elementary"; - kind: "fixed"; + kind: "address"; label?: string; - bits: number; - places: number; + payable?: boolean; + definition?: Address.Definition; } - export const isFixed = (value: unknown): value is Fixed => + export const isAddress = (value: unknown): value is Address => typeof value === "object" && !!value && mayHaveClass(value, "elementary") && mayHaveLabel(value) && - hasKind(value, "fixed") && - "bits" in value && - typeof value.bits === "number" && - value.bits >= 8 && - value.bits <= 256 && - value.bits % 8 === 0 && - "places" in value && - typeof value.places === "number" && - value.places >= 0 && - value.places <= 80; + hasKind(value, "address") && + (!("payable" in value) || typeof value.payable === "boolean") && + (!("definition" in value) || Address.isDefinition(value.definition)); export interface Bool { class?: "elementary"; @@ -204,99 +158,75 @@ export namespace Type { mayHaveLabel(value) && hasKind(value, "bool"); - export interface Bytes { - class?: "elementary"; - kind: "bytes"; - label?: string; - size?: Data.Unsigned; - } - - export const isBytes = (value: unknown): value is Bytes => - typeof value === "object" && - !!value && - mayHaveClass(value, "elementary") && - mayHaveLabel(value) && - hasKind(value, "bytes") && - (!("size" in value) || Data.isUnsigned(value.size)); + const isNames = (value: unknown): value is string[] => + Array.isArray(value) && + value.length >= 1 && + value.every((name) => typeof name === "string") && + new Set(value).size === value.length; - export interface String { + export interface Enum { class?: "elementary"; - kind: "string"; + kind: "enum"; label?: string; - encoding?: string; + values: string[]; + definition?: Definition; } - export const isString = (value: unknown): value is String => + export const isEnum = (value: unknown): value is Enum => typeof value === "object" && !!value && mayHaveClass(value, "elementary") && mayHaveLabel(value) && - hasKind(value, "string") && - (!("encoding" in value) || typeof value.encoding === "string"); + hasKind(value, "enum") && + "values" in value && + isNames(value.values) && + (!("definition" in value) || isDefinition(value.definition)); - export interface Address { + export interface Flags { class?: "elementary"; - kind: "address"; + kind: "flags"; label?: string; - payable?: boolean; + values: string[]; + definition?: Definition; } - export const isAddress = (value: unknown): value is Address => + export const isFlags = (value: unknown): value is Flags => typeof value === "object" && !!value && mayHaveClass(value, "elementary") && mayHaveLabel(value) && - hasKind(value, "address") && - (!("payable" in value) || typeof value.payable === "boolean"); + hasKind(value, "flags") && + "values" in value && + isNames(value.values) && + (!("definition" in value) || isDefinition(value.definition)); - export interface Contract { + export interface Bytes { class?: "elementary"; - kind: "contract"; + kind: "bytes"; label?: string; - payable?: boolean; - library?: boolean; - interface?: boolean; - definition?: Definition; } - export const isContract = (value: unknown): value is Contract => + export const isBytes = (value: unknown): value is Bytes => typeof value === "object" && !!value && mayHaveClass(value, "elementary") && mayHaveLabel(value) && - hasKind(value, "contract") && - (!("payable" in value) || typeof value.payable === "boolean") && - (!("library" in value) || typeof value.library === "boolean") && - (!("interface" in value) || typeof value.interface === "boolean") && - // The schema's oneOf splits contract types three ways (normal / - // library / interface). `library` and `interface` cannot both be - // true: that shape satisfies two branches at once, which the - // oneOf rejects. - !( - "library" in value && - value.library === true && - "interface" in value && - value.interface === true - ) && - (!("definition" in value) || isDefinition(value.definition)); + hasKind(value, "bytes"); - export interface Enum { + export interface String { class?: "elementary"; - kind: "enum"; + kind: "string"; label?: string; - values: any[]; - definition?: Definition; + encoding?: string; } - export const isEnum = (value: unknown): value is Enum => + export const isString = (value: unknown): value is String => typeof value === "object" && !!value && mayHaveClass(value, "elementary") && mayHaveLabel(value) && - hasKind(value, "enum") && - "values" in value && - Array.isArray(value.values) && - (!("definition" in value) || isDefinition(value.definition)); + hasKind(value, "string") && + (!("encoding" in value) || typeof value.encoding === "string"); } export type Complex = diff --git a/schemas/type/complex/alias.schema.yaml b/schemas/type/complex/alias.schema.yaml index 6ace84728f..f727fd287c 100644 --- a/schemas/type/complex/alias.schema.yaml +++ b/schemas/type/complex/alias.schema.yaml @@ -27,8 +27,7 @@ examples: - kind: alias contains: type: - kind: uint - bits: 256 + kind: number - kind: alias contains: diff --git a/schemas/type/complex/array.schema.yaml b/schemas/type/complex/array.schema.yaml index d76688c901..252df9ac20 100644 --- a/schemas/type/complex/array.schema.yaml +++ b/schemas/type/complex/array.schema.yaml @@ -37,8 +37,7 @@ examples: - kind: array contains: type: - kind: uint - bits: 256 + kind: number # example: a fixed-size array of 10 addresses - kind: array diff --git a/schemas/type/complex/function.schema.yaml b/schemas/type/complex/function.schema.yaml index aec103b505..f2fe4485ec 100644 --- a/schemas/type/complex/function.schema.yaml +++ b/schemas/type/complex/function.schema.yaml @@ -93,7 +93,7 @@ oneOf: properties: type: oneOf: - - $ref: "schema:ethdebug/format/type/elementary/contract" + - $ref: "schema:ethdebug/format/type/elementary/address" - $ref: "schema:ethdebug/format/type/reference" required: - external @@ -120,12 +120,10 @@ examples: contains: - name: value type: - kind: uint - bits: 256 + kind: number returns: type: - kind: uint - bits: 256 + kind: number - kind: function external: true definition: @@ -133,11 +131,11 @@ examples: contains: contract: type: - kind: contract + kind: address payable: true - interface: true definition: name: Bank + interface: true parameters: type: kind: tuple @@ -148,8 +146,7 @@ examples: payable: true - name: amount type: - kind: ufixed - bits: 128 + kind: number places: 18 returns: type: diff --git a/schemas/type/complex/mapping.schema.yaml b/schemas/type/complex/mapping.schema.yaml index cf5050ff3e..d766a5b948 100644 --- a/schemas/type/complex/mapping.schema.yaml +++ b/schemas/type/complex/mapping.schema.yaml @@ -38,5 +38,4 @@ examples: kind: address value: type: - kind: uint - bits: 256 + kind: number diff --git a/schemas/type/complex/struct.schema.yaml b/schemas/type/complex/struct.schema.yaml index b99f98b19f..cf90cc1192 100644 --- a/schemas/type/complex/struct.schema.yaml +++ b/schemas/type/complex/struct.schema.yaml @@ -30,12 +30,10 @@ examples: contains: - name: x type: - kind: uint - bits: 128 + kind: number - name: y type: - kind: uint - bits: 128 + kind: number $defs: MemberField: diff --git a/schemas/type/complex/tuple.schema.yaml b/schemas/type/complex/tuple.schema.yaml index 10cddde48a..ca6f759b9e 100644 --- a/schemas/type/complex/tuple.schema.yaml +++ b/schemas/type/complex/tuple.schema.yaml @@ -32,12 +32,10 @@ examples: contains: - name: x type: - kind: uint - bits: 128 + kind: number - name: y type: - kind: uint - bits: 128 + kind: number $defs: Element: diff --git a/schemas/type/elementary.schema.yaml b/schemas/type/elementary.schema.yaml index 0dfb9168be..fcfacf16fb 100644 --- a/schemas/type/elementary.schema.yaml +++ b/schemas/type/elementary.schema.yaml @@ -19,16 +19,9 @@ allOf: - if: properties: kind: - const: uint + const: number then: - $ref: "schema:ethdebug/format/type/elementary/uint" - - - if: - properties: - kind: - const: int - then: - $ref: "schema:ethdebug/format/type/elementary/int" + $ref: "schema:ethdebug/format/type/elementary/number" - if: properties: @@ -51,19 +44,6 @@ allOf: then: $ref: "schema:ethdebug/format/type/elementary/string" - - if: - properties: - kind: - const: ufixed - then: - $ref: "schema:ethdebug/format/type/elementary/ufixed" - - - if: - properties: - kind: - const: fixed - then: - $ref: "schema:ethdebug/format/type/elementary/fixed" - if: properties: kind: @@ -74,16 +54,16 @@ allOf: - if: properties: kind: - const: contract + const: enum then: - $ref: "schema:ethdebug/format/type/elementary/contract" + $ref: "schema:ethdebug/format/type/elementary/enum" - if: properties: kind: - const: enum + const: flags then: - $ref: "schema:ethdebug/format/type/elementary/enum" + $ref: "schema:ethdebug/format/type/elementary/flags" $defs: Kind: @@ -93,13 +73,10 @@ $defs: included in ethdebug/format type: string enum: - - uint - - int + - number - bool - bytes - string - - ufixed - - fixed - address - - contract - enum + - flags diff --git a/schemas/type/elementary/address.schema.yaml b/schemas/type/elementary/address.schema.yaml index 10b9d362e7..c19882ae95 100644 --- a/schemas/type/elementary/address.schema.yaml +++ b/schemas/type/elementary/address.schema.yaml @@ -2,7 +2,13 @@ $schema: "https://json-schema.org/draft/2020-12/schema" $id: "schema:ethdebug/format/type/elementary/address" title: ethdebug/format/type/elementary/address -description: Schema describing the representation of an address type +description: | + Schema describing the representation of an address type. An address + type with a `definition` is a reference to a contract. + + Standard interpretation: read the bytes of the value as a big-endian + unsigned integer. That integer is the address. This type has no size. + The number of bytes comes from the value's location. type: object properties: @@ -16,6 +22,43 @@ properties: type: boolean description: If this field is omitted, this type represents an address whose payability is not known. + definition: + description: | + If this field is omitted, this type is a plain address. If present, + this type is a reference to a contract. A contract can be a library + or an interface. The `library` and `interface` fields cannot both be + true. + allOf: + - $ref: "schema:ethdebug/format/type/definition" + - type: object + properties: + library: + type: boolean + description: Indicates that this is a type representing a library + interface: + type: boolean + description: Indicates that this is a type representing an interface + oneOf: + - title: Normal contract type + properties: + library: + const: false + interface: + const: false + + - title: Contract library type + properties: + library: + const: true + required: + - library + + - title: Contract interface type + properties: + interface: + const: true + required: + - interface required: - kind examples: @@ -25,3 +68,22 @@ examples: - # a type for payable addresses kind: address payable: true + + - # a type for a reference to a contract + kind: address + payable: true + definition: + name: Ballot + + - # a type for a reference to a library + kind: address + label: MathLib + definition: + name: MathLib + library: true + + - # a type for a reference to an interface + kind: address + definition: + name: IERC20 + interface: true diff --git a/schemas/type/elementary/bool.schema.yaml b/schemas/type/elementary/bool.schema.yaml index 8f3374b98b..6b72540574 100644 --- a/schemas/type/elementary/bool.schema.yaml +++ b/schemas/type/elementary/bool.schema.yaml @@ -2,7 +2,12 @@ $schema: "https://json-schema.org/draft/2020-12/schema" $id: "schema:ethdebug/format/type/elementary/bool" title: ethdebug/format/type/elementary/bool -description: Schema describing the representation of the boolean type +description: | + Schema describing the representation of the boolean type. + + Standard interpretation: read the bytes of the value as a big-endian + unsigned integer. The value 0 is false and the value 1 is true. Any + other value is invalid. type: object properties: @@ -16,3 +21,5 @@ required: - kind examples: - kind: bool + - kind: bool + label: bool diff --git a/schemas/type/elementary/bytes.schema.yaml b/schemas/type/elementary/bytes.schema.yaml index c231ff11ec..79b2764a10 100644 --- a/schemas/type/elementary/bytes.schema.yaml +++ b/schemas/type/elementary/bytes.schema.yaml @@ -2,8 +2,11 @@ $schema: "https://json-schema.org/draft/2020-12/schema" $id: "schema:ethdebug/format/type/elementary/bytes" title: ethdebug/format/type/elementary/bytes -description: Schema describing the representation of a type of bytes string - (either dynamic or static) +description: | + Schema describing the representation of a type of bytes string. + + Standard interpretation: the value is the bytes, in order. This type has + no size. The number of bytes comes from the value's location. type: object properties: @@ -13,16 +16,9 @@ properties: const: elementary kind: const: bytes - size: - description: - The number of bytes in the bytes string. If this field is omitted, this - type is the dynamic bytes string type. - $ref: "schema:ethdebug/format/data/unsigned" required: - kind examples: - - # example static bytes type - kind: bytes - size: 32 - - # example dynamic bytes type - kind: bytes + - kind: bytes + - kind: bytes + label: bytes32 diff --git a/schemas/type/elementary/contract.schema.yaml b/schemas/type/elementary/contract.schema.yaml deleted file mode 100644 index 3df2da73f4..0000000000 --- a/schemas/type/elementary/contract.schema.yaml +++ /dev/null @@ -1,59 +0,0 @@ -$schema: "https://json-schema.org/draft/2020-12/schema" -$id: "schema:ethdebug/format/type/elementary/contract" - -title: ethdebug/format/type/elementary/contract -description: Schema describing the representation of a contract type - -type: object -properties: - label: - $ref: "schema:ethdebug/format/type/base#/$defs/Label" - class: - const: elementary - kind: - const: contract - payable: - type: boolean - description: If this field is omitted, this type represents an address whose - payability is not known. - library: - type: boolean - interface: - type: boolean - definition: - $ref: "schema:ethdebug/format/type/definition" - -oneOf: - - title: Normal contract type - properties: - library: - const: false - interface: - const: false - - - title: Contract library type - properties: - library: - const: true - description: Indicates that this is a type representing a library - required: - - library - - - title: Contract interface type - properties: - interface: - const: true - description: Indicates that this is a type representing an interface - required: - - interface - -required: - - kind - -examples: - - kind: contract - - - kind: contract - library: false - interface: false - payable: true diff --git a/schemas/type/elementary/enum.schema.yaml b/schemas/type/elementary/enum.schema.yaml index de247cb4bf..2f44b6c6b6 100644 --- a/schemas/type/elementary/enum.schema.yaml +++ b/schemas/type/elementary/enum.schema.yaml @@ -2,7 +2,12 @@ $schema: "https://json-schema.org/draft/2020-12/schema" $id: "schema:ethdebug/format/type/elementary/enum" title: ethdebug/format/type/elementary/enum -description: Schema describing the representation of an enumerated type +description: | + Schema describing the representation of an enumerated type. + + Standard interpretation: read the bytes of the value as a big-endian + unsigned integer `i`. The value is `values[i]`. If `i` is not less than + `values.length`, the value is invalid. type: object properties: @@ -13,11 +18,12 @@ properties: kind: const: enum values: - description: - The allowed values of an enum. This format makes no restriction on which - values are allowed here. + description: The names of the enum values, where `values[i]` is value `i`. type: array - items: true + items: + type: string + minItems: 1 + uniqueItems: true definition: $ref: "schema:ethdebug/format/type/definition" @@ -31,3 +37,10 @@ examples: - A - B - C + - kind: enum + label: Direction + values: + - North + - South + definition: + name: Direction diff --git a/schemas/type/elementary/fixed.schema.yaml b/schemas/type/elementary/fixed.schema.yaml deleted file mode 100644 index de6dc49b40..0000000000 --- a/schemas/type/elementary/fixed.schema.yaml +++ /dev/null @@ -1,37 +0,0 @@ -$schema: "https://json-schema.org/draft/2020-12/schema" -$id: "schema:ethdebug/format/type/elementary/fixed" - -title: ethdebug/format/type/elementary/fixed -description: Schema describing the representation of a signed fixed decimal type - -type: object -properties: - label: - $ref: "schema:ethdebug/format/type/base#/$defs/Label" - class: - const: elementary - kind: - const: fixed - bits: - type: integer - multipleOf: 8 - minimum: 8 - maximum: 256 - places: - type: integer - description: - How many decimal places, implying that an unscaled value `v` of this - type should be interpreted as `v / (10**places)` - minimum: 0 - maximum: 80 -required: - - kind - - bits - - places -examples: - - kind: fixed - bits: 256 - places: 10 - - kind: fixed - bits: 64 - places: 0 diff --git a/schemas/type/elementary/flags.schema.yaml b/schemas/type/elementary/flags.schema.yaml new file mode 100644 index 0000000000..cb88fd65ad --- /dev/null +++ b/schemas/type/elementary/flags.schema.yaml @@ -0,0 +1,46 @@ +$schema: "https://json-schema.org/draft/2020-12/schema" +$id: "schema:ethdebug/format/type/elementary/flags" + +title: ethdebug/format/type/elementary/flags +description: | + Schema describing the representation of a flags type: a set of named + flags. + + Standard interpretation: read the bytes of the value as a big-endian + unsigned integer. If bit `i` is set, `values[i]` is in the set. The + value 0 is the empty set. A value with a bit set at or above + `values.length` is invalid. + +type: object +properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" + class: + const: elementary + kind: + const: flags + values: + description: The names of the flags, where `values[i]` is bit `i`. + type: array + items: + type: string + minItems: 1 + uniqueItems: true + definition: + $ref: "schema:ethdebug/format/type/definition" +required: + - kind + - values +examples: + - kind: flags + values: + - READ + - WRITE + - EXECUTE + - kind: flags + label: Permissions + values: + - READ + - WRITE + definition: + name: Permissions diff --git a/schemas/type/elementary/int.schema.yaml b/schemas/type/elementary/int.schema.yaml deleted file mode 100644 index f85f730fb7..0000000000 --- a/schemas/type/elementary/int.schema.yaml +++ /dev/null @@ -1,25 +0,0 @@ -$schema: "https://json-schema.org/draft/2020-12/schema" -$id: "schema:ethdebug/format/type/elementary/int" - -title: ethdebug/format/type/elementary/int -description: Schema describing the representation of a signed integer type - -type: object -properties: - label: - $ref: "schema:ethdebug/format/type/base#/$defs/Label" - class: - const: elementary - kind: - const: int - bits: - type: integer - multipleOf: 8 - minimum: 8 - maximum: 256 -required: - - kind - - bits -examples: - - kind: int - bits: 256 diff --git a/schemas/type/elementary/number.schema.yaml b/schemas/type/elementary/number.schema.yaml new file mode 100644 index 0000000000..a30fa2cfaa --- /dev/null +++ b/schemas/type/elementary/number.schema.yaml @@ -0,0 +1,47 @@ +$schema: "https://json-schema.org/draft/2020-12/schema" +$id: "schema:ethdebug/format/type/elementary/number" + +title: ethdebug/format/type/elementary/number +description: | + Schema describing the representation of a number type, covering unsigned + and signed integers and fixed-point numbers. + + Standard interpretation: read the bytes of the value as a big-endian + integer `v`, in two's complement if `signed` is true. The number is + `v / 10**places`. + + This type has no width. The number of bytes comes from the value's + location. + +type: object +properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" + class: + const: elementary + kind: + const: number + signed: + description: Whether the integer is in two's complement. + type: boolean + default: false + places: + description: The number of decimal places of the fixed-point number. + type: integer + minimum: 0 + default: 0 +required: + - kind +examples: + - # an unsigned integer + kind: number + - # a signed integer + kind: number + signed: true + - # a fixed-point number with 10 decimal places + kind: number + signed: true + places: 10 + - # a number with a label + kind: number + label: uint8 diff --git a/schemas/type/elementary/string.schema.yaml b/schemas/type/elementary/string.schema.yaml index 96eba5aebc..d5c3044235 100644 --- a/schemas/type/elementary/string.schema.yaml +++ b/schemas/type/elementary/string.schema.yaml @@ -2,7 +2,12 @@ $schema: "https://json-schema.org/draft/2020-12/schema" $id: "schema:ethdebug/format/type/elementary/string" title: ethdebug/format/type/elementary/string -description: Schema describing the representation of a string type +description: | + Schema describing the representation of a string type. + + Standard interpretation: decode the bytes of the value with `encoding`. + If the bytes are not a valid sequence in that encoding, the value is + invalid. type: object properties: @@ -23,3 +28,5 @@ examples: - kind: string - kind: string encoding: utf-16le + - kind: string + label: string diff --git a/schemas/type/elementary/ufixed.schema.yaml b/schemas/type/elementary/ufixed.schema.yaml deleted file mode 100644 index d30b45e0b8..0000000000 --- a/schemas/type/elementary/ufixed.schema.yaml +++ /dev/null @@ -1,37 +0,0 @@ -$schema: "https://json-schema.org/draft/2020-12/schema" -$id: "schema:ethdebug/format/type/elementary/ufixed" - -title: ethdebug/format/type/elementary/ufixed -description: Schema describing the representation of an unsigned fixed decimal type - -type: object -properties: - label: - $ref: "schema:ethdebug/format/type/base#/$defs/Label" - class: - const: elementary - kind: - const: ufixed - bits: - type: integer - multipleOf: 8 - minimum: 8 - maximum: 256 - places: - type: integer - description: - How many decimal places, implying that an unscaled value `v` of this - type should be interpreted as `v / (10**places)` - minimum: 0 - maximum: 80 -required: - - kind - - bits - - places -examples: - - kind: ufixed - bits: 256 - places: 10 - - kind: ufixed - bits: 64 - places: 0 diff --git a/schemas/type/elementary/uint.schema.yaml b/schemas/type/elementary/uint.schema.yaml deleted file mode 100644 index aa2590329b..0000000000 --- a/schemas/type/elementary/uint.schema.yaml +++ /dev/null @@ -1,25 +0,0 @@ -$schema: "https://json-schema.org/draft/2020-12/schema" -$id: "schema:ethdebug/format/type/elementary/uint" - -title: ethdebug/format/type/elementary/uint -description: Schema describing the representation of an unsigned integer type - -type: object -properties: - label: - $ref: "schema:ethdebug/format/type/base#/$defs/Label" - class: - const: elementary - kind: - const: uint - bits: - type: integer - multipleOf: 8 - minimum: 8 - maximum: 256 -required: - - kind - - bits -examples: - - kind: uint - bits: 256 diff --git a/schemas/type/specifier.schema.yaml b/schemas/type/specifier.schema.yaml index 8781c890e8..af51a6a989 100644 --- a/schemas/type/specifier.schema.yaml +++ b/schemas/type/specifier.schema.yaml @@ -15,6 +15,5 @@ else: $ref: "schema:ethdebug/format/type" examples: - - kind: uint - bits: 256 + - kind: number - id: 42 From 9cb9ba6063d6c3f96cace58cb33bb1ef62533261 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:11:17 -0500 Subject: [PATCH 03/19] format: fix address standard interpretation --- schemas/type/elementary/address.schema.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/schemas/type/elementary/address.schema.yaml b/schemas/type/elementary/address.schema.yaml index c19882ae95..98600077ac 100644 --- a/schemas/type/elementary/address.schema.yaml +++ b/schemas/type/elementary/address.schema.yaml @@ -6,9 +6,9 @@ description: | Schema describing the representation of an address type. An address type with a `definition` is a reference to a contract. - Standard interpretation: read the bytes of the value as a big-endian - unsigned integer. That integer is the address. This type has no size. - The number of bytes comes from the value's location. + Standard interpretation: the bytes of the value are the address. If the + type has a `definition`, the value refers to that contract. This type has + no size. The number of bytes comes from the value's location. type: object properties: From 6f9f182fa5b798cf501d09340a8b2d577af705f7 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:13:29 -0500 Subject: [PATCH 04/19] format: replace complex type kinds --- packages/format/src/types/type/index.test.ts | 63 ++++++- packages/format/src/types/type/index.ts | 131 ++++++++++----- packages/format/test/extensions.ts | 8 +- schemas/type/complex.schema.yaml | 16 +- schemas/type/complex/array.schema.yaml | 15 +- schemas/type/complex/function.schema.yaml | 168 ++++++++----------- schemas/type/complex/struct.schema.yaml | 17 +- schemas/type/complex/tuple.schema.yaml | 59 ------- schemas/type/complex/variant.schema.yaml | 92 ++++++++++ 9 files changed, 345 insertions(+), 224 deletions(-) delete mode 100644 schemas/type/complex/tuple.schema.yaml create mode 100644 schemas/type/complex/variant.schema.yaml diff --git a/packages/format/src/types/type/index.test.ts b/packages/format/src/types/type/index.test.ts index 605dd0d5bd..cea73693f7 100644 --- a/packages/format/src/types/type/index.test.ts +++ b/packages/format/src/types/type/index.test.ts @@ -57,10 +57,6 @@ testSchemaGuards("ethdebug/format/type", [ schema: "schema:ethdebug/format/type/complex/alias", guard: Type.Complex.isAlias, }, - { - schema: "schema:ethdebug/format/type/complex/tuple", - guard: Type.Complex.isTuple, - }, { schema: "schema:ethdebug/format/type/complex/array", guard: Type.Complex.isArray, @@ -73,6 +69,14 @@ testSchemaGuards("ethdebug/format/type", [ schema: "schema:ethdebug/format/type/complex/struct", guard: Type.Complex.isStruct, }, + { + schema: "schema:ethdebug/format/type/complex/variant", + guard: Type.Complex.isVariant, + }, + { + schema: "schema:ethdebug/format/type/complex/function", + guard: Type.Complex.isFunction, + }, // type reference and specifier @@ -187,6 +191,57 @@ describe("rejected values", () => { title: "a repeated flags value", value: { kind: "flags", values: ["A", "A"] }, }, + { + title: "the removed tuple kind", + value: { kind: "tuple", contains: [] }, + }, + { + title: "a variant case without a discriminant", + value: { kind: "variant", cases: [{ name: "A" }] }, + }, + { + title: "a variant case with a payload that is not a wrapper", + value: { + kind: "variant", + cases: [{ name: "A", discriminant: 0, payload: { kind: "bool" } }], + }, + }, + { + title: "a function without returns", + value: { kind: "function", internal: true, parameters: [] }, + }, + { + title: "the old function shape", + value: { + kind: "function", + internal: true, + contains: { parameters: { type: { kind: "struct", contains: [] } } }, + }, + }, + { + title: "a function with neither internal nor external", + value: { kind: "function", parameters: [], returns: [] }, + }, + { + title: "an internal function with a contract", + value: { + kind: "function", + internal: true, + parameters: [], + returns: [], + contract: { type: { id: "C" } }, + }, + }, + { + title: "an external function with a plain address contract", + value: { + kind: "function", + external: true, + parameters: [], + returns: [], + contract: { type: { kind: "address" } }, + }, + }, { title: "a non-string label", value: { kind: "bool", label: 7 }, diff --git a/packages/format/src/types/type/index.ts b/packages/format/src/types/type/index.ts index 04fd52f237..8ec9bc31fa 100644 --- a/packages/format/src/types/type/index.ts +++ b/packages/format/src/types/type/index.ts @@ -1,3 +1,4 @@ +import { Data } from "#types/data"; import { Materials } from "#types/materials"; import * as _Base from "./base.js"; @@ -231,11 +232,11 @@ export namespace Type { export type Complex = | Complex.Alias - | Complex.Tuple | Complex.Array | Complex.Mapping - | Complex.Struct; - /* currently unsupported: | Complex.Function */ + | Complex.Struct + | Complex.Variant + | Complex.Function; export const hasComplexKind = ( value: unknown, @@ -246,22 +247,18 @@ export namespace Type { !!value && "kind" in value && typeof value.kind === "string" && - [ - "alias", - "tuple", - "array", - "mapping", - "struct", - // "function" - ].includes(value.kind); + ["alias", "array", "mapping", "struct", "variant", "function"].includes( + value.kind, + ); export const isComplex = (value: unknown): value is Complex => [ Complex.isAlias, - Complex.isTuple, Complex.isArray, Complex.isMapping, Complex.isStruct, + Complex.isVariant, + Complex.isFunction, ].some((guard) => guard(value)); export namespace Complex { @@ -283,27 +280,6 @@ export namespace Type { isWrapper(value.contains) && (!("definition" in value) || isDefinition(value.definition)); - export interface Tuple { - class?: "complex"; - kind: "tuple"; - label?: string; - contains: (Wrapper & { name?: string })[]; - } - - export const isTuple = (value: unknown): value is Tuple => - typeof value === "object" && - !!value && - mayHaveClass(value, "complex") && - mayHaveLabel(value) && - hasKind(value, "tuple") && - "contains" in value && - Array.isArray(value.contains) && - value.contains.every( - (element) => - isWrapper(element) && - (!("name" in element) || typeof element.name === "string"), - ); - export interface Array { class?: "complex"; kind: "array"; @@ -348,7 +324,7 @@ export namespace Type { class?: "complex"; kind: "struct"; label?: string; - contains: (Wrapper & { name?: string })[]; + contains: Named[]; definition?: Definition; } @@ -360,12 +336,89 @@ export namespace Type { hasKind(value, "struct") && "contains" in value && Array.isArray(value.contains) && - value.contains.every( - (field) => - isWrapper(field) && - (!("name" in field) || typeof field.name === "string"), - ) && + value.contains.every(isNamed) && + (!("definition" in value) || isDefinition(value.definition)); + + export interface Variant { + class?: "complex"; + kind: "variant"; + label?: string; + cases: Variant.Case[]; + definition?: Definition; + } + + export namespace Variant { + export interface Case { + name: string; + discriminant: Data.Value; + payload?: Wrapper; + } + + export const isCase = (value: unknown): value is Case => + typeof value === "object" && + !!value && + "name" in value && + typeof value.name === "string" && + "discriminant" in value && + Data.isValue(value.discriminant) && + (!("payload" in value) || isWrapper(value.payload)); + } + + export const isVariant = (value: unknown): value is Variant => + typeof value === "object" && + !!value && + mayHaveClass(value, "complex") && + mayHaveLabel(value) && + hasKind(value, "variant") && + "cases" in value && + Array.isArray(value.cases) && + value.cases.every(Variant.isCase) && (!("definition" in value) || isDefinition(value.definition)); + + export interface Function { + class?: "complex"; + kind: "function"; + label?: string; + internal?: boolean; + external?: boolean; + parameters: Named[]; + returns: Named[]; + definition?: Definition; + contract?: Wrapper; + } + + const isContractWrapper = (value: unknown): value is Wrapper => + isWrapper(value) && + (isReference(value.type) || + (Elementary.isAddress(value.type) && !!value.type.definition)); + + export const isFunction = (value: unknown): value is Function => + typeof value === "object" && + !!value && + mayHaveClass(value, "complex") && + mayHaveLabel(value) && + hasKind(value, "function") && + "parameters" in value && + Array.isArray(value.parameters) && + value.parameters.every(isNamed) && + "returns" in value && + Array.isArray(value.returns) && + value.returns.every(isNamed) && + (!("definition" in value) || isDefinition(value.definition)) && + // exactly one of internal / external is true + ("external" in value && value.external === true + ? (!("internal" in value) || value.internal === false) && + (!("contract" in value) || isContractWrapper(value.contract)) + : "internal" in value && + value.internal === true && + (!("external" in value) || value.external === false) && + !("contract" in value)); + + type Named = Wrapper & { name?: string }; + + const isNamed = (value: unknown): value is Named => + isWrapper(value) && + (!("name" in value) || typeof value.name === "string"); } export interface Definition { diff --git a/packages/format/test/extensions.ts b/packages/format/test/extensions.ts index 20e07ec7d4..57051c4747 100644 --- a/packages/format/test/extensions.ts +++ b/packages/format/test/extensions.ts @@ -57,9 +57,6 @@ export const schemaExtensions: { "schema:ethdebug/format/type/complex/alias": { extends: new Set(["schema:ethdebug/format/type/complex"]), }, - "schema:ethdebug/format/type/complex/tuple": { - extends: new Set(["schema:ethdebug/format/type/complex"]), - }, "schema:ethdebug/format/type/complex/array": { extends: new Set(["schema:ethdebug/format/type/complex"]), }, @@ -69,7 +66,6 @@ export const schemaExtensions: { "schema:ethdebug/format/type/complex/struct": { extends: new Set(["schema:ethdebug/format/type/complex"]), }, - "schema:ethdebug/format/type/complex/function": { - extends: new Set(["schema:ethdebug/format/type/complex"]), - }, + // function and variant are absent on purpose. They have no `contains`, + // so they are not valid base complex types. }; diff --git a/schemas/type/complex.schema.yaml b/schemas/type/complex.schema.yaml index c69933ff1c..4d56c8b6a4 100644 --- a/schemas/type/complex.schema.yaml +++ b/schemas/type/complex.schema.yaml @@ -19,13 +19,6 @@ allOf: then: $ref: "schema:ethdebug/format/type/complex/alias" - - if: - properties: - kind: - const: tuple - then: - $ref: "schema:ethdebug/format/type/complex/tuple" - - if: properties: kind: @@ -54,6 +47,13 @@ allOf: then: $ref: "schema:ethdebug/format/type/complex/function" + - if: + properties: + kind: + const: variant + then: + $ref: "schema:ethdebug/format/type/complex/variant" + $defs: Kind: title: Known complex kind @@ -63,8 +63,8 @@ $defs: type: string enum: - alias - - tuple - array - mapping - struct - function + - variant diff --git a/schemas/type/complex/array.schema.yaml b/schemas/type/complex/array.schema.yaml index 252df9ac20..7593636458 100644 --- a/schemas/type/complex/array.schema.yaml +++ b/schemas/type/complex/array.schema.yaml @@ -3,9 +3,9 @@ $id: "schema:ethdebug/format/type/complex/array" title: ethdebug/format/type/complex/array description: | - Schema for representing array types, both fixed-size and dynamically - sized. An array type specifies the element type it contains and, - optionally, a fixed element count. + Schema for representing array types. An array type specifies the + element type it contains. It has no element count. The number of + elements comes from the value's location. type: object properties: @@ -22,11 +22,6 @@ properties: The element type contained by this array, specified as an **ethdebug/format/type/wrapper**. $ref: "schema:ethdebug/format/type/wrapper" - count: - description: | - The fixed number of elements in this array. When omitted, the array - is dynamically sized. - $ref: "schema:ethdebug/format/data/value" required: - kind @@ -39,9 +34,9 @@ examples: type: kind: number - # example: a fixed-size array of 10 addresses + # example: an array of addresses - kind: array - count: 10 + label: "address[10]" contains: type: kind: address diff --git a/schemas/type/complex/function.schema.yaml b/schemas/type/complex/function.schema.yaml index f2fe4485ec..8ad4070a98 100644 --- a/schemas/type/complex/function.schema.yaml +++ b/schemas/type/complex/function.schema.yaml @@ -11,9 +11,12 @@ description: | Internal function types require the `"internal": true` field; external function types require `"external": true`. - Note that external function types may include a representation of the - contract type that defines or provides this function as an external - interface. + A function type lists its `parameters` and its `returns`. An empty + `returns` list means that the function returns no values. + + External function types may include a `contract` field. It is a wrapper + around the contract type that provides this function as an external + interface. Internal function types must not have a `contract` field. type: object properties: @@ -25,48 +28,31 @@ properties: kind: type: string const: function - contains: - type: object - title: Parameter and return types + parameters: + type: array + title: Parameter types description: | - Types this function type composes. Function types inherently compose - two groupings of types (an ordered list of parameter types and typically - either a return value or return parameters). Function types' `contains` - field is organized as a mapping of `parameters` types (a type wrapper for - a tuple type) and an optional `returns` type (either a generic type - wrapper or a type wrapper for a tuple type). - - This definition applies for both cases (internal and external function - types). Each of those specific types may expand this `contains` field - schema with other semantic details (such as an external function type - indicating the contract type from which it is exposed). - properties: - parameters: - $ref: "#/$defs/Parameters" - returns: - type: object - title: Return type (or tuple of types) - description: | - To accommodate languages differing in whether functions return single - values or lists of values, this field may be either a generic type - wrapper or explicitly defined as a type wrapper around a tuple type. - - Debuggers that implement this schema **should** be aware that - languages whose functions return sole values might return tuple - types. Resolving this ambiguity remains outside the scope of the - schema (but compilers **must** be consistent when representing - function types in this schema). - anyOf: - - $ref: "schema:ethdebug/format/type/wrapper" - - $ref: "#/$defs/Parameters" - required: - - parameters + The ordered list of parameter types. Each item is an + **ethdebug/format/type/wrapper** that may have a `name`. + items: + $ref: "#/$defs/Value" + returns: + type: array + title: Return types + description: | + The ordered list of return types. Each item is an + **ethdebug/format/type/wrapper** that may have a `name`. + An empty list means that the function returns no values. A function + that returns one tuple value has a list of one struct type. + items: + $ref: "#/$defs/Value" definition: $ref: "schema:ethdebug/format/type/definition" required: - kind - - contains + - parameters + - returns oneOf: - type: object @@ -76,25 +62,25 @@ oneOf: const: false external: const: true - contains: - type: object - title: Additional contents - properties: - contract: - type: object - title: Contract type providing external function - description: - A wrapper around the contract type that composes this external - function type. - allOf: - - $ref: "schema:ethdebug/format/type/wrapper" - - type: object - title: Contract type wrapper - properties: - type: - oneOf: + contract: + title: Contract type providing external function + description: | + A wrapper around the contract type that provides this external + function. The type is an **ethdebug/format/type/elementary/address** + that has a `definition`, or an **ethdebug/format/type/reference**. + allOf: + - $ref: "schema:ethdebug/format/type/wrapper" + - type: object + title: Contract type wrapper + properties: + type: + oneOf: + - allOf: - $ref: "schema:ethdebug/format/type/elementary/address" - - $ref: "schema:ethdebug/format/type/reference" + - type: object + required: + - definition + - $ref: "schema:ethdebug/format/type/reference" required: - external @@ -105,6 +91,8 @@ oneOf: const: true external: const: false + contract: + not: {} required: - internal @@ -113,59 +101,45 @@ examples: internal: true definition: name: increment - contains: - parameters: - type: - kind: tuple - contains: - - name: value - type: - kind: number - returns: + parameters: + - name: value type: kind: number + returns: + - type: + kind: number + - kind: function external: true definition: name: withdraw - contains: - contract: + contract: + type: + kind: address + payable: true + definition: + name: Bank + interface: true + parameters: + - name: beneficiary type: kind: address payable: true - definition: - name: Bank - interface: true - parameters: - type: - kind: tuple - contains: - - name: beneficiary - type: - kind: address - payable: true - - name: amount - type: - kind: number - places: 18 - returns: + - name: amount type: - kind: tuple - contains: [] + kind: number + places: 18 + returns: [] $defs: - Parameters: + Value: type: object - title: Parameters - description: - A type wrapper around a tuple of types. This schema uses a tuple type to - represent an ordered list of types. + title: Parameter or return type + description: | + An **ethdebug/format/type/wrapper** with an optional `name`. allOf: - $ref: "schema:ethdebug/format/type/wrapper" - - title: Tuple type wrapper - type: object + - type: object properties: - type: - oneOf: - - $ref: "schema:ethdebug/format/type/complex/tuple" - - $ref: "schema:ethdebug/format/type/reference" + name: + type: string diff --git a/schemas/type/complex/struct.schema.yaml b/schemas/type/complex/struct.schema.yaml index cf90cc1192..ee60ecccb4 100644 --- a/schemas/type/complex/struct.schema.yaml +++ b/schemas/type/complex/struct.schema.yaml @@ -2,7 +2,10 @@ $schema: "https://json-schema.org/draft/2020-12/schema" $id: "schema:ethdebug/format/type/complex/struct" title: ethdebug/format/type/complex/struct -description: Schema for representing struct types +description: | + Schema for representing struct types. A struct type is an ordered list + of member types. Members may have names. A struct with no named members + is a tuple. A struct with no members is legal. type: object properties: @@ -35,6 +38,18 @@ examples: type: kind: number + - # a struct with unnamed members (a tuple) + kind: struct + contains: + - type: + kind: number + - type: + kind: bool + + - # a struct with no members + kind: struct + contains: [] + $defs: MemberField: type: object diff --git a/schemas/type/complex/tuple.schema.yaml b/schemas/type/complex/tuple.schema.yaml deleted file mode 100644 index ca6f759b9e..0000000000 --- a/schemas/type/complex/tuple.schema.yaml +++ /dev/null @@ -1,59 +0,0 @@ -$schema: "https://json-schema.org/draft/2020-12/schema" -$id: "schema:ethdebug/format/type/complex/tuple" - -title: ethdebug/format/type/complex/tuple -description: Schema for representing tuple types - -type: object -properties: - label: - $ref: "schema:ethdebug/format/type/base#/$defs/Label" - class: - type: string - const: complex - kind: - type: string - const: tuple - contains: - type: array - items: - $ref: "#/$defs/Element" - -required: - - kind - - contains - -examples: - - # empty tuple type - kind: tuple - contains: [] - - - kind: tuple - contains: - - name: x - type: - kind: number - - name: y - type: - kind: number - -$defs: - Element: - type: object - title: Element - description: An optionally named element type within a tuple. This is an - **ethdebug/format/type/wrapper** with additional fields. - allOf: - - $ref: "schema:ethdebug/format/type/wrapper" - - title: Additional fields - type: object - properties: - name: - type: string - description: - For tuple types where positional element types are identified - by name, this field **should** include this information. - - This schema makes no restriction on whether all-or-no elements - have names, and so this field may be sparse across elements of - the same tuple. diff --git a/schemas/type/complex/variant.schema.yaml b/schemas/type/complex/variant.schema.yaml new file mode 100644 index 0000000000..7797f8163e --- /dev/null +++ b/schemas/type/complex/variant.schema.yaml @@ -0,0 +1,92 @@ +$schema: "https://json-schema.org/draft/2020-12/schema" +$id: "schema:ethdebug/format/type/complex/variant" + +title: ethdebug/format/type/complex/variant +description: | + Schema for representing variant types. A variant type is a value that is + exactly one of a list of cases. Each case has a name, a `discriminant` + and, optionally, a `payload` type. + + The active case is the case whose `discriminant` equals the value read + for the discriminant. If no case matches, the value is invalid. + + This type says what each case is. It does not say where the discriminant + and the payload are. A realization gives their locations. + +type: object +properties: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" + class: + type: string + const: complex + kind: + type: string + const: variant + cases: + type: array + items: + $ref: "#/$defs/Case" + definition: + $ref: "schema:ethdebug/format/type/definition" + +required: + - kind + - cases + +examples: + - # a variant with a case that has no payload + kind: variant + label: Option + cases: + - name: None + discriminant: 0 + - name: Some + discriminant: 1 + payload: + type: + kind: number + + - # a variant with different payloads + kind: variant + definition: + name: Shape + cases: + - name: Circle + discriminant: "0x00" + payload: + type: + kind: number + - name: Rectangle + discriminant: "0x01" + payload: + type: + kind: struct + contains: + - name: width + type: + kind: number + - name: height + type: + kind: number + +$defs: + Case: + type: object + title: Variant case + properties: + name: + type: string + description: The name of this case. + discriminant: + description: | + The value of the discriminant that selects this case. + $ref: "schema:ethdebug/format/data/value" + payload: + description: | + The type of the data this case holds, if any. A case without a + `payload` holds no data. + $ref: "schema:ethdebug/format/type/wrapper" + required: + - name + - discriminant From 5985ef7a33a8e528a69ea439c5f2d4efb1aeaffb Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:14:59 -0500 Subject: [PATCH 05/19] format: list the new kinds in the schema extension map --- packages/format/test/extensions.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/packages/format/test/extensions.ts b/packages/format/test/extensions.ts index 57051c4747..7ff755fbfc 100644 --- a/packages/format/test/extensions.ts +++ b/packages/format/test/extensions.ts @@ -18,10 +18,10 @@ export const schemaExtensions: { "schema:ethdebug/format/type/base#/$defs/ElementaryType", ]), }, - "schema:ethdebug/format/type/elementary/uint": { + "schema:ethdebug/format/type/elementary/number": { extends: new Set(["schema:ethdebug/format/type/elementary"]), }, - "schema:ethdebug/format/type/elementary/int": { + "schema:ethdebug/format/type/elementary/flags": { extends: new Set(["schema:ethdebug/format/type/elementary"]), }, "schema:ethdebug/format/type/elementary/bool": { @@ -33,18 +33,9 @@ export const schemaExtensions: { "schema:ethdebug/format/type/elementary/string": { extends: new Set(["schema:ethdebug/format/type/elementary"]), }, - "schema:ethdebug/format/type/elementary/ufixed": { - extends: new Set(["schema:ethdebug/format/type/elementary"]), - }, - "schema:ethdebug/format/type/elementary/fixed": { - extends: new Set(["schema:ethdebug/format/type/elementary"]), - }, "schema:ethdebug/format/type/elementary/address": { extends: new Set(["schema:ethdebug/format/type/elementary"]), }, - "schema:ethdebug/format/type/elementary/contract": { - extends: new Set(["schema:ethdebug/format/type/elementary"]), - }, "schema:ethdebug/format/type/elementary/enum": { extends: new Set(["schema:ethdebug/format/type/elementary"]), }, @@ -66,6 +57,7 @@ export const schemaExtensions: { "schema:ethdebug/format/type/complex/struct": { extends: new Set(["schema:ethdebug/format/type/complex"]), }, - // function and variant are absent on purpose. They have no `contains`, - // so they are not valid base complex types. + // function and variant are absent on purpose. Listing them under + // type/complex fails: the check follows that entry up to the base + // complex type, which requires `contains`. These kinds have none. }; From 466a0084cfcde28825be781a2c71b94517517744 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:16:26 -0500 Subject: [PATCH 06/19] format: move embedded type examples to new kinds --- schemas/info.schema.yaml | 14 +++++--------- schemas/info/resources.schema.yaml | 8 ++++---- schemas/program.schema.yaml | 8 ++++---- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/schemas/info.schema.yaml b/schemas/info.schema.yaml index d3ecd6de0e..9f32b58f6e 100644 --- a/schemas/info.schema.yaml +++ b/schemas/info.schema.yaml @@ -142,19 +142,15 @@ examples: kind: "address" - name: "amount" type: - kind: "uint" - bits: 256 + kind: "number" + label: "uint256" - name: "canRemit" type: kind: "function" internal: true - contains: - parameters: - type: - kind: "tuple" - contains: [] - returns: - type: + parameters: [] + returns: + - type: kind: "bool" pointers: diff --git a/schemas/info/resources.schema.yaml b/schemas/info/resources.schema.yaml index ddb1ec6a89..568073f416 100644 --- a/schemas/info/resources.schema.yaml +++ b/schemas/info/resources.schema.yaml @@ -65,12 +65,12 @@ examples: contains: - name: x type: - kind: uint - bits: 128 + kind: number + label: uint128 - name: y type: - kind: uint - bits: 128 + kind: number + label: uint128 definition: name: Coordinate location: diff --git a/schemas/program.schema.yaml b/schemas/program.schema.yaml index 1697c5dd69..936a23467b 100644 --- a/schemas/program.schema.yaml +++ b/schemas/program.schema.yaml @@ -106,8 +106,8 @@ examples: - &stored-value identifier: storedValue type: - kind: uint - bits: 256 + kind: number + label: uint256 pointer: location: storage slot: 0 @@ -127,8 +127,8 @@ examples: - &local-value identifier: localValue type: - kind: uint - bits: 256 + kind: number + label: uint256 pointer: location: stack slot: 0 From 31d3da1cfb6c72e1ba2233abf28c9b3ec93e5fd1 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:21:27 -0500 Subject: [PATCH 07/19] bugc: emit the new type kinds --- .../debug/local-variables.soundness.test.ts | 4 +- .../src/evmgen/debug/local-variables.test.ts | 2 +- packages/bugc/src/irgen/debug/types.ts | 63 +++++-------------- 3 files changed, 18 insertions(+), 51 deletions(-) diff --git a/packages/bugc/src/evmgen/debug/local-variables.soundness.test.ts b/packages/bugc/src/evmgen/debug/local-variables.soundness.test.ts index 26295d270a..ab35540076 100644 --- a/packages/bugc/src/evmgen/debug/local-variables.soundness.test.ts +++ b/packages/bugc/src/evmgen/debug/local-variables.soundness.test.ts @@ -1656,10 +1656,10 @@ code { const strings = await pointerOf("string calldata"); const bytes = await pointerOf("bytes calldata"); for (const entry of strings) { - expect(entry.type).toEqual({ kind: "string" }); + expect(entry.type).toEqual({ kind: "string", label: "string" }); } for (const entry of bytes) { - expect(entry.type).toEqual({ kind: "bytes" }); + expect(entry.type).toEqual({ kind: "bytes", label: "bytes" }); } expect(strings.map((entry) => entry.pointer)).toEqual( bytes.map((entry) => entry.pointer), diff --git a/packages/bugc/src/evmgen/debug/local-variables.test.ts b/packages/bugc/src/evmgen/debug/local-variables.test.ts index 5e6600b431..b79691552a 100644 --- a/packages/bugc/src/evmgen/debug/local-variables.test.ts +++ b/packages/bugc/src/evmgen/debug/local-variables.test.ts @@ -92,7 +92,7 @@ code { r = add(3, 4); }`; expect(entry, `variables entry for ${name}`).toBeDefined(); expect(entry!.identifier).toBe(name); expect(isFrameRelative(entry!.pointer)).toBe(true); - expect(entry!.type).toEqual({ kind: "uint", bits: 256 }); + expect(entry!.type).toEqual({ kind: "number", label: "uint256" }); } }); diff --git a/packages/bugc/src/irgen/debug/types.ts b/packages/bugc/src/irgen/debug/types.ts index 9a9ace4d97..c162221a0c 100644 --- a/packages/bugc/src/irgen/debug/types.ts +++ b/packages/bugc/src/irgen/debug/types.ts @@ -51,7 +51,6 @@ export function convertBugType(bugType: BugType): Format.Type | undefined { contains: { type: elementType, }, - ...(bugType.size !== undefined && { length: bugType.size }), }; } @@ -113,47 +112,30 @@ function convertElementaryType( switch (kind) { case "uint": - return { - kind: "uint", - bits: elementary.bits, - }; + return { kind: "number", label: `uint${elementary.bits}` }; case "int": return { - kind: "int", - bits: elementary.bits, + kind: "number", + signed: true, + label: `int${elementary.bits}`, }; case "address": - return { - kind: "address", - // payable is optional, omit if unknown - }; + return { kind: "address", label: "address" }; case "bool": + return { kind: "bool", label: "bool" }; + + case "bytes": return { - kind: "bool", + kind: "bytes", + label: + elementary.size !== undefined ? `bytes${elementary.size}` : "bytes", }; - case "bytes": { - if (elementary.size !== undefined) { - // Fixed-size bytes (bytes1 - bytes32) - return { - kind: "bytes", - size: elementary.size, - }; - } else { - // Dynamic bytes - return { - kind: "bytes", - }; - } - } - case "string": - return { - kind: "string", - }; + return { kind: "string", label: "string" }; default: return undefined; @@ -168,28 +150,13 @@ function convertElementaryType( */ function convertSyntheticType(irType: Ir.Type): Format.Type | undefined { if (Ir.Type.isScalar(irType)) { - // Scalar types - infer based on size - const bits = irType.size * 8; - - // Common patterns for synthetic scalars - if (irType.size === 32) { - // Most 32-byte scalars are uint256 - return { kind: "uint", bits: 256 }; - } - + // Scalar types - infer based on size; bugc knows no spelling, + // so synthetic types carry no label if (irType.size === 20) { - // 20-byte scalars are addresses return { kind: "address" }; } - if (irType.size === 1) { - // 1-byte scalars could be bool or uint8 - // Default to uint8 for safety - return { kind: "uint", bits: 8 }; - } - - // For other sizes, use uint with appropriate bit size - return { kind: "uint", bits }; + return { kind: "number" }; } if (Ir.Type.isRef(irType)) { From 75090dc7c7b13adf408082e682aaa7f9778183cb Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:25:43 -0500 Subject: [PATCH 08/19] web, conformance: read the new type kinds --- packages/conformance/test/conformance.test.ts | 50 ++++++++++++++++--- .../src/utils/mockTrace.test.ts | 12 ++--- .../src/theme/ProgramExample/TraceDrawer.tsx | 17 ++----- 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/packages/conformance/test/conformance.test.ts b/packages/conformance/test/conformance.test.ts index 50e8e19a7a..e7c5e89dbd 100644 --- a/packages/conformance/test/conformance.test.ts +++ b/packages/conformance/test/conformance.test.ts @@ -109,8 +109,8 @@ function validResources() { compilation: validCompilation(), types: { CounterSlot: { - kind: "uint", - bits: 256, + kind: "number", + label: "uint256", }, }, pointers: { @@ -157,6 +157,18 @@ function withoutResourcesStamp( return rest; } +// Expected failure (#423): solc's `resources.types` still uses the type +// kinds that #282 replaced, so its resources do not validate. Conformance +// checks solc resources without the table. The tripwire test below fails +// once solc's types validate; then remove this function and the tripwire. +function withoutResourcesTypes(artifact: EthdebugArtifact): EthdebugArtifact { + if (!artifact.resources) { + return artifact; + } + const { types: _, ...resources } = artifact.resources; + return { ...artifact, resources } as EthdebugArtifact; +} + function validArtifact( overrides: Partial = {}, ): EthdebugArtifact { @@ -202,7 +214,9 @@ describe("@ethdebug/conformance", () => { sourcePath: path.join(root, "test/fixtures/solc/Counter.sol"), }); - const result = await validateStaticConformance(artifact); + const result = await validateStaticConformance( + withoutResourcesTypes(artifact), + ); expect(result.issues).toEqual([]); expect(result.ok).toBe(true); expect( @@ -211,6 +225,28 @@ describe("@ethdebug/conformance", () => { }, ); + // Expected failure (#423): see withoutResourcesTypes. + it.skipIf(!solc)( + "[solc] resources types do not yet validate (#423)", + async () => { + const artifact = await compileEthdebug({ + kind: "solc", + solcPath: solc!, + sourcePath: path.join(root, "test/fixtures/solc/Counter.sol"), + }); + + const result = await validateStaticConformance(artifact); + + expect( + result.ok, + "solc's types now validate; remove withoutResourcesTypes (#423)", + ).toBe(false); + for (const { message } of result.issues) { + expect(message).toContain("schema:ethdebug/format/info/resources"); + } + }, + ); + it.skipIf(!soldb || !solc)( "[soldb] checks solc ETHDebug resources through the SolDB consumer backend", async () => { @@ -311,7 +347,9 @@ describe("@ethdebug/conformance", () => { path.join(sourceDir, "Math.sol"), ], }); - const result = await validateStaticConformance(artifact); + const result = await validateStaticConformance( + withoutResourcesTypes(artifact), + ); expect(result.issues).toEqual([]); expect(result.ok).toBe(true); @@ -583,8 +621,8 @@ describe("@ethdebug/conformance", () => { ); expect(resources.types.CounterSlot).toEqual({ - kind: "uint", - bits: 256, + kind: "number", + label: "uint256", }); expect(resources.pointers.CounterSlotStorage).toEqual({ expect: ["slot"], diff --git a/packages/programs-react/src/utils/mockTrace.test.ts b/packages/programs-react/src/utils/mockTrace.test.ts index f2bef2efbc..8c48db0074 100644 --- a/packages/programs-react/src/utils/mockTrace.test.ts +++ b/packages/programs-react/src/utils/mockTrace.test.ts @@ -67,7 +67,7 @@ describe("extractVariablesFromInstruction", () => { it("composes two entries for one variable", () => { const declaration = { source: { id: 0 }, range: { offset: 1 } }; - const typed = { identifier: "x", declaration, type: { kind: "uint" } }; + const typed = { identifier: "x", declaration, type: { kind: "number" } }; const located = { identifier: "x", declaration, pointer: x.pointer }; expect( extractVariablesFromInstruction( @@ -113,8 +113,8 @@ describe("extractVariablesFromInstruction", () => { extractVariablesFromInstruction( instr(0, { pick: [ - { variables: [x({ kind: "uint", bits: 8 })] }, - { variables: [x({ kind: "int", bits: 8 })] }, + { variables: [x({ kind: "number", label: "uint8" })] }, + { variables: [x({ kind: "number", label: "int8" })] }, ], }), ), @@ -145,7 +145,7 @@ describe("extractVariablesFromInstruction", () => { extractVariablesFromInstruction( instr(0, { gather: [ - { variables: [{ identifier: "x", type: { kind: "uint" } }] }, + { variables: [{ identifier: "x", type: { kind: "number" } }] }, { variables: [{ identifier: "x", pointer: x.pointer }] }, ], }), @@ -154,7 +154,7 @@ describe("extractVariablesFromInstruction", () => { }); it("keeps entries from different frames apart", () => { - const typed = { ...declared("x", 1), type: { kind: "uint" } }; + const typed = { ...declared("x", 1), type: { kind: "number" } }; const located = declared("x", 1, memory(0)); expect( extractVariablesFromInstruction( @@ -169,7 +169,7 @@ describe("extractVariablesFromInstruction", () => { }); it("matches declarations whatever the order of their keys", () => { - const typed = { ...declared("x", 1), type: { kind: "uint" } }; + const typed = { ...declared("x", 1), type: { kind: "number" } }; const located = { identifier: "x", declaration: { range: { length: 1, offset: 1 }, source: { id: 0 } }, diff --git a/packages/web/src/theme/ProgramExample/TraceDrawer.tsx b/packages/web/src/theme/ProgramExample/TraceDrawer.tsx index affcd27777..613b2f2e63 100644 --- a/packages/web/src/theme/ProgramExample/TraceDrawer.tsx +++ b/packages/web/src/theme/ProgramExample/TraceDrawer.tsx @@ -1291,20 +1291,11 @@ function formatType(type: unknown): string { const t = type as Record; - if (t.kind === "uint" && typeof t.bits === "number") { - return `uint${t.bits}`; + if (typeof t.label === "string") { + return t.label; } - if (t.kind === "int" && typeof t.bits === "number") { - return `int${t.bits}`; - } - if (t.kind === "bool") { - return "bool"; - } - if (t.kind === "address") { - return "address"; - } - if (t.kind === "bytes" && typeof t.size === "number") { - return `bytes${t.size}`; + if (typeof t.kind === "string") { + return t.kind; } return JSON.stringify(type); From d95778e325df167aacec123d81ce60005b3686a8 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:27:15 -0500 Subject: [PATCH 09/19] conformance: keep an empty types table in the solc workaround --- packages/conformance/test/conformance.test.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/conformance/test/conformance.test.ts b/packages/conformance/test/conformance.test.ts index e7c5e89dbd..b539eab5e6 100644 --- a/packages/conformance/test/conformance.test.ts +++ b/packages/conformance/test/conformance.test.ts @@ -159,14 +159,17 @@ function withoutResourcesStamp( // Expected failure (#423): solc's `resources.types` still uses the type // kinds that #282 replaced, so its resources do not validate. Conformance -// checks solc resources without the table. The tripwire test below fails -// once solc's types validate; then remove this function and the tripwire. -function withoutResourcesTypes(artifact: EthdebugArtifact): EthdebugArtifact { +// checks solc resources with an empty table (the schema requires `types`). +// The tripwire test below fails once solc's types validate; then remove +// this function and the tripwire. +function withEmptyResourcesTypes(artifact: EthdebugArtifact): EthdebugArtifact { if (!artifact.resources) { return artifact; } - const { types: _, ...resources } = artifact.resources; - return { ...artifact, resources } as EthdebugArtifact; + return { + ...artifact, + resources: { ...artifact.resources, types: {} }, + }; } function validArtifact( @@ -215,7 +218,7 @@ describe("@ethdebug/conformance", () => { }); const result = await validateStaticConformance( - withoutResourcesTypes(artifact), + withEmptyResourcesTypes(artifact), ); expect(result.issues).toEqual([]); expect(result.ok).toBe(true); @@ -225,7 +228,7 @@ describe("@ethdebug/conformance", () => { }, ); - // Expected failure (#423): see withoutResourcesTypes. + // Expected failure (#423): see withEmptyResourcesTypes. it.skipIf(!solc)( "[solc] resources types do not yet validate (#423)", async () => { @@ -239,7 +242,7 @@ describe("@ethdebug/conformance", () => { expect( result.ok, - "solc's types now validate; remove withoutResourcesTypes (#423)", + "solc's types now validate; remove withEmptyResourcesTypes (#423)", ).toBe(false); for (const { message } of result.issues) { expect(message).toContain("schema:ethdebug/format/info/resources"); @@ -348,7 +351,7 @@ describe("@ethdebug/conformance", () => { ], }); const result = await validateStaticConformance( - withoutResourcesTypes(artifact), + withEmptyResourcesTypes(artifact), ); expect(result.issues).toEqual([]); expect(result.ok).toBe(true); From 3b8aad3aaef4a1b9731c2f478580680fc2f73854 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:37:29 -0500 Subject: [PATCH 10/19] web: document the new type kinds --- packages/web/docs/concepts/programs.mdx | 2 +- packages/web/docs/concepts/types.mdx | 35 ++++-- .../web/docs/core-schemas/info/resources.mdx | 4 +- .../core-schemas/programs/instructions.mdx | 4 +- .../docs/core-schemas/programs/tracing.mdx | 2 +- .../docs/core-schemas/programs/variables.mdx | 6 +- .../web/docs/core-schemas/types/composite.mdx | 58 +++++---- .../docs/core-schemas/types/elementary.mdx | 118 ++++++++---------- .../getting-started/for-compiler-authors.mdx | 10 +- .../getting-started/for-debugger-authors.mdx | 12 +- .../building-a-trace-viewer.mdx | 3 +- .../compiler/case-study-bug.mdx | 8 +- packages/web/spec/program/example.mdx | 52 ++++---- packages/web/spec/type/base.mdx | 27 ++-- packages/web/spec/type/complex/function.mdx | 7 -- .../type/complex/{tuple.mdx => variant.mdx} | 8 +- packages/web/spec/type/concepts.mdx | 11 +- .../web/spec/type/elementary/contract.mdx | 12 -- packages/web/spec/type/elementary/fixed.mdx | 10 -- .../type/elementary/{int.mdx => flags.mdx} | 8 +- packages/web/spec/type/elementary/number.mdx | 12 ++ packages/web/spec/type/elementary/ufixed.mdx | 12 -- packages/web/spec/type/elementary/uint.mdx | 10 -- packages/web/spec/type/overview.mdx | 6 +- packages/web/src/schemas.ts | 20 +-- 25 files changed, 193 insertions(+), 264 deletions(-) rename packages/web/spec/type/complex/{tuple.mdx => variant.mdx} (62%) delete mode 100644 packages/web/spec/type/elementary/contract.mdx delete mode 100644 packages/web/spec/type/elementary/fixed.mdx rename packages/web/spec/type/elementary/{int.mdx => flags.mdx} (61%) create mode 100644 packages/web/spec/type/elementary/number.mdx delete mode 100644 packages/web/spec/type/elementary/ufixed.mdx delete mode 100644 packages/web/spec/type/elementary/uint.mdx diff --git a/packages/web/docs/concepts/programs.mdx b/packages/web/docs/concepts/programs.mdx index 93c844c275..0995eb7096 100644 --- a/packages/web/docs/concepts/programs.mdx +++ b/packages/web/docs/concepts/programs.mdx @@ -97,7 +97,7 @@ What variables are in scope and where to find their values: "variables": [ { "identifier": "balance", - "type": { "kind": "uint", "bits": 256 }, + "type": { "kind": "number" }, "pointer": { "location": "storage", "slot": 0 } } ] diff --git a/packages/web/docs/concepts/types.mdx b/packages/web/docs/concepts/types.mdx index f7027ed23d..554fd02373 100644 --- a/packages/web/docs/concepts/types.mdx +++ b/packages/web/docs/concepts/types.mdx @@ -28,15 +28,22 @@ Together, they enable a debugger to find bytes (via the pointer) and interpret them correctly (via the type). The same type definition can be used regardless of where the data happens to be stored. +A type also does not give the size of its value. A `number` type has no +width, and an `array` type has no element count. The pointer gives the +value's bytes, and so their number. + ## All types have a `kind` field Every type representation is a JSON object with a `kind` field that identifies what kind of type it is: - + {`{ - "kind": "uint", - "bits": 256 + "kind": "number", + "label": "uint256" }`} @@ -54,9 +61,10 @@ for validation and how to interpret the rest of the object. **ethdebug/format** defines specific schemas for known type kinds. These correspond to reserved string values for `kind`: -- Elementary types: `uint`, `int`, `bool`, `address`, `bytes`, `string`, - `fixed`, `ufixed`, `enum`, `contract` -- Complex types: `array`, `struct`, `mapping`, `tuple`, `alias`, `function` +- Elementary types: `number`, `bool`, `address`, `bytes`, `string`, `enum`, + `flags` +- Complex types: `array`, `struct`, `mapping`, `alias`, `function`, + `variant` Type representations **should** use the specific schema when representing a known type. They **must not** reuse reserved `kind` values for other purposes. @@ -92,12 +100,14 @@ Types fall into one of two classes: - A mapping from one type to another This distinction is expressed through the presence or absence of a `contains` -field. Complex types always have `contains`; elementary types never do. +field. Elementary types never have `contains`. Complex types of unknown kinds +always have `contains`. Some known complex kinds use their own fields instead: +`function` lists `parameters` and `returns`, and `variant` lists `cases`. ## The `contains` field for complex types -Complex types use `contains` to specify what types they compose. This field is -polymorphic — it takes one of three forms depending on the type kind: +Most complex types use `contains` to specify what types they compose. This +field is polymorphic — it takes one of three forms depending on the type kind: ### Single type (e.g., arrays) @@ -108,8 +118,7 @@ Arrays compose exactly one element type: "kind": "array", "contains": { "type": { - "kind": "uint", - "bits": 256 + "kind": "number" } } }`} @@ -125,7 +134,7 @@ Structs compose an ordered list of named members: "contains": [ { "name": "balance", - "type": { "kind": "uint", "bits": 256 } + "type": { "kind": "number" } }, { "name": "owner", @@ -147,7 +156,7 @@ Mappings compose a key type and a value type: "kind": "mapping", "contains": { "key": { "type": { "kind": "address" } }, - "value": { "type": { "kind": "uint", "bits": 256 } } + "value": { "type": { "kind": "number" } } } }`} diff --git a/packages/web/docs/core-schemas/info/resources.mdx b/packages/web/docs/core-schemas/info/resources.mdx index 2e71c1f5f2..536d1d794b 100644 --- a/packages/web/docs/core-schemas/info/resources.mdx +++ b/packages/web/docs/core-schemas/info/resources.mdx @@ -138,8 +138,8 @@ keyed by name: "struct__Coordinate": { "kind": "struct", "contains": [ - { "name": "x", "type": { "kind": "uint", "bits": 128 } }, - { "name": "y", "type": { "kind": "uint", "bits": 128 } } + { "name": "x", "type": { "kind": "number" } }, + { "name": "y", "type": { "kind": "number" } } ], "definition": { "name": "Coordinate", diff --git a/packages/web/docs/core-schemas/programs/instructions.mdx b/packages/web/docs/core-schemas/programs/instructions.mdx index 671424817b..bef129342c 100644 --- a/packages/web/docs/core-schemas/programs/instructions.mdx +++ b/packages/web/docs/core-schemas/programs/instructions.mdx @@ -105,7 +105,7 @@ Declares variables that are in scope: "variables": [ { "identifier": "amount", - "type": { "kind": "uint", "bits": 256 }, + "type": { "kind": "number" }, "pointer": { "location": "stack", "slot": 0 @@ -170,7 +170,7 @@ Combine multiple contexts (like nested scopes): "variables": [ { "identifier": "x", - "type": { "kind": "uint", "bits": 256 }, + "type": { "kind": "number" }, "pointer": { "location": "stack", "slot": 0 } } ] diff --git a/packages/web/docs/core-schemas/programs/tracing.mdx b/packages/web/docs/core-schemas/programs/tracing.mdx index 67e2e234a7..3d109a0ca6 100644 --- a/packages/web/docs/core-schemas/programs/tracing.mdx +++ b/packages/web/docs/core-schemas/programs/tracing.mdx @@ -256,7 +256,7 @@ The program's instruction list maps each PC to its context: "variables": [ { "identifier": "count", - "type": { "kind": "uint", "bits": 256 }, + "type": { "kind": "number" }, "pointer": { "location": "storage", "slot": 0 } } ] diff --git a/packages/web/docs/core-schemas/programs/variables.mdx b/packages/web/docs/core-schemas/programs/variables.mdx index dc77388e3f..867838e184 100644 --- a/packages/web/docs/core-schemas/programs/variables.mdx +++ b/packages/web/docs/core-schemas/programs/variables.mdx @@ -37,7 +37,7 @@ A variable has up to four optional fields (at least one required): > {`{ "identifier": "balance", - "type": { "kind": "uint", "bits": 256 }, + "type": { "kind": "number" }, "pointer": { "location": "storage", "slot": 0 @@ -72,7 +72,7 @@ structures: "type": { "kind": "struct", "contains": [ - { "name": "id", "type": { "kind": "uint", "bits": 256 } }, + { "name": "id", "type": { "kind": "number" } }, { "name": "active", "type": { "kind": "bool" } } ] }, @@ -168,7 +168,7 @@ An instruction's context can declare multiple variables: }, { "identifier": "value", - "type": { "kind": "uint", "bits": 256 }, + "type": { "kind": "number" }, "pointer": { "location": "stack", "slot": 1 } }, { diff --git a/packages/web/docs/core-schemas/types/composite.mdx b/packages/web/docs/core-schemas/types/composite.mdx index c246dba4b4..1c9f25133e 100644 --- a/packages/web/docs/core-schemas/types/composite.mdx +++ b/packages/web/docs/core-schemas/types/composite.mdx @@ -12,8 +12,8 @@ import SchemaExample from "@site/src/components/SchemaExample"; href="/spec/category/complex-types" /> -Complex types contain other types. They use the `contains` field to -express this composition. +Complex types contain other types. Most complex types use the `contains` +field to express this composition. ## Arrays @@ -25,7 +25,7 @@ Arrays represent ordered collections of a single element type. {`{ "kind": "array", "contains": { - "type": { "kind": "uint", "bits": 256 } + "type": { "kind": "number" } } }`} @@ -37,14 +37,16 @@ This represents `uint256[]`—an array of any length. {`{ "kind": "array", - "count": 10, + "label": "address[10]", "contains": { "type": { "kind": "address" } } }`} -This represents `address[10]`—exactly 10 addresses. +This represents `address[10]`—exactly 10 addresses. An array type has no +element count. The type says what the elements are; the value's pointer +says where they are, and so how many there are. ## Structs @@ -59,7 +61,7 @@ Structs group named members of potentially different types: "contains": [ { "name": "balance", - "type": { "kind": "uint", "bits": 256 } + "type": { "kind": "number" } }, { "name": "owner", @@ -75,7 +77,7 @@ Structs group named members of potentially different types: The `contains` field is an ordered list. Each element includes: -- `name`: The member's identifier +- `name`: The member's identifier (optional) - `type`: The member's type (inline or by reference) ## Mappings @@ -90,7 +92,7 @@ Mappings represent key-value associations: "type": { "kind": "address" } }, "value": { - "type": { "kind": "uint", "bits": 256 } + "type": { "kind": "number" } } } }`} @@ -118,7 +120,7 @@ Mappings can nest by using another mapping as the value type: "kind": "mapping", "contains": { "key": { "type": { "kind": "address" } }, - "value": { "type": { "kind": "uint", "bits": 256 } } + "value": { "type": { "kind": "number" } } } } } @@ -131,21 +133,21 @@ used for ERC-20 allowances. ## Tuples -Tuples represent ordered, unnamed sequences: +Tuples represent ordered, unnamed sequences. A tuple is a struct whose +members have no names: - + {`{ - "kind": "tuple", + "kind": "struct", "contains": [ - { "type": { "kind": "uint", "bits": 256 } }, + { "type": { "kind": "number" } }, { "type": { "kind": "address" } }, { "type": { "kind": "bool" } } ] }`} -Unlike structs, tuple elements don't have names. Tuples commonly appear in -function return types and event parameters. +Tuples commonly appear in function return types and event parameters. ## Type aliases @@ -158,7 +160,7 @@ Aliases give names to other types: "name": "TokenId" }, "contains": { - "type": { "kind": "uint", "bits": 256 } + "type": { "kind": "number" } } }`} @@ -176,23 +178,19 @@ Function types represent callable references: {`{ "kind": "function", "internal": true, - "contains": { - "parameters": { - "type": { - "kind": "tuple", - "contains": [ - { "type": { "kind": "address" } }, - { "type": { "kind": "uint", "bits": 256 } } - ] - } - }, - "returns": { - "type": { "kind": "bool" } - } - } + "parameters": [ + { "type": { "kind": "address" } }, + { "type": { "kind": "number" } } + ], + "returns": [ + { "type": { "kind": "bool" } } + ] }`} +The `parameters` and `returns` fields are ordered lists of types. An empty +`returns` list means that the function returns no values. + Function types must specify either `"internal": true` or `"external": true`. Internal functions are called within the language's own semantics; external functions are called via EVM diff --git a/packages/web/docs/core-schemas/types/elementary.mdx b/packages/web/docs/core-schemas/types/elementary.mdx index f545a1a2ed..e04733c4fc 100644 --- a/packages/web/docs/core-schemas/types/elementary.mdx +++ b/packages/web/docs/core-schemas/types/elementary.mdx @@ -17,51 +17,57 @@ building blocks that complex types compose. ## Numeric types -### Unsigned integers (`uint`) +Unsigned integers, signed integers, and fixed-point numbers all use the +`number` kind. A `number` type has no width. The type says what the value +is; the value's pointer says where its bytes are, and so how many bytes +there are. -Unsigned integers range from 8 to 256 bits, in increments of 8: - - - {`{ "kind": "uint", "bits": 256 }`} + + {`{ "kind": "number" }`} - - {`{ "kind": "uint", "bits": 8 }`} - +The optional `label` field gives the type as the language spells it: -The `bits` field is required and must be a multiple of 8 between 8 and 256. + + {`{ "kind": "number", "label": "uint8" }`} + -### Signed integers (`int`) +### Signed integers Signed integers use two's complement representation: - - {`{ "kind": "int", "bits": 256 }`} + + {`{ "kind": "number", "signed": true }`} -Like `uint`, the `bits` field must be a multiple of 8 between 8 and 256. +When `signed` is omitted, the number is unsigned. -### Fixed-point numbers (`ufixed`, `fixed`) +### Fixed-point numbers -Fixed-point decimals specify both total bits and decimal places: +Fixed-point decimals specify the number of decimal places: - {`{ "kind": "ufixed", "bits": 128, "places": 18 }`} + {`{ "kind": "number", "signed": true, "places": 18 }`} - - {`{ "kind": "fixed", "bits": 128, "places": 18 }`} - +The number is the integer value of its bytes divided by `10**places`. When +`places` is omitted, the number is an integer. ## Address type -Addresses represent 20-byte Ethereum addresses: +Addresses represent Ethereum addresses: -In the EVM, booleans occupy a full 32-byte word where 0 is false and any -non-zero value is true. +The value 0 is false and the value 1 is true. Any other value is invalid. ## Byte types -### Fixed-size bytes (`bytes`) - -Fixed-size byte arrays range from 1 to 32 bytes: +Byte strings use the `bytes` kind: - {`{ "kind": "bytes", "size": 32 }`} - - - - {`{ "kind": "bytes", "size": 4 }`} + {`{ "kind": "bytes" }`} -The `size` field is required for fixed-size bytes. - -### Dynamic bytes (`bytes`) - -Dynamic byte arrays have no size limit: +A `bytes` type has no size. Fixed-size and dynamic byte strings both use +this kind; the value's pointer says how many bytes there are. The `label` +field can keep the language's spelling: - {`{ "kind": "bytes" }`} + {`{ "kind": "bytes", "label": "bytes32" }`} -When `size` is omitted, the type represents dynamically-sized bytes. - ## String type Strings represent UTF-8 encoded text: @@ -139,8 +131,8 @@ Strings represent UTF-8 encoded text: {`{ "kind": "string" }`} -Strings are dynamically sized. Languages that treat strings as character -arrays may choose to represent them as `array` types instead. +Languages that treat strings as character arrays may choose to represent them +as `array` types instead. ## Enum type @@ -156,38 +148,30 @@ Enums represent a fixed set of named values: }`} -The `values` field lists all possible values in order. The underlying -representation is typically a `uint8` (or larger if needed). +The `values` field lists all possible values in order. The value is read +as an unsigned integer `i`, which selects `values[i]`. ## Contract type -Contract types represent references to contract instances: +Contract types are `address` types with a `definition` field. The +definition names the contract: - {`{ "kind": "contract" }`} - - -Contract types may include a `definition` field when the contract is defined -in source code: - - {`{ - "kind": "contract", + "kind": "address", "definition": { "name": "MyToken" } }`} -In the EVM, contract references are addresses (20 bytes), but the contract -type carries additional semantic information about which contract interface -applies. +The value is an address, but the type carries additional semantic +information about which contract interface applies. A definition may mark +the contract as a library or an interface with the `library` or +`interface` field. ## User-defined types with definitions diff --git a/packages/web/docs/getting-started/for-compiler-authors.mdx b/packages/web/docs/getting-started/for-compiler-authors.mdx index e82e5fd9de..9ae5b1fd73 100644 --- a/packages/web/docs/getting-started/for-compiler-authors.mdx +++ b/packages/web/docs/getting-started/for-compiler-authors.mdx @@ -28,13 +28,13 @@ experiences for your users. Here's how to describe a simple `uint256`: {`{ - "kind": "uint", - "bits": 256 + "kind": "number", + "label": "uint256" }`} @@ -49,7 +49,7 @@ A storage mapping from addresses to balances: "kind": "mapping", "contains": { "key": { "type": { "kind": "address" } }, - "value": { "type": { "kind": "uint", "bits": 256 } } + "value": { "type": { "kind": "number" } } } }`} diff --git a/packages/web/docs/getting-started/for-debugger-authors.mdx b/packages/web/docs/getting-started/for-debugger-authors.mdx index 59646ff5cd..353007b076 100644 --- a/packages/web/docs/getting-started/for-debugger-authors.mdx +++ b/packages/web/docs/getting-started/for-debugger-authors.mdx @@ -28,13 +28,13 @@ Type information describes the structure of data. Here's what a simple `uint256` type looks like in **ethdebug/format**: {`{ - "kind": "uint", - "bits": 256 + "kind": "number", + "label": "uint256" }`} @@ -51,8 +51,8 @@ And a more complex struct: "name": "Position" }, "contains": [ - { "name": "x", "type": { "kind": "int", "bits": 256 } }, - { "name": "y", "type": { "kind": "int", "bits": 256 } } + { "name": "x", "type": { "kind": "number", "signed": true } }, + { "name": "y", "type": { "kind": "number", "signed": true } } ] }`} diff --git a/packages/web/docs/implementation-guides/building-a-trace-viewer.mdx b/packages/web/docs/implementation-guides/building-a-trace-viewer.mdx index 4a3a944d34..74271c0166 100644 --- a/packages/web/docs/implementation-guides/building-a-trace-viewer.mdx +++ b/packages/web/docs/implementation-guides/building-a-trace-viewer.mdx @@ -56,7 +56,8 @@ import { Raw } from "@ethdebug/common"; function decodeValue(bytes: Raw, type: Type): string { switch (type.kind) { - case "uint": + case "number": + // unsigned integer; `signed` and `places` need more decoding return Raw.asUint(bytes).toString(); case "bool": return Raw.asUint(bytes) !== 0n ? "true" : "false"; diff --git a/packages/web/docs/implementation-guides/compiler/case-study-bug.mdx b/packages/web/docs/implementation-guides/compiler/case-study-bug.mdx index c848d96928..1d9533e4d7 100644 --- a/packages/web/docs/implementation-guides/compiler/case-study-bug.mdx +++ b/packages/web/docs/implementation-guides/compiler/case-study-bug.mdx @@ -303,7 +303,6 @@ export function convertBugType(bugType: BugType): Format.Type | undefined { return { kind: "array", contains: { type: elementType }, - ...(bugType.size !== undefined && { count: bugType.size }), }; } @@ -313,8 +312,9 @@ export function convertBugType(bugType: BugType): Format.Type | undefined { The type conversion handles: -- **Elementary types** — Direct mapping (`uint256` → `{kind: "uint", bits: 256}`) -- **Arrays** — Recursive conversion with optional count +- **Elementary types** — Direct mapping + (`uint256` → `{kind: "number", label: "uint256"}`) +- **Arrays** — Recursive conversion of the element type - **Mappings** — Key/value type conversion - **Structs** — Field-by-field conversion with names @@ -456,7 +456,7 @@ Each bytecode instruction includes context with: "variables": [ { "identifier": "count", - "type": { "kind": "uint", "bits": 256 }, + "type": { "kind": "number" }, "pointer": { "location": "storage", "slot": 0 } } ] diff --git a/packages/web/spec/program/example.mdx b/packages/web/spec/program/example.mdx index b3c17892f4..54a4363a5f 100644 --- a/packages/web/spec/program/example.mdx +++ b/packages/web/spec/program/example.mdx @@ -42,8 +42,8 @@ code { variables: [{ identifier: "storedValue", type: { - kind: "uint", - bits: 256 + kind: "number", + label: "uint256" }, pointer: { location: "storage", @@ -63,8 +63,8 @@ code { variables: [{ identifier: "storedValue", type: { - kind: "uint", - bits: 256 + kind: "number", + label: "uint256" }, pointer: { location: "storage", @@ -83,8 +83,8 @@ code { variables: [{ identifier: "storedValue", type: { - kind: "uint", - bits: 256 + kind: "number", + label: "uint256" }, pointer: { location: "storage", @@ -104,8 +104,8 @@ code { variables: [{ identifier: "storedValue", type: { - kind: "uint", - bits: 256 + kind: "number", + label: "uint256" }, pointer: { location: "storage", @@ -125,8 +125,8 @@ code { variables: [{ identifier: "storedValue", type: { - kind: "uint", - bits: 256 + kind: "number", + label: "uint256" }, pointer: { location: "storage", @@ -146,8 +146,8 @@ code { variables: [{ identifier: "storedValue", type: { - kind: "uint", - bits: 256 + kind: "number", + label: "uint256" }, pointer: { location: "storage", @@ -167,8 +167,8 @@ code { variables: [{ identifier: "storedValue", type: { - kind: "uint", - bits: 256 + kind: "number", + label: "uint256" }, pointer: { location: "storage", @@ -188,8 +188,8 @@ code { variables: [{ identifier: "storedValue", type: { - kind: "uint", - bits: 256 + kind: "number", + label: "uint256" }, pointer: { location: "storage", @@ -208,8 +208,8 @@ code { variables: [{ identifier: "storedValue", type: { - kind: "uint", - bits: 256 + kind: "number", + label: "uint256" }, pointer: { location: "storage", @@ -219,8 +219,8 @@ code { }, { identifier: "localValue", type: { - kind: "uint", - bits: 256 + kind: "number", + label: "uint256" }, pointer: { location: "stack", @@ -239,8 +239,8 @@ code { variables: [{ identifier: "storedValue", type: { - kind: "uint", - bits: 256 + kind: "number", + label: "uint256" }, pointer: { location: "storage", @@ -250,8 +250,8 @@ code { }, { identifier: "localValue", type: { - kind: "uint", - bits: 256 + kind: "number", + label: "uint256" }, pointer: { location: "stack", @@ -270,8 +270,8 @@ code { variables: [{ identifier: "storedValue", type: { - kind: "uint", - bits: 256 + kind: "number", + label: "uint256" }, pointer: { location: "storage", diff --git a/packages/web/spec/type/base.mdx b/packages/web/spec/type/base.mdx index 0283a83762..ea5de6d112 100644 --- a/packages/web/spec/type/base.mdx +++ b/packages/web/spec/type/base.mdx @@ -101,20 +101,20 @@ schema. ## Example schema extensions for particular types -These examples show valid schemas that extend **ethdebug/format/types/base** +These examples show valid schemas that extend **ethdebug/format/type/base** for particular kinds of types. _**Note**: These are just examples and may not correspond to the canonical **ethdebug/format/type** schema._ - + @@ -186,7 +182,7 @@ correspond to the canonical **ethdebug/format/type** schema._ const: complex kind: type: string - const: array + const: mapping contains: type: object properties: @@ -219,8 +215,7 @@ correspond to the canonical **ethdebug/format/type** schema._ payable: true value: type: - kind: uint - bits: 256 + kind: number description: An example schema for mapping types. See example value for a mapping from an \`address payable\` to a \`uint256\`, adhering to this diff --git a/packages/web/spec/type/complex/function.mdx b/packages/web/spec/type/complex/function.mdx index 4451f6842b..97eb33c7b7 100644 --- a/packages/web/spec/type/complex/function.mdx +++ b/packages/web/spec/type/complex/function.mdx @@ -8,10 +8,3 @@ import SchemaViewer from "@site/src/components/SchemaViewer"; # `function` - -## Parameters schema - - diff --git a/packages/web/spec/type/complex/tuple.mdx b/packages/web/spec/type/complex/variant.mdx similarity index 62% rename from packages/web/spec/type/complex/tuple.mdx rename to packages/web/spec/type/complex/variant.mdx index 11c3fdba21..838d710aaa 100644 --- a/packages/web/spec/type/complex/tuple.mdx +++ b/packages/web/spec/type/complex/variant.mdx @@ -1,10 +1,10 @@ --- -sidebar_position: 2 -description: Tuple types schema +sidebar_position: 7 +description: Variant types schema --- import SchemaViewer from "@site/src/components/SchemaViewer"; -# `tuple` +# `variant` - + diff --git a/packages/web/spec/type/concepts.mdx b/packages/web/spec/type/concepts.mdx index 0d3c4105d9..75c33e7ffd 100644 --- a/packages/web/spec/type/concepts.mdx +++ b/packages/web/spec/type/concepts.mdx @@ -98,15 +98,14 @@ possibly includes other fields alongside `"type"`. "kind": "array", "contains": { "type": { - "kind": "uint", - "bits": 256 + "kind": "number" } } } ``` - This is an example array type, which composes an ordered list of member + This is an example struct type, which composes an ordered list of member types. ```json @@ -115,8 +114,7 @@ possibly includes other fields alongside `"type"`. "contains": [{ "name": "balance", "type": { - "kind": "uint", - "bits": 256 + "kind": "number" } }, { "name": "scoreSheet", @@ -146,8 +144,7 @@ possibly includes other fields alongside `"type"`. }, "value": { "type": { - "kind": "uint", - "bits": 256 + "kind": "number" } } } diff --git a/packages/web/spec/type/elementary/contract.mdx b/packages/web/spec/type/elementary/contract.mdx deleted file mode 100644 index 7a8d0bafca..0000000000 --- a/packages/web/spec/type/elementary/contract.mdx +++ /dev/null @@ -1,12 +0,0 @@ ---- -sidebar_position: 9 -description: Contract types schema ---- - -import SchemaViewer from "@site/src/components/SchemaViewer"; - -# `contract` - - diff --git a/packages/web/spec/type/elementary/fixed.mdx b/packages/web/spec/type/elementary/fixed.mdx deleted file mode 100644 index df82cfcc9e..0000000000 --- a/packages/web/spec/type/elementary/fixed.mdx +++ /dev/null @@ -1,10 +0,0 @@ ---- -sidebar_position: 4 -description: Signed decimal fixed point types schema ---- - -import SchemaViewer from "@site/src/components/SchemaViewer"; - -# `fixed` - - diff --git a/packages/web/spec/type/elementary/int.mdx b/packages/web/spec/type/elementary/flags.mdx similarity index 61% rename from packages/web/spec/type/elementary/int.mdx rename to packages/web/spec/type/elementary/flags.mdx index a70712cc97..5ea7c8bc35 100644 --- a/packages/web/spec/type/elementary/int.mdx +++ b/packages/web/spec/type/elementary/flags.mdx @@ -1,10 +1,10 @@ --- -sidebar_position: 2 -description: Signed integer types schema +sidebar_position: 11 +description: Flags types schema --- import SchemaViewer from "@site/src/components/SchemaViewer"; -# `int` +# `flags` - + diff --git a/packages/web/spec/type/elementary/number.mdx b/packages/web/spec/type/elementary/number.mdx new file mode 100644 index 0000000000..8d8cb0d4e3 --- /dev/null +++ b/packages/web/spec/type/elementary/number.mdx @@ -0,0 +1,12 @@ +--- +sidebar_position: 1 +description: Number types schema +--- + +import SchemaViewer from "@site/src/components/SchemaViewer"; + +# `number` + + diff --git a/packages/web/spec/type/elementary/ufixed.mdx b/packages/web/spec/type/elementary/ufixed.mdx deleted file mode 100644 index 3a033f5282..0000000000 --- a/packages/web/spec/type/elementary/ufixed.mdx +++ /dev/null @@ -1,12 +0,0 @@ ---- -sidebar_position: 3 -description: Unsigned decimal fixed point types schema ---- - -import SchemaViewer from "@site/src/components/SchemaViewer"; - -# `ufixed` - - diff --git a/packages/web/spec/type/elementary/uint.mdx b/packages/web/spec/type/elementary/uint.mdx deleted file mode 100644 index b324b7d60b..0000000000 --- a/packages/web/spec/type/elementary/uint.mdx +++ /dev/null @@ -1,10 +0,0 @@ ---- -sidebar_position: 1 -description: Unsigned integer types schema ---- - -import SchemaViewer from "@site/src/components/SchemaViewer"; - -# `uint` - - diff --git a/packages/web/spec/type/overview.mdx b/packages/web/spec/type/overview.mdx index e285903dc9..2a12d45aa9 100644 --- a/packages/web/spec/type/overview.mdx +++ b/packages/web/spec/type/overview.mdx @@ -26,8 +26,8 @@ JSON values: ```json { - "kind": "uint", - "bits": 256 + "kind": "number", + "label": "uint256" } ``` @@ -55,7 +55,7 @@ This format defines schemas for representing the data types allowable in a supporting high-level language. JSON values that adhere to this schema may (for example) represent a particular -`uint` type (like `uint256`), a `struct` type with a particular set of member +`number` type (like `uint256`), a `struct` type with a particular set of member fields, a particular `mapping` type from a certain key type to a certain value type, and so on. diff --git a/packages/web/src/schemas.ts b/packages/web/src/schemas.ts index 02cf5873e1..8e25b82389 100644 --- a/packages/web/src/schemas.ts +++ b/packages/web/src/schemas.ts @@ -39,36 +39,20 @@ const typeSchemaIndex: SchemaIndex = { "schema:ethdebug/format/type/complex": { href: "/spec/type#complex-type-schema", }, - ...[ - "uint", - "int", - "ufixed", - "fixed", - "bool", - "bytes", - "string", - "address", - "contract", - "enum", - ] + ...["number", "bool", "bytes", "string", "address", "enum", "flags"] .map((kind) => ({ [`schema:ethdebug/format/type/elementary/${kind}`]: { href: `/spec/type/elementary/${kind}`, }, })) .reduce((a, b) => ({ ...a, ...b }), {}), - ...["alias", "tuple", "array", "mapping", "struct", "function"] + ...["alias", "array", "mapping", "struct", "function", "variant"] .map((kind) => ({ [`schema:ethdebug/format/type/complex/${kind}`]: { href: `/spec/type/complex/${kind}`, }, })) .reduce((a, b) => ({ ...a, ...b }), {}), - - "schema:ethdebug/format/type/complex/function#/$defs/Parameters": { - title: "Parameters schema", - href: "/spec/type/complex/function#parameters-schema", - }, }; const pointerSchemaIndex: SchemaIndex = { From 0dea127bda7be943a9768fa8b961a4ad1077e9fc Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:39:22 -0500 Subject: [PATCH 11/19] web: list flags and variant in the type overviews --- packages/web/docs/concepts/types.mdx | 2 +- .../web/docs/core-schemas/types/composite.mdx | 23 +++++++++++++++++++ .../docs/core-schemas/types/elementary.mdx | 20 ++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/packages/web/docs/concepts/types.mdx b/packages/web/docs/concepts/types.mdx index 554fd02373..e9273ceb9a 100644 --- a/packages/web/docs/concepts/types.mdx +++ b/packages/web/docs/concepts/types.mdx @@ -90,7 +90,7 @@ Types fall into one of two classes: **Elementary types** don't contain other types. They represent atomic values: - `uint256` — an unsigned integer -- `address` — a 20-byte account identifier +- `address` — an account identifier - `bool` — true or false **Complex types** compose one or more other types: diff --git a/packages/web/docs/core-schemas/types/composite.mdx b/packages/web/docs/core-schemas/types/composite.mdx index 1c9f25133e..4e960bb3ea 100644 --- a/packages/web/docs/core-schemas/types/composite.mdx +++ b/packages/web/docs/core-schemas/types/composite.mdx @@ -196,6 +196,29 @@ Function types must specify either `"internal": true` or language's own semantics; external functions are called via EVM contract call semantics (e.g., the Solidity ABI). +## Variant types + +Variants represent a value that is exactly one of a list of cases: + + + {`{ + "kind": "variant", + "label": "Option", + "cases": [ + { "name": "None", "discriminant": 0 }, + { + "name": "Some", + "discriminant": 1, + "payload": { "type": { "kind": "number" } } + } + ] +}`} + + +Each case has a `name`, a `discriminant`, and an optional `payload` type. The +active case is the case whose `discriminant` matches the value read for the +discriminant. + ## Using type references For deeply nested or repeated types, use references to avoid duplication: diff --git a/packages/web/docs/core-schemas/types/elementary.mdx b/packages/web/docs/core-schemas/types/elementary.mdx index e04733c4fc..62ed3dc8e2 100644 --- a/packages/web/docs/core-schemas/types/elementary.mdx +++ b/packages/web/docs/core-schemas/types/elementary.mdx @@ -151,6 +151,26 @@ Enums represent a fixed set of named values: The `values` field lists all possible values in order. The value is read as an unsigned integer `i`, which selects `values[i]`. +## Flags type + +Flags represent a set of named flags: + + + {`{ + "kind": "flags", + "definition": { + "name": "Permissions" + }, + "values": ["READ", "WRITE", "EXECUTE"] +}`} + + +The value is read as an unsigned integer. If bit `i` is set, `values[i]` is +in the set. The value 0 is the empty set. + ## Contract type Contract types are `address` types with a `definition` field. The From d03778ab39a9892f4d2ad95549f7b429a37fd599 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:42:42 -0500 Subject: [PATCH 12/19] docs: changelog entries for the type rewrite --- CHANGELOG.md | 150 +++++++++++++++++++++++++++++++++++ packages/bugc/CHANGELOG.md | 17 ++++ packages/format/CHANGELOG.md | 19 +++++ 3 files changed, 186 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a129594b1..171f0fc8fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,155 @@ The sections do not signal obligations; the prefixes do. ## Unreleased +### Changed + +- Every type kind is replaced. A type now says what a value is, and no longer + says where its bytes are or how many there are. The layout keywords `bits`, + `size` and `count` are gone, and the integer, fixed-point, address and + tuple kinds merge into fewer kinds. Each kind's description now states its + standard interpretation: how a consumer reads a value from the bytes the + value occupies. Every type may have an optional `label`, the type as its + language spells it (e.g., `uint256`, `bytes32`, `uint8[3]`), for display + only. Nothing interprets a label ([#282]). + - Schemas: **ethdebug/format/type**, **ethdebug/format/type/base**, + **ethdebug/format/type/elementary**, **ethdebug/format/type/complex**, + **ethdebug/format/type/specifier** + - Producers: required: the kinds below replace the old kinds, and the old + kinds no longer validate. See the entries for each kind. + - Consumers: required: producers emit the new kinds. A consumer must read + them and must not expect the old kinds. See the entries for each kind. + +- The **ethdebug/format/type/elementary/number** type replaces the `uint`, + `int`, `ufixed` and `fixed` kinds. It has an optional `signed` (default + false) and an optional `places` (default 0, minimum 0), and has no width. + The value is the big-endian integer over the value's bytes, in two's + complement if `signed`, divided by 10 to the power of `places`. For + example, `{ "kind": "uint", "bits": 256 }` becomes + `{ "kind": "number", "label": "uint256" }`, and `{ "kind": "int", +"bits": 8 }` becomes `{ "kind": "number", "signed": true, "label": "int8" }` + ([#282]). + - Schemas: **ethdebug/format/type/elementary/number**, + **ethdebug/format/type/elementary/uint**, + **ethdebug/format/type/elementary/int**, + **ethdebug/format/type/elementary/ufixed**, + **ethdebug/format/type/elementary/fixed** + - Producers: required: the schemas for kinds `uint`, `int`, `ufixed` and + `fixed` are removed, so a type with one of those kinds no longer + validates. Use kind `number`. The `bits` keyword is not allowed. + - Consumers: required: a type with kind `number` is an integer or fixed-point + number as described. The width comes from the pointer, not the type. + +- The **ethdebug/format/type/elementary/address** type now also covers + contract references, and the `contract` kind is removed. An address has an + optional `payable` (absent means unknown) and an optional `definition`. A + type without `definition` is a plain address. A type with `definition` is a + reference to a contract, and the `definition` may also have `library` or + `interface` (not both true) ([#282]). + - Schemas: **ethdebug/format/type/elementary/address**, + **ethdebug/format/type/elementary/contract** + - Producers: required: the schema for kind `contract` is removed. Use kind + `address` with a `definition`. + - Consumers: required: a type with kind `address` and a `definition` + refers to a contract. It is read as an address. + +- The **ethdebug/format/type/elementary/bytes** type no longer has `size`. + Its value is the bytes of the value, in order ([#282]). + - Schemas: **ethdebug/format/type/elementary/bytes** + - Producers: required: the `size` keyword is removed, so a type with it no + longer validates. A fixed-size `bytes` type is `{ "kind": "bytes" }`, and + the pointer gives the size. + - Consumers: required: a type with kind `bytes` has no `size`. Take the + length from the bytes the value occupies. + +- The **ethdebug/format/type/elementary/enum** type now has `values` as a + non-empty list of unique strings. The value is the unsigned big-endian + integer `i` over the value's bytes, and the member is `values[i]`. An `i` + past the end of `values` is invalid ([#282]). + - Schemas: **ethdebug/format/type/elementary/enum** + - Producers: required: `values` must be a non-empty list of unique + strings. Data with any other `values` no longer validates. + - Consumers: required: read an enum value as the index into `values` + described above. + +- The **ethdebug/format/type/elementary/flags** type is new. It is a set of + named members, with `values` (a list of unique strings) and an optional + `definition`. A set bit `i` in the value's bytes means `values[i]` is + present. Zero is the empty set. A set bit at or past the length of `values` + is invalid ([#282]). + - Schemas: **ethdebug/format/type/elementary/flags** + - Producers: optional: a type may have kind `flags`. + - Consumers: required: a type may have kind `flags`. A consumer must read it + as described to read the data at all. + +- The **ethdebug/format/type/elementary/bool** and + **ethdebug/format/type/elementary/string** types are unchanged except for + the `label` and the standard interpretation in their descriptions. A bool + is 0 (false) or 1 (true), and any other value is invalid. A string is text + in its `encoding` (default utf-8), and an invalid sequence is invalid + ([#282]). + - Schemas: **ethdebug/format/type/elementary/bool**, + **ethdebug/format/type/elementary/string** + - Producers: no change needed. + - Consumers: no change needed. + +- The **ethdebug/format/type/complex/struct** type replaces the `tuple` + kind. A struct has an ordered `contains` list whose items may each have a + `name`. An unnamed list is a tuple, and the list may be empty. The + `definition` is optional ([#282]). + - Schemas: **ethdebug/format/type/complex/struct**, + **ethdebug/format/type/complex/tuple** + - Producers: required: the schema for kind `tuple` is removed. Use kind + `struct` with unnamed items. + - Consumers: required: a type with kind `struct` may have unnamed items, + and may have none. + +- The **ethdebug/format/type/complex/array** type no longer has `count`. Its + items are all of the `contains` type. The pointer gives how many there are + ([#282]). + - Schemas: **ethdebug/format/type/complex/array** + - Producers: required: the `count` keyword is removed, so an array with it no + longer validates. + - Consumers: required: an array type has no length. Take the item count + from the pointer. + +- The **ethdebug/format/type/complex/variant** type is new. It has `cases`, + a list of `name`, `discriminant` (an **ethdebug/format/data/value**) and + optional `payload` (a type wrapper), and an optional `definition`. The type + says what each case is. The active case is the one whose `discriminant` + matches the value read as the discriminant. No match is invalid ([#282]). + - Schemas: **ethdebug/format/type/complex/variant** + - Producers: optional: a type may have kind `variant`. + - Consumers: required: a type may have kind `variant`. A consumer must read + it as described to read the data at all. + +- The **ethdebug/format/type/complex/function** type has a new shape. + `parameters` and `returns` are top-level lists (`returns` is required, and + `[]` means no values). They replace `contains.parameters` and + `contains.returns`. An external function may have a top-level `contract` + wrapper, whose type is an **ethdebug/format/type/elementary/address** + with a `definition` or a type reference. It replaces `contains.contract`. + Exactly one of `internal` and `external` is true, as before ([#282]). + - Schemas: **ethdebug/format/type/complex/function** + - Producers: required: `contains` is not allowed in a function type, and + `returns` is required. Data in the old shape no longer validates. + - Consumers: required: read `parameters`, `returns` and `contract` at the + top level of the function type. + +- The **ethdebug/format/type/complex/alias** and + **ethdebug/format/type/complex/mapping** types keep their structure and + gain the `label` and the standard interpretation in their descriptions + ([#282]). + - Schemas: **ethdebug/format/type/complex/alias**, + **ethdebug/format/type/complex/mapping** + - Producers: no change needed. + - Consumers: no change needed. + +- The examples that embed types now use the new kinds ([#282]). + - Schemas: **ethdebug/format/info**, **ethdebug/format/info/resources**, + **ethdebug/format/program** + - Producers: no change needed. + - Consumers: no change needed. + ## 0.1.0-draft.3 — 2026-11-19 ### Added @@ -793,6 +942,7 @@ First published version of the specification. [#279]: https://github.com/ethdebug/format/pull/279 [#280]: https://github.com/ethdebug/format/pull/280 [#281]: https://github.com/ethdebug/format/pull/281 +[#282]: https://github.com/ethdebug/format/issues/282 [#284]: https://github.com/ethdebug/format/pull/284 [#285]: https://github.com/ethdebug/format/pull/285 [#286]: https://github.com/ethdebug/format/pull/286 diff --git a/packages/bugc/CHANGELOG.md b/packages/bugc/CHANGELOG.md index 09fe34bccc..fb2af21347 100644 --- a/packages/bugc/CHANGELOG.md +++ b/packages/bugc/CHANGELOG.md @@ -7,6 +7,22 @@ support. Changes to the specification itself are tracked in the root ## Unreleased +### Changed + +- The debug information's types use the new type kinds. An integer type is + `{ "kind": "number", "label": "uint256" }`, and a signed one adds + `"signed": true`. `bytes` and `bytesN` are `{ "kind": "bytes" }`, with the + spelling in `label` and no `size`. An array has no `count`. `address`, + `bool` and `string` types carry a `label`. A scalar that comes from the + compiler and not from a source type is `{ "kind": "number" }` or + `{ "kind": "address" }` and has no label. The emitted code is the same + ([#282]). + +### Fixed + +- An array type's element count was emitted as `length`, which the schema + does not define. It is no longer emitted ([#282]). + ## 0.1.0-preview.3 — 2026-11-19 ### Added @@ -574,6 +590,7 @@ The version scheme changed: prerelease versions are now `preview.`, and First publication. +[#282]: https://github.com/ethdebug/format/issues/282 [#286]: https://github.com/ethdebug/format/pull/286 [#298]: https://github.com/ethdebug/format/pull/298 [#300]: https://github.com/ethdebug/format/pull/300 diff --git a/packages/format/CHANGELOG.md b/packages/format/CHANGELOG.md index cd3c6610ef..356f55757a 100644 --- a/packages/format/CHANGELOG.md +++ b/packages/format/CHANGELOG.md @@ -6,6 +6,24 @@ tracked in the root [`CHANGELOG.md`](../../CHANGELOG.md). ## Unreleased +### Added + +- `Type.Elementary.Number`, `Type.Elementary.Flags`, `Type.Complex.Variant` + and `Type.Complex.Function`, with the guards `Type.Elementary.isNumber`, + `Type.Elementary.isFlags`, `Type.Complex.isVariant` and + `Type.Complex.isFunction`. `Type.Elementary.Address.Definition` and + `Type.Elementary.Address.isDefinition` cover an address that refers to a + contract. Every type has an optional `label` ([#282]). + +### Breaking + +- The type kinds follow the schemas. The types and guards for `Uint`, + `Int`, `Ufixed`, `Fixed`, `Contract` and `Tuple` are removed. Use + `Number`, `Address` and `Struct`. `Elementary.Bytes` has no `size`, + `Complex.Array` has no `count`, `Elementary.Enum.values` is `string[]`, + and `Complex.Function` has top-level `parameters`, `returns` and + `contract`. See the root [`CHANGELOG.md`](../../CHANGELOG.md) ([#282]). + ## 0.1.0-draft.3 — 2026-11-19 ### Added @@ -158,6 +176,7 @@ First publication. [#245]: https://github.com/ethdebug/format/pull/245 [#246]: https://github.com/ethdebug/format/pull/246 [#276]: https://github.com/ethdebug/format/pull/276 +[#282]: https://github.com/ethdebug/format/issues/282 [#284]: https://github.com/ethdebug/format/pull/284 [#286]: https://github.com/ethdebug/format/pull/286 [#293]: https://github.com/ethdebug/format/pull/293 From 0dccc1441d8871f7f7d74505724c5f2ea9b6cf91 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:44:04 -0500 Subject: [PATCH 13/19] docs: correct the type rewrite changelog entries --- CHANGELOG.md | 74 +++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 171f0fc8fa..5b91ff2b54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,14 +53,36 @@ The sections do not signal obligations; the prefixes do. ## Unreleased +### Added + +- The **ethdebug/format/type/elementary/flags** type is new. It is a set of + named members, with `values` (a list of unique strings) and an optional + `definition`. A set bit `i` in the value's bytes means `values[i]` is + present. Zero is the empty set. A set bit at or past the length of `values` + is invalid ([#282]). + - Schemas: **ethdebug/format/type/elementary/flags** + - Producers: optional: a type may have kind `flags`. + - Consumers: required: a type may have kind `flags`. A consumer must read it + as described to read the data at all. + +- The **ethdebug/format/type/complex/variant** type is new. It has `cases`, + a list of `name`, `discriminant` (an **ethdebug/format/data/value**) and + optional `payload` (a type wrapper), and an optional `definition`. The type + says what each case is. The active case is the one whose `discriminant` + matches the value read as the discriminant. No match is invalid ([#282]). + - Schemas: **ethdebug/format/type/complex/variant** + - Producers: optional: a type may have kind `variant`. + - Consumers: required: a type may have kind `variant`. A consumer must read + it as described to read the data at all. + ### Changed - Every type kind is replaced. A type now says what a value is, and no longer says where its bytes are or how many there are. The layout keywords `bits`, `size` and `count` are gone, and the integer, fixed-point, address and - tuple kinds merge into fewer kinds. Each kind's description now states its - standard interpretation: how a consumer reads a value from the bytes the - value occupies. Every type may have an optional `label`, the type as its + tuple kinds merge into fewer kinds. The descriptions of most kinds now + state their standard interpretation: how a consumer reads a value from the + bytes the value occupies. Every type may have an optional `label`, the type as its language spells it (e.g., `uint256`, `bytes32`, `uint8[3]`), for display only. Nothing interprets a label ([#282]). - Schemas: **ethdebug/format/type**, **ethdebug/format/type/base**, @@ -77,9 +99,9 @@ The sections do not signal obligations; the prefixes do. The value is the big-endian integer over the value's bytes, in two's complement if `signed`, divided by 10 to the power of `places`. For example, `{ "kind": "uint", "bits": 256 }` becomes - `{ "kind": "number", "label": "uint256" }`, and `{ "kind": "int", -"bits": 8 }` becomes `{ "kind": "number", "signed": true, "label": "int8" }` - ([#282]). + `{ "kind": "number", "label": "uint256" }`, and + `{ "kind": "int", "bits": 8 }` becomes + `{ "kind": "number", "signed": true, "label": "int8" }` ([#282]). - Schemas: **ethdebug/format/type/elementary/number**, **ethdebug/format/type/elementary/uint**, **ethdebug/format/type/elementary/int**, @@ -123,26 +145,17 @@ The sections do not signal obligations; the prefixes do. - Consumers: required: read an enum value as the index into `values` described above. -- The **ethdebug/format/type/elementary/flags** type is new. It is a set of - named members, with `values` (a list of unique strings) and an optional - `definition`. A set bit `i` in the value's bytes means `values[i]` is - present. Zero is the empty set. A set bit at or past the length of `values` - is invalid ([#282]). - - Schemas: **ethdebug/format/type/elementary/flags** - - Producers: optional: a type may have kind `flags`. - - Consumers: required: a type may have kind `flags`. A consumer must read it - as described to read the data at all. - - The **ethdebug/format/type/elementary/bool** and - **ethdebug/format/type/elementary/string** types are unchanged except for - the `label` and the standard interpretation in their descriptions. A bool - is 0 (false) or 1 (true), and any other value is invalid. A string is text - in its `encoding` (default utf-8), and an invalid sequence is invalid + **ethdebug/format/type/elementary/string** types may have a `label`, and + their descriptions now state the standard interpretation. A bool is 0 + (false) or 1 (true). A string is text in its `encoding` (default utf-8) ([#282]). - Schemas: **ethdebug/format/type/elementary/bool**, **ethdebug/format/type/elementary/string** - - Producers: no change needed. - - Consumers: no change needed. + - Producers: optional: a type may have a `label`. + - Consumers: required: "Any other value is invalid" (bool) and "If the + bytes are not a valid sequence in that encoding, the value is invalid" + (string). The previous text did not say how to read such values. - The **ethdebug/format/type/complex/struct** type replaces the `tuple` kind. A struct has an ordered `contains` list whose items may each have a @@ -164,16 +177,6 @@ The sections do not signal obligations; the prefixes do. - Consumers: required: an array type has no length. Take the item count from the pointer. -- The **ethdebug/format/type/complex/variant** type is new. It has `cases`, - a list of `name`, `discriminant` (an **ethdebug/format/data/value**) and - optional `payload` (a type wrapper), and an optional `definition`. The type - says what each case is. The active case is the one whose `discriminant` - matches the value read as the discriminant. No match is invalid ([#282]). - - Schemas: **ethdebug/format/type/complex/variant** - - Producers: optional: a type may have kind `variant`. - - Consumers: required: a type may have kind `variant`. A consumer must read - it as described to read the data at all. - - The **ethdebug/format/type/complex/function** type has a new shape. `parameters` and `returns` are top-level lists (`returns` is required, and `[]` means no values). They replace `contains.parameters` and @@ -188,13 +191,12 @@ The sections do not signal obligations; the prefixes do. top level of the function type. - The **ethdebug/format/type/complex/alias** and - **ethdebug/format/type/complex/mapping** types keep their structure and - gain the `label` and the standard interpretation in their descriptions + **ethdebug/format/type/complex/mapping** types may have a `label` ([#282]). - Schemas: **ethdebug/format/type/complex/alias**, **ethdebug/format/type/complex/mapping** - - Producers: no change needed. - - Consumers: no change needed. + - Producers: optional: a type may have a `label`. + - Consumers: no change needed. A label is for display only. - The examples that embed types now use the new kinds ([#282]). - Schemas: **ethdebug/format/info**, **ethdebug/format/info/resources**, From 0d2ed0f8686d01a0598bc6bc63e235785c7e76c8 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:53:43 -0500 Subject: [PATCH 14/19] format: state alias and mapping interpretations --- schemas/type/complex/alias.schema.yaml | 6 +++++- schemas/type/complex/mapping.schema.yaml | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/schemas/type/complex/alias.schema.yaml b/schemas/type/complex/alias.schema.yaml index f727fd287c..4332e54e84 100644 --- a/schemas/type/complex/alias.schema.yaml +++ b/schemas/type/complex/alias.schema.yaml @@ -2,7 +2,11 @@ $schema: "https://json-schema.org/draft/2020-12/schema" $id: "schema:ethdebug/format/type/complex/alias" title: ethdebug/format/type/complex/alias -description: Schema representing a type alias to another type +description: | + Schema representing a type alias to another type. + + Standard interpretation: the value is read as the `contains` type. An + alias does not change how the value is read. type: object properties: diff --git a/schemas/type/complex/mapping.schema.yaml b/schemas/type/complex/mapping.schema.yaml index d766a5b948..241f9d0c5c 100644 --- a/schemas/type/complex/mapping.schema.yaml +++ b/schemas/type/complex/mapping.schema.yaml @@ -2,7 +2,12 @@ $schema: "https://json-schema.org/draft/2020-12/schema" $id: "schema:ethdebug/format/type/complex/mapping" title: ethdebug/format/type/complex/mapping -description: Schema for representing mapping types +description: | + Schema for representing mapping types. + + Standard interpretation: each entry's value is read as the `value` type, + and its key as the `key` type. This type does not define how a key selects + its entry's bytes. type: object properties: From 10a4659b1ef2bd436444280dd88c5d8e151eb2ea Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:53:44 -0500 Subject: [PATCH 15/19] docs: correct changelog reasons for removed fields --- CHANGELOG.md | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b91ff2b54..2359fc03ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,9 +82,9 @@ The sections do not signal obligations; the prefixes do. `size` and `count` are gone, and the integer, fixed-point, address and tuple kinds merge into fewer kinds. The descriptions of most kinds now state their standard interpretation: how a consumer reads a value from the - bytes the value occupies. Every type may have an optional `label`, the type as its - language spells it (e.g., `uint256`, `bytes32`, `uint8[3]`), for display - only. Nothing interprets a label ([#282]). + bytes the value occupies. Every type may have an optional `label`, the type + as its language spells it (e.g., `uint256`, `bytes32`, `uint8[3]`), for + display only. Nothing interprets a label ([#282]). - Schemas: **ethdebug/format/type**, **ethdebug/format/type/base**, **ethdebug/format/type/elementary**, **ethdebug/format/type/complex**, **ethdebug/format/type/specifier** @@ -109,7 +109,8 @@ The sections do not signal obligations; the prefixes do. **ethdebug/format/type/elementary/fixed** - Producers: required: the schemas for kinds `uint`, `int`, `ufixed` and `fixed` are removed, so a type with one of those kinds no longer - validates. Use kind `number`. The `bits` keyword is not allowed. + validates. Use kind `number`. The `bits` keyword has no meaning now, and + consumers ignore it. - Consumers: required: a type with kind `number` is an integer or fixed-point number as described. The width comes from the pointer, not the type. @@ -129,9 +130,9 @@ The sections do not signal obligations; the prefixes do. - The **ethdebug/format/type/elementary/bytes** type no longer has `size`. Its value is the bytes of the value, in order ([#282]). - Schemas: **ethdebug/format/type/elementary/bytes** - - Producers: required: the `size` keyword is removed, so a type with it no - longer validates. A fixed-size `bytes` type is `{ "kind": "bytes" }`, and - the pointer gives the size. + - Producers: required: the `size` keyword is removed. It has no meaning now, + and consumers ignore it. A fixed-size `bytes` type is + `{ "kind": "bytes" }`, and the pointer gives the size. - Consumers: required: a type with kind `bytes` has no `size`. Take the length from the bytes the value occupies. @@ -172,8 +173,9 @@ The sections do not signal obligations; the prefixes do. items are all of the `contains` type. The pointer gives how many there are ([#282]). - Schemas: **ethdebug/format/type/complex/array** - - Producers: required: the `count` keyword is removed, so an array with it no - longer validates. + - Producers: required: the `count` keyword is removed. It has no meaning + now, and consumers ignore it. A stale `count` does not fix the length of + the array. - Consumers: required: an array type has no length. Take the item count from the pointer. @@ -185,18 +187,23 @@ The sections do not signal obligations; the prefixes do. with a `definition` or a type reference. It replaces `contains.contract`. Exactly one of `internal` and `external` is true, as before ([#282]). - Schemas: **ethdebug/format/type/complex/function** - - Producers: required: `contains` is not allowed in a function type, and - `returns` is required. Data in the old shape no longer validates. + - Producers: required: `returns` is required, so data in the old shape no + longer validates. `contains` has no meaning in a function type now, and + consumers ignore it. - Consumers: required: read `parameters`, `returns` and `contract` at the top level of the function type. - The **ethdebug/format/type/complex/alias** and - **ethdebug/format/type/complex/mapping** types may have a `label` - ([#282]). + **ethdebug/format/type/complex/mapping** types may have a `label`, and + their descriptions now state the standard interpretation. An alias is read + as its `contains` type. A mapping entry's value is read as the `value` type + and its key as the `key` type ([#282]). - Schemas: **ethdebug/format/type/complex/alias**, **ethdebug/format/type/complex/mapping** - Producers: optional: a type may have a `label`. - - Consumers: no change needed. A label is for display only. + - Consumers: required: "An alias does not change how the value is + read" (alias) and "This type does not define how a key selects its entry's + bytes" (mapping). The previous text did not say how to read such values. - The examples that embed types now use the new kinds ([#282]). - Schemas: **ethdebug/format/info**, **ethdebug/format/info/resources**, From 3e26c983d630c957bcc8d4e6e7924f681dd44d03 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:53:44 -0500 Subject: [PATCH 16/19] web: fix type docs details --- packages/web/docs/core-schemas/types/composite.mdx | 6 +++--- packages/web/docs/core-schemas/types/elementary.mdx | 2 +- .../docs/implementation-guides/building-a-trace-viewer.mdx | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/web/docs/core-schemas/types/composite.mdx b/packages/web/docs/core-schemas/types/composite.mdx index 4e960bb3ea..5cb41a6295 100644 --- a/packages/web/docs/core-schemas/types/composite.mdx +++ b/packages/web/docs/core-schemas/types/composite.mdx @@ -44,9 +44,9 @@ This represents `uint256[]`—an array of any length. }`} -This represents `address[10]`—exactly 10 addresses. An array type has no -element count. The type says what the elements are; the value's pointer -says where they are, and so how many there are. +The label spells the type as `address[10]`, but nothing reads the 10 from +it. An array type has no element count. The type says what the elements +are; the value's pointer says where they are, and so how many there are. ## Structs diff --git a/packages/web/docs/core-schemas/types/elementary.mdx b/packages/web/docs/core-schemas/types/elementary.mdx index 62ed3dc8e2..dbf0d3b943 100644 --- a/packages/web/docs/core-schemas/types/elementary.mdx +++ b/packages/web/docs/core-schemas/types/elementary.mdx @@ -122,7 +122,7 @@ field can keep the language's spelling: ## String type -Strings represent UTF-8 encoded text: +Strings represent text in the type's `encoding` (default UTF-8): Date: Fri, 20 Nov 2026 15:53:44 -0500 Subject: [PATCH 17/19] bugc: test signed integer type emission --- packages/bugc/src/irgen/debug/types.test.ts | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 packages/bugc/src/irgen/debug/types.test.ts diff --git a/packages/bugc/src/irgen/debug/types.test.ts b/packages/bugc/src/irgen/debug/types.test.ts new file mode 100644 index 0000000000..081fafa0c0 --- /dev/null +++ b/packages/bugc/src/irgen/debug/types.test.ts @@ -0,0 +1,22 @@ +import { describe, it, expect } from "vitest"; + +import { Type as BugType } from "#types"; + +import { convertBugType } from "./types.js"; + +describe("convertBugType", () => { + it("emits an unsigned number for uint", () => { + expect(convertBugType(BugType.Elementary.uint(256))).toEqual({ + kind: "number", + label: "uint256", + }); + }); + + it("emits a signed number for int", () => { + expect(convertBugType(BugType.Elementary.int(8))).toEqual({ + kind: "number", + signed: true, + label: "int8", + }); + }); +}); From 8c5e7548aede106691e59a31ed3bc7374c383bbc Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:55:25 -0500 Subject: [PATCH 18/19] format: let base complex types omit contains when they give class --- CHANGELOG.md | 8 +++- packages/format/src/types/type/base.ts | 16 ++++--- packages/format/src/types/type/index.test.ts | 47 ++++++++++++++++++++ packages/format/test/extensions.ts | 7 +-- packages/web/spec/type/base.mdx | 11 +++-- packages/web/spec/type/concepts.mdx | 5 +++ schemas/type/base.schema.yaml | 12 ++++- 7 files changed, 89 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2359fc03ff..6219c8d72a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,14 +84,18 @@ The sections do not signal obligations; the prefixes do. state their standard interpretation: how a consumer reads a value from the bytes the value occupies. Every type may have an optional `label`, the type as its language spells it (e.g., `uint256`, `bytes32`, `uint8[3]`), for - display only. Nothing interprets a label ([#282]). + display only. Nothing interprets a label. A complex base type may now omit + `contains` if it gives `class` as `complex`, since the new `variant` and + `function` kinds have no `contains` ([#282]). - Schemas: **ethdebug/format/type**, **ethdebug/format/type/base**, **ethdebug/format/type/elementary**, **ethdebug/format/type/complex**, **ethdebug/format/type/specifier** - Producers: required: the kinds below replace the old kinds, and the old kinds no longer validate. See the entries for each kind. - Consumers: required: producers emit the new kinds. A consumer must read - them and must not expect the old kinds. See the entries for each kind. + them and must not expect the old kinds. See the entries for each kind. A consumer that + uses **ethdebug/format/type/base** to classify complex types must accept + a complex type without `contains`. - The **ethdebug/format/type/elementary/number** type replaces the `uint`, `int`, `ufixed` and `fixed` kinds. It has an optional `signed` (default diff --git a/packages/format/src/types/type/base.ts b/packages/format/src/types/type/base.ts index 0ba41731d7..f60b155322 100644 --- a/packages/format/src/types/type/base.ts +++ b/packages/format/src/types/type/base.ts @@ -22,7 +22,8 @@ export interface Complex { class?: "complex"; kind: string; label?: string; - contains: + /** Required unless `class` is `"complex"`. */ + contains?: | Wrapper | Wrapper[] | { @@ -37,12 +38,13 @@ export const isComplex = (value: unknown): value is Complex => typeof value.kind === "string" && (!("label" in value) || typeof value.label === "string") && (!("class" in value) || value.class === "complex") && - "contains" in value && - !!value.contains && - (isWrapper(value.contains) || - (Array.isArray(value.contains) && value.contains.every(isWrapper)) || - (typeof value.contains === "object" && - Object.values(value.contains).every(isWrapper))); + (("class" in value && !("contains" in value)) || + ("contains" in value && + !!value.contains && + (isWrapper(value.contains) || + (Array.isArray(value.contains) && value.contains.every(isWrapper)) || + (typeof value.contains === "object" && + Object.values(value.contains).every(isWrapper))))); export interface Wrapper { type: Type | { id: any }; diff --git a/packages/format/src/types/type/index.test.ts b/packages/format/src/types/type/index.test.ts index cea73693f7..72b6b60e85 100644 --- a/packages/format/src/types/type/index.test.ts +++ b/packages/format/src/types/type/index.test.ts @@ -255,3 +255,50 @@ describe("rejected values", () => { }); } }); + +describe("complex types without contains", () => { + const typeSchema = "schema:ethdebug/format/type"; + const baseSchema = "schema:ethdebug/format/type/base"; + + const variant = { + class: "complex", + kind: "variant", + discriminant: { type: { kind: "number" } }, + cases: [{ name: "A", discriminant: 0 }], + }; + const fn = { + class: "complex", + kind: "function", + internal: true, + parameters: [], + returns: [], + }; + + const accepted = [ + { + title: "an unknown complex kind that contains a known variant", + value: { class: "complex", kind: "pair", contains: [{ type: variant }] }, + }, + { + title: "an unknown complex kind that contains a known function", + value: { class: "complex", kind: "pair", contains: [{ type: fn }] }, + }, + ] as const; + + for (const { title, value } of accepted) { + it(`accepts ${title}`, async () => { + expect(isType(value)).toBe(true); + await expect(value).toValidate({ schema: typeSchema }); + }); + } + + it("accepts a complex base type with a class and no contains", async () => { + const value = { class: "complex", kind: "thing" }; + expect(Type.Base.isType(value)).toBe(true); + await expect(value).toValidate({ schema: baseSchema }); + }); + + it("rejects an unknown kind without a class", () => { + expect(isType({ kind: "thing" })).toBe(false); + }); +}); diff --git a/packages/format/test/extensions.ts b/packages/format/test/extensions.ts index 7ff755fbfc..b45ce3a5c8 100644 --- a/packages/format/test/extensions.ts +++ b/packages/format/test/extensions.ts @@ -57,7 +57,8 @@ export const schemaExtensions: { "schema:ethdebug/format/type/complex/struct": { extends: new Set(["schema:ethdebug/format/type/complex"]), }, - // function and variant are absent on purpose. Listing them under - // type/complex fails: the check follows that entry up to the base - // complex type, which requires `contains`. These kinds have none. + // function and variant are absent on purpose. Their examples omit + // `class` (it is optional on known kinds) and have no `contains`. + // The base complex type needs one of the two, so those examples are + // not valid base complex types. With `class: "complex"` they are. }; diff --git a/packages/web/spec/type/base.mdx b/packages/web/spec/type/base.mdx index ea5de6d112..bc17751a79 100644 --- a/packages/web/spec/type/base.mdx +++ b/packages/web/spec/type/base.mdx @@ -63,13 +63,14 @@ When extending this schema, there **should** exist exactly one corresponding schema for each `kind` value. ::: -### The `class` field is always optional +### The `class` field Although **ethdebug/format/type** does not require the `class` field to be defined for known types, it does require this field for representations of unknown types. -The **ethdebug/format/type/base** schema does not ever require this field. +The **ethdebug/format/type/base** schema does not require this field for +elementary types. A complex base type gives either `class` or `contains`. ### A complex base type `contains` other base types @@ -77,7 +78,11 @@ As described in key concept [Elementary vs. complex types](/spec/type/concepts#elementary-vs-complex-types), this format allows the representation of types whose definition includes other types. Both the primary schema and this base schema -require type composition to be represented via complex types' `contains` field. +require an unknown complex kind to give `class` as `"complex"` and, if it +composes other types, to put them under `contains`. Known kinds have their +own schemas, and some state their parts in other fields (`variant` uses +`cases`, and `function` uses `parameters` and `returns`). A complex base type +gives `contains`, `class`, or both. These two schemas differ by which type schema this field is permitted to compose. Naturally, **ethdebug/format/type**'s `contains` field diff --git a/packages/web/spec/type/concepts.mdx b/packages/web/spec/type/concepts.mdx index 75c33e7ffd..5362ec6ff3 100644 --- a/packages/web/spec/type/concepts.mdx +++ b/packages/web/spec/type/concepts.mdx @@ -81,6 +81,11 @@ of three forms: All three forms of composition polymorphically use the `"contains"` field. +Some known kinds state their parts in other fields instead (`variant` uses +`cases`, and `function` uses `parameters` and `returns`). Where such a type +sits inside an unknown complex kind, it gives `"class": "complex"`. The base +schema needs `"class"` or `"contains"`, and this type has no `"contains"`. + As described in [Type specifiers, wrappers, and references](#type-specifiers-wrappers-and-references) below, complex types compose diff --git a/schemas/type/base.schema.yaml b/schemas/type/base.schema.yaml index c5d2e7c2f1..d5a70e9b42 100644 --- a/schemas/type/base.schema.yaml +++ b/schemas/type/base.schema.yaml @@ -47,7 +47,11 @@ $defs: title: Base complex type description: Represents a complex type, one that composes other types (e.g., arrays, - structs, mappings) + structs, mappings). A complex type gives `contains`, or gives + `class` as `complex`, or both. A complex type with `class` and no + `contains` is one whose kind states its parts in other fields (e.g., + `variant` has `cases`, and `function` has `parameters` and `returns`). + When `contains` is present, it follows the rules below. type: object properties: class: @@ -71,7 +75,11 @@ $defs: required: - kind - - contains + anyOf: + - required: + - contains + - required: + - class examples: - kind: array contains: From cdd90b21105ed328c88ca1c58ac0ad16c34b591d Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 20 Nov 2026 15:56:31 -0500 Subject: [PATCH 19/19] docs: fix two changelog details --- CHANGELOG.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6219c8d72a..2e7f268c95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -93,9 +93,9 @@ The sections do not signal obligations; the prefixes do. - Producers: required: the kinds below replace the old kinds, and the old kinds no longer validate. See the entries for each kind. - Consumers: required: producers emit the new kinds. A consumer must read - them and must not expect the old kinds. See the entries for each kind. A consumer that - uses **ethdebug/format/type/base** to classify complex types must accept - a complex type without `contains`. + them and must not expect the old kinds. See the entries for each kind. + A consumer that uses **ethdebug/format/type/base** to classify complex + types must accept a complex type without `contains`. - The **ethdebug/format/type/elementary/number** type replaces the `uint`, `int`, `ufixed` and `fixed` kinds. It has an optional `signed` (default @@ -205,9 +205,8 @@ The sections do not signal obligations; the prefixes do. - Schemas: **ethdebug/format/type/complex/alias**, **ethdebug/format/type/complex/mapping** - Producers: optional: a type may have a `label`. - - Consumers: required: "An alias does not change how the value is - read" (alias) and "This type does not define how a key selects its entry's - bytes" (mapping). The previous text did not say how to read such values. + - Consumers: no change needed. The new prose describes how these kinds + were already read. - The examples that embed types now use the new kinds ([#282]). - Schemas: **ethdebug/format/info**, **ethdebug/format/info/resources**,