diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a129594b1..2e7f268c95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,167 @@ 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. 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. 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. + 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 + 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 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. + +- 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. 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. + +- 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/bool** and + **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: 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 + `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. 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. + +- 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: `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`, 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. 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**, + **ethdebug/format/program** + - Producers: no change needed. + - Consumers: no change needed. + ## 0.1.0-draft.3 — 2026-11-19 ### Added @@ -793,6 +954,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/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.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", + }); + }); +}); 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)) { diff --git a/packages/conformance/test/conformance.test.ts b/packages/conformance/test/conformance.test.ts index 50e8e19a7a..b539eab5e6 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,21 @@ 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 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; + } + return { + ...artifact, + resources: { ...artifact.resources, types: {} }, + }; +} + function validArtifact( overrides: Partial = {}, ): EthdebugArtifact { @@ -202,7 +217,9 @@ describe("@ethdebug/conformance", () => { sourcePath: path.join(root, "test/fixtures/solc/Counter.sol"), }); - const result = await validateStaticConformance(artifact); + const result = await validateStaticConformance( + withEmptyResourcesTypes(artifact), + ); expect(result.issues).toEqual([]); expect(result.ok).toBe(true); expect( @@ -211,6 +228,28 @@ describe("@ethdebug/conformance", () => { }, ); + // Expected failure (#423): see withEmptyResourcesTypes. + 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 withEmptyResourcesTypes (#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 +350,9 @@ describe("@ethdebug/conformance", () => { path.join(sourceDir, "Math.sol"), ], }); - const result = await validateStaticConformance(artifact); + const result = await validateStaticConformance( + withEmptyResourcesTypes(artifact), + ); expect(result.issues).toEqual([]); expect(result.ok).toBe(true); @@ -583,8 +624,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/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 diff --git a/packages/format/src/types/type/base.ts b/packages/format/src/types/type/base.ts index ff0f2d98b5..f60b155322 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,13 +14,16 @@ 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; - contains: + label?: string; + /** Required unless `class` is `"complex"`. */ + contains?: | Wrapper | Wrapper[] | { @@ -32,13 +36,15 @@ 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 && - (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 7747395dc7..72b6b60e85 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 @@ -69,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, @@ -85,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 @@ -102,53 +94,211 @@ 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 contract", + value: { kind: "address", definition: { name: "T" } }, + }, + { + title: "normal contract (flags explicitly false)", + value: { + kind: "address", + definition: { name: "T", library: false, interface: false }, + }, + }, { - title: "normal (flags explicitly false)", - value: { kind: "contract", 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 }); }); } +}); + +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 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: "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 }, + }, + ] as const; + + for (const { title, value } of rejected) { + it(`rejects ${title}`, async () => { + expect(isType(value)).toBe(false); + await expect(value).not.toValidate({ schema: typeSchema }); + }); + } +}); + +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 non-boolean flag values", () => { - expect( - Type.Elementary.isContract({ kind: "contract", library: "true" }), - ).toBe(false); - expect(Type.Elementary.isContract({ kind: "contract", interface: 1 })).toBe( - false, - ); + it("rejects an unknown kind without a class", () => { + expect(isType({ kind: "thing" })).toBe(false); }); }); diff --git a/packages/format/src/types/type/index.ts b/packages/format/src/types/type/index.ts index 71efeb15fe..8ec9bc31fa 100644 --- a/packages/format/src/types/type/index.ts +++ b/packages/format/src/types/type/index.ts @@ -57,16 +57,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,215 +74,169 @@ 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"; - bits: number; + kind: "number"; + label?: string; + 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") && - 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"; - bits: number; - } + mayHaveLabel(value) && + 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") && - 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"; - 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") && - 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"; - bits: number; - places: number; + kind: "address"; + label?: string; + 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") && - 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; + mayHaveLabel(value) && + hasKind(value, "address") && + (!("payable" in value) || typeof value.payable === "boolean") && + (!("definition" in value) || Address.isDefinition(value.definition)); 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"; - size?: Data.Unsigned; - } - - export const isBytes = (value: unknown): value is Bytes => - typeof value === "object" && - !!value && - mayHaveClass(value, "elementary") && - 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"; - encoding?: string; + kind: "enum"; + label?: 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") && - hasKind(value, "string") && - (!("encoding" in value) || typeof value.encoding === "string"); + mayHaveLabel(value) && + 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"; - payable?: boolean; + kind: "flags"; + label?: string; + 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") && - hasKind(value, "address") && - (!("payable" in value) || typeof value.payable === "boolean"); + mayHaveLabel(value) && + 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"; - payable?: boolean; - library?: boolean; - interface?: boolean; - definition?: Definition; + kind: "bytes"; + label?: string; } - export const isContract = (value: unknown): value is Contract => + export const isBytes = (value: unknown): value is Bytes => typeof value === "object" && !!value && mayHaveClass(value, "elementary") && - 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)); + mayHaveLabel(value) && + hasKind(value, "bytes"); - export interface Enum { + export interface String { class?: "elementary"; - kind: "enum"; - values: any[]; - definition?: Definition; + kind: "string"; + label?: string; + 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") && - hasKind(value, "enum") && - "values" in value && - Array.isArray(value.values) && - (!("definition" in value) || isDefinition(value.definition)); + mayHaveLabel(value) && + hasKind(value, "string") && + (!("encoding" in value) || typeof value.encoding === "string"); } 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, @@ -296,28 +247,25 @@ 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 { export interface Alias { class?: "complex"; kind: "alias"; + label?: string; contains: Wrapper; definition?: Definition; } @@ -326,33 +274,16 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "complex") && + mayHaveLabel(value) && hasKind(value, "alias") && "contains" in value && isWrapper(value.contains) && (!("definition" in value) || isDefinition(value.definition)); - export interface Tuple { - class?: "complex"; - kind: "tuple"; - contains: (Wrapper & { name?: string })[]; - } - - export const isTuple = (value: unknown): value is Tuple => - typeof value === "object" && - !!value && - mayHaveClass(value, "complex") && - 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"; + label?: string; contains: Wrapper; } @@ -360,6 +291,7 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "complex") && + mayHaveLabel(value) && hasKind(value, "array") && "contains" in value && isWrapper(value.contains); @@ -367,6 +299,7 @@ export namespace Type { export interface Mapping { class?: "complex"; kind: "mapping"; + label?: string; contains: { key: Wrapper; value: Wrapper; @@ -377,6 +310,7 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "complex") && + mayHaveLabel(value) && hasKind(value, "mapping") && "contains" in value && typeof value.contains === "object" && @@ -389,7 +323,8 @@ export namespace Type { export interface Struct { class?: "complex"; kind: "struct"; - contains: (Wrapper & { name?: string })[]; + label?: string; + contains: Named[]; definition?: Definition; } @@ -397,15 +332,93 @@ export namespace Type { typeof value === "object" && !!value && mayHaveClass(value, "complex") && + mayHaveLabel(value) && 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 { @@ -428,6 +441,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/packages/format/test/extensions.ts b/packages/format/test/extensions.ts index 20e07ec7d4..b45ce3a5c8 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"]), }, @@ -57,9 +48,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 +57,8 @@ 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. 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/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/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..e9273ceb9a 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. @@ -82,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: @@ -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..5cb41a6295 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. +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 @@ -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,28 +178,47 @@ 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 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 f545a1a2ed..dbf0d3b943 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: - - - {`{ "kind": "bytes", "size": 32 }`} - +Byte strings use the `bytes` kind: - {`{ "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: +Strings represent text in the type's `encoding` (default UTF-8): -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,50 @@ 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 +## Flags type -Contract types represent references to contract instances: +Flags represent a set of named flags: - {`{ "kind": "contract" }`} + {`{ + "kind": "flags", + "definition": { + "name": "Permissions" + }, + "values": ["READ", "WRITE", "EXECUTE"] +}`} -Contract types may include a `definition` field when the contract is defined -in source code: +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 +definition names the contract: {`{ - "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..2242d136d2 100644 --- a/packages/web/docs/implementation-guides/building-a-trace-viewer.mdx +++ b/packages/web/docs/implementation-guides/building-a-trace-viewer.mdx @@ -56,10 +56,12 @@ 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"; + // 0 is false, 1 is true, any other value is invalid + return ["false", "true"][Number(Raw.asUint(bytes))] ?? "invalid"; case "address": return "0x" + Raw.toHex(bytes).slice(-40); // ... other types 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..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 @@ -101,20 +106,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 +187,7 @@ correspond to the canonical **ethdebug/format/type** schema._ const: complex kind: type: string - const: array + const: mapping contains: type: object properties: @@ -219,8 +220,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..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 @@ -98,15 +103,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 +119,7 @@ possibly includes other fields alongside `"type"`. "contains": [{ "name": "balance", "type": { - "kind": "uint", - "bits": 256 + "kind": "number" } }, { "name": "scoreSheet", @@ -146,8 +149,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 = { 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); 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 diff --git a/schemas/type/base.schema.yaml b/schemas/type/base.schema.yaml index eeca1e9ceb..d5a70e9b42 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,14 +36,22 @@ $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 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: @@ -45,6 +61,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: @@ -57,23 +75,24 @@ $defs: required: - kind - - contains + anyOf: + - required: + - contains + - required: + - class examples: - 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 +101,7 @@ $defs: payable: true value: type: - kind: uint - bits: 256 + kind: number TypeWrapper: title: '{ "type": ... }' 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/alias.schema.yaml b/schemas/type/complex/alias.schema.yaml index 6e68e5eae1..4332e54e84 100644 --- a/schemas/type/complex/alias.schema.yaml +++ b/schemas/type/complex/alias.schema.yaml @@ -2,10 +2,16 @@ $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: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: type: string const: complex @@ -25,8 +31,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 b01d54b1c9..7593636458 100644 --- a/schemas/type/complex/array.schema.yaml +++ b/schemas/type/complex/array.schema.yaml @@ -3,12 +3,14 @@ $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: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: type: string const: complex @@ -20,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 @@ -35,12 +32,11 @@ examples: - kind: array contains: type: - kind: uint - bits: 256 + 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 b6c61c8736..8ad4070a98 100644 --- a/schemas/type/complex/function.schema.yaml +++ b/schemas/type/complex/function.schema.yaml @@ -11,60 +11,48 @@ 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: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: type: string const: complex 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 @@ -74,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: - - $ref: "schema:ethdebug/format/type/elementary/contract" - - $ref: "schema:ethdebug/format/type/reference" + 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" + - type: object + required: + - definition + - $ref: "schema:ethdebug/format/type/reference" required: - external @@ -103,6 +91,8 @@ oneOf: const: true external: const: false + contract: + not: {} required: - internal @@ -111,62 +101,45 @@ examples: internal: true definition: name: increment - contains: - parameters: - type: - kind: tuple - contains: - - name: value - type: - kind: uint - bits: 256 - returns: + parameters: + - name: value type: - kind: uint - bits: 256 + kind: number + returns: + - type: + kind: number + - kind: function external: true definition: name: withdraw - contains: - contract: - type: - kind: contract - payable: true + contract: + type: + kind: address + payable: true + definition: + name: Bank interface: true - definition: - name: Bank - parameters: + parameters: + - name: beneficiary type: - kind: tuple - contains: - - name: beneficiary - type: - kind: address - payable: true - - name: amount - type: - kind: ufixed - bits: 128 - places: 18 - returns: + kind: address + payable: true + - 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/mapping.schema.yaml b/schemas/type/complex/mapping.schema.yaml index 8f1b0c23ed..241f9d0c5c 100644 --- a/schemas/type/complex/mapping.schema.yaml +++ b/schemas/type/complex/mapping.schema.yaml @@ -2,10 +2,17 @@ $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: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: type: string const: complex @@ -36,5 +43,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 9affcbc291..ee60ecccb4 100644 --- a/schemas/type/complex/struct.schema.yaml +++ b/schemas/type/complex/struct.schema.yaml @@ -2,10 +2,15 @@ $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: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: type: string const: complex @@ -28,12 +33,22 @@ examples: contains: - name: x type: - kind: uint - bits: 128 + kind: number - name: y type: - kind: uint - bits: 128 + 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: diff --git a/schemas/type/complex/tuple.schema.yaml b/schemas/type/complex/tuple.schema.yaml deleted file mode 100644 index 70c4ed84c2..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: - 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: uint - bits: 128 - - name: y - type: - kind: uint - bits: 128 - -$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 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 d386940427..98600077ac 100644 --- a/schemas/type/elementary/address.schema.yaml +++ b/schemas/type/elementary/address.schema.yaml @@ -2,10 +2,18 @@ $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: 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: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: const: elementary kind: @@ -14,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: @@ -23,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 044dea73e7..6b72540574 100644 --- a/schemas/type/elementary/bool.schema.yaml +++ b/schemas/type/elementary/bool.schema.yaml @@ -2,10 +2,17 @@ $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: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: const: elementary kind: @@ -14,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 5fb217ad4b..79b2764a10 100644 --- a/schemas/type/elementary/bytes.schema.yaml +++ b/schemas/type/elementary/bytes.schema.yaml @@ -2,25 +2,23 @@ $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: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: 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 48d4eeb47d..0000000000 --- a/schemas/type/elementary/contract.schema.yaml +++ /dev/null @@ -1,57 +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: - 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 f20a4488d5..2f44b6c6b6 100644 --- a/schemas/type/elementary/enum.schema.yaml +++ b/schemas/type/elementary/enum.schema.yaml @@ -2,20 +2,28 @@ $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: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: const: elementary 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" @@ -29,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 0fe866a2b3..0000000000 --- a/schemas/type/elementary/fixed.schema.yaml +++ /dev/null @@ -1,35 +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: - 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 fac0c378a4..0000000000 --- a/schemas/type/elementary/int.schema.yaml +++ /dev/null @@ -1,23 +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: - 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 1eb4566b84..d5c3044235 100644 --- a/schemas/type/elementary/string.schema.yaml +++ b/schemas/type/elementary/string.schema.yaml @@ -2,10 +2,17 @@ $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: + label: + $ref: "schema:ethdebug/format/type/base#/$defs/Label" class: const: elementary kind: @@ -21,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 3bfb36af30..0000000000 --- a/schemas/type/elementary/ufixed.schema.yaml +++ /dev/null @@ -1,35 +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: - 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 6a913e478a..0000000000 --- a/schemas/type/elementary/uint.schema.yaml +++ /dev/null @@ -1,23 +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: - 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