Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ The sections do not signal obligations; the prefixes do.
it uses. If members depend on each other in a cycle, the pointer is
invalid."

- The description of `places` in the fixed-point types calls the integer
before scaling an "unscaled value" instead of a "raw value". "Raw" now
means bytes only.
- Schemas: **ethdebug/format/type/elementary/fixed**,
**ethdebug/format/type/elementary/ufixed**
- Producers: no change needed.
- Consumers: no change needed.

- Variables now have a stated sort. A list's `each` variable is an integer.
A `define` variable has the sort of its expression, so a bytes variable
keeps its width. A template's `expect`ed variable takes the sort of the
Expand Down
9 changes: 5 additions & 4 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ guards that run in CI live in `bin/check-tarballs.ts` and
packages work but implement a draft. Releases before `0.1.0-draft.0`
used a plain number (`0.1.0-0` to `0.1.0-2`); they sort before the
named ones.
- Ten workspaces can take part in a release: the seven public
packages (`format`, `pointers`, `evm`, `bugc`, `bugc-react`,
- Eleven workspaces can take part in a release: the eight public
packages (`format`, `common`, `pointers`, `evm`, `bugc`, `bugc-react`,
`pointers-react`, `programs-react`) and the three private ones
(`format-web`, `bug-playground`, `conformance`). Private workspaces
get versions and tags like the others, but the publish script skips
Expand All @@ -32,8 +32,9 @@ guards that run in CI live in `bin/check-tarballs.ts` and
not count), `@ethdebug/format` when `schemas/` changed (the schemas
live outside the package directory but ship inside it), and every
workspace that depends on a moving one, directly or transitively.
Every workspace depends on `@ethdebug/format`, so a specification
change moves all ten.
Every workspace except `@ethdebug/common` and `@ethdebug/evm`
depends on `@ethdebug/format`, so a specification change moves the
other nine.
- Series convention, for now: all workspaces start a `major.minor`
series together and graduate together with the spec; between those
events each workspace moves only when it or a dependency changed,
Expand Down
1 change: 1 addition & 0 deletions bin/check-react-consumers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// type-checks with skipLibCheck off, so a broken .d.ts fails.
const packed = [
"format",
"common",
"pointers",
"evm",
"programs-react",
Expand Down Expand Up @@ -130,5 +131,5 @@
`,
);
run("node", ["highlight.mjs"], dir);
console.log(`ok: React ${react} + shiki ${shiki}/${sub}, bundle ${kb} KB gz`);

Check warning on line 134 in bin/check-react-consumers.ts

View workflow job for this annotation

GitHub Actions / lint-and-format

Unexpected console statement
}
3 changes: 2 additions & 1 deletion bin/start
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ fi

# Run the commands with concurrently
concurrently \
--names=format,pointers,evm,bugc,bugc-react,pointers-react,programs-react,playground,web,tests \
--names=format,common,pointers,evm,bugc,bugc-react,pointers-react,programs-react,playground,web,tests \
"cd ./packages/format && yarn watch" \
"cd ./packages/common && yarn watch" \
"cd ./packages/pointers && yarn watch" \
"cd ./packages/evm && yarn watch" \
"cd ./packages/bugc && yarn watch" \
Expand Down
1 change: 1 addition & 0 deletions packages/bugc-react/tsconfig.typecheck.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"rootDir": "../..",
"paths": {
"@ethdebug/bugc": ["../bugc/src/index.ts"],
"@ethdebug/common": ["../common/src/index.ts"],
"@ethdebug/evm": ["../evm/src/index.ts"],
"@ethdebug/format": ["../format/src/index.ts"],
"@ethdebug/pointers": ["../pointers/src/index.ts"],
Expand Down
2 changes: 2 additions & 0 deletions packages/bugc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ support. Changes to the specification itself are tracked in the root

### Changed

- The tests read machine state as `Raw` from `@ethdebug/common`, a new
development dependency.
- `==`, `!=` and a mapping key with bytes or a string in calldata are
now type errors. Before, they compared or hashed the calldata
reference's word (offset and length), not the bytes ([#379]).
Expand Down
1 change: 1 addition & 0 deletions packages/bugc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
},
"license": "MIT",
"devDependencies": {
"@ethdebug/common": "^0.1.0-preview.2",
"@ethdebug/evm": "^0.1.0-preview.2",
"@ethdebug/pointers": "^0.1.0-preview.2",
"@hyperjump/browser": "^1.2.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/bugc/src/evmgen/call-contexts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { describe, it, expect } from "vitest";
import { compile } from "#compiler";
import type * as Format from "@ethdebug/format";
import { Pointer, Program } from "@ethdebug/format";
import { Raw } from "@ethdebug/common";
import { dereference } from "@ethdebug/pointers";
import { traceLocals } from "#test/evm/locals";

Expand Down Expand Up @@ -140,7 +141,7 @@ code {
const view = await cursor.view(state);
const values = await Promise.all(
["a", "b"].map(async (name) =>
(await view.read(view.regions.lookup[name])).asUint(),
Raw.asUint(await view.read(view.regions.lookup[name])),
),
);
expect(values).toEqual([10n, 20n]);
Expand Down
3 changes: 2 additions & 1 deletion packages/bugc/src/evmgen/call-timing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* `return` data pointer must read the returned value.
*/
import { describe, it, expect } from "vitest";
import { Raw } from "@ethdebug/common";
import { dereference } from "@ethdebug/pointers";
import { Program } from "@ethdebug/format";
import type * as Format from "@ethdebug/format";
Expand Down Expand Up @@ -157,7 +158,7 @@ describe("call frame timing", () => {
const state = stateAt(i);
const cursor = await dereference(ret.data.pointer, { state });
const view = await cursor.view(state);
read.push((await view.read(view.regions[0])).asUint());
read.push(Raw.asUint(await view.read(view.regions[0])));
} else {
read.push(undefined);
}
Expand Down
15 changes: 8 additions & 7 deletions packages/bugc/src/evmgen/debug/local-variables.soundness.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { describe, it, expect } from "vitest";

import { Program } from "@ethdebug/format";
import type * as Format from "@ethdebug/format";
import { Raw } from "@ethdebug/common";
import { dereference } from "@ethdebug/pointers";
import { executeProgram } from "#test/evm/behavioral";
import {
Expand Down Expand Up @@ -1707,16 +1708,16 @@ describe.each(levels)("a calldata reference's word at O%i", (level) => {
return regions[0];
});
expect(length.location).toEqual(offset.location);
expect(offset.length?.asUint()).toEqual(16n);
expect(length.length?.asUint()).toEqual(16n);
expect(offset.length && Raw.asUint(offset.length)).toEqual(16n);
expect(length.length && Raw.asUint(length.length)).toEqual(16n);
if (offset.location === "stack" && length.location === "stack") {
expect(length.slot.asUint()).toEqual(offset.slot.asUint());
expect(offset.offset?.asUint()).toEqual(0n);
expect(length.offset?.asUint()).toEqual(16n);
expect(Raw.asUint(length.slot)).toEqual(Raw.asUint(offset.slot));
expect(offset.offset && Raw.asUint(offset.offset)).toEqual(0n);
expect(length.offset && Raw.asUint(length.offset)).toEqual(16n);
} else {
expect(offset.location).toEqual("memory");
expect(length.offset!.asUint()).toEqual(
offset.offset!.asUint() + 16n,
expect(Raw.asUint(length.offset!)).toEqual(
Raw.asUint(offset.offset!) + 16n,
);
}
expect(view.regions.named(name)).toHaveLength(0);
Expand Down
3 changes: 2 additions & 1 deletion packages/bugc/src/evmgen/storage-array-layout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import { describe, it, expect } from "vitest";
import { keccak256 } from "ethereum-cryptography/keccak";
import { bytesToHex } from "ethereum-cryptography/utils";
import { Raw } from "@ethdebug/common";
import { dereference } from "@ethdebug/pointers";
import type * as Format from "@ethdebug/format";

Expand Down Expand Up @@ -173,7 +174,7 @@ describe("storage array pointers", () => {
const read = await Promise.all(
view.regions
.filter((region) => region.name === regionName)
.map(async (region) => (await view.read(region)).asUint()),
.map(async (region) => Raw.asUint(await view.read(region))),
);
expect(read, `${identifier}: ${regionName}`).toEqual(values);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/bugc/src/evmgen/storage-array-push.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { describe, it, expect } from "vitest";
import { keccak256 } from "ethereum-cryptography/keccak";
import { bytesToHex } from "ethereum-cryptography/utils";
import { Raw } from "@ethdebug/common";
import { dereference } from "@ethdebug/pointers";
import type * as Format from "@ethdebug/format";

Expand Down Expand Up @@ -143,7 +144,7 @@ code { h.push(5); h.push(7); h.push(9); }`,
const read = await Promise.all(
view.regions
.filter((region) => region.name === "element")
.map(async (region) => (await view.read(region)).asUint()),
.map(async (region) => Raw.asUint(await view.read(region))),
);
expect(read).toEqual([5n, 7n, 9n]);
});
Expand Down
13 changes: 7 additions & 6 deletions packages/bugc/src/irgen/debug/templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import path from "path";
import { glob } from "glob";
import * as Format from "@ethdebug/format";
import { createMachineState } from "@ethdebug/evm";
import { dereference, type Data, type Machine } from "@ethdebug/pointers";
import { type Machine, Raw } from "@ethdebug/common";
import { dereference } from "@ethdebug/pointers";

import { localsOf, traceLocals } from "#test/evm/locals";
import { parseTestBlocks } from "#test/examples/annotations";
Expand Down Expand Up @@ -97,15 +98,15 @@ async function read(
).view(state);
const regions = [];
for (const region of view.regions) {
const at = (["slot", "offset", "length"] as const).map((key) => [
key,
(region as Partial<Record<typeof key, Data>>)[key]?.toHex(),
]);
const at = (["slot", "offset", "length"] as const).map((key) => {
const value = (region as Partial<Record<typeof key, Raw>>)[key];
return [key, value && Raw.toHex(value)];
});
regions.push({
name: region.name,
location: region.location,
...Object.fromEntries(at),
bytes: (await view.read(region)).toHex(),
bytes: Raw.toHex(await view.read(region)),
});
}
return regions;
Expand Down
3 changes: 2 additions & 1 deletion packages/bugc/src/irgen/debug/variables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { describe, it, expect } from "vitest";
import { bytesToHex, hexToBytes } from "ethereum-cryptography/utils";
import { Executor, createMachineState } from "@ethdebug/evm";
import { Raw } from "@ethdebug/common";
import { dereference } from "@ethdebug/pointers";
import * as Format from "@ethdebug/format";

Expand Down Expand Up @@ -242,7 +243,7 @@ code {
expect(inner.name).toEqual("value");
if (!("slot" in inner)) throw new Error("not a storage region");
const cell = entryOf(pointerOf("grid"), templates, "value-entry", {
slot: inner.slot.toHex(),
slot: Raw.toHex(inner.slot),
key: text.length,
});
expect(await readRegions(cell, state, templates, "value")).toEqual([
Expand Down
3 changes: 2 additions & 1 deletion packages/bugc/src/irgen/generate/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, it, expect } from "vitest";
import { keccak256 } from "ethereum-cryptography/keccak";
import { bytesToHex, hexToBytes } from "ethereum-cryptography/utils";

import { Raw } from "@ethdebug/common";
import { dereference } from "@ethdebug/pointers";
import { createMachineState } from "@ethdebug/evm";

Expand Down Expand Up @@ -136,7 +137,7 @@ describe("packed storage struct field pointers", () => {
});
const view = await cursor.view(state);
const read = async (name: string) =>
(await view.read(view.regions.lookup[name])).asUint();
Raw.asUint(await view.read(view.regions.lookup[name]));

expect(await read("a")).toBe(7n);
expect(await read("b")).toBe(1988n);
Expand Down
31 changes: 18 additions & 13 deletions packages/bugc/test/evm/locals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
type Trace,
type TraceStep,
} from "@ethdebug/evm";
import { dereference, type Machine } from "@ethdebug/pointers";
import { type Machine, Raw } from "@ethdebug/common";
import { dereference } from "@ethdebug/pointers";
import { bytesToHex } from "ethereum-cryptography/utils";
import type * as Format from "@ethdebug/format";

Expand Down Expand Up @@ -347,8 +348,8 @@ async function regionsAt(pointer: unknown, run: LocalsTrace, index: number) {
const data = await view.read(region);
if (region.location === "memory" || region.location === "calldata") {
const bytes = region.location === "memory" ? memory : calldata;
const start = region.offset!.asUint();
const length = region.length!.asUint();
const start = Raw.asUint(region.offset!);
const length = Raw.asUint(region.length!);
if (offset !== undefined && start !== offset) {
throw new Error(`${name} at ${start}, expected ${offset}`);
}
Expand All @@ -357,7 +358,7 @@ async function regionsAt(pointer: unknown, run: LocalsTrace, index: number) {
}
const actual = new Uint8Array(Number(length));
actual.set(bytes.slice(Number(start), Number(start + length)));
if (data.toHex() !== "0x" + bytesToHex(actual)) {
if (Raw.toHex(data) !== "0x" + bytesToHex(actual)) {
throw new Error(
`${name} does not read ${region.location} at ${start}`,
);
Expand All @@ -377,7 +378,7 @@ async function readScalar(
): Promise<string> {
const regions = await regionsAt(pointer, run, index);
regions.seek(name);
return (await regions.read(name)).toHex();
return Raw.toHex(await regions.read(name));
}

/**
Expand All @@ -400,9 +401,9 @@ async function readReference(

if (shape.kind === "calldata") {
regions.seek(`${name}-offset`);
const offset = (await regions.read(`${name}-offset`)).asUint();
const length = (await regions.read(`${name}-length`)).asUint();
return (await regions.read(`${name}-data`, offset, length)).toHex();
const offset = Raw.asUint(await regions.read(`${name}-offset`));
const length = Raw.asUint(await regions.read(`${name}-length`));
return Raw.toHex(await regions.read(`${name}-data`, offset, length));
}

regions.seek(name);
Expand All @@ -415,9 +416,9 @@ async function readReference(
): Promise<RefValue> => {
if (shape.kind === "scalar") {
const size = BigInt(shape.size);
return (await regions.read(prefix, word + 32n - size, size)).asUint();
return Raw.asUint(await regions.read(prefix, word + 32n - size, size));
}
const address = (await regions.read(prefix, word, 32n)).asUint();
const address = Raw.asUint(await regions.read(prefix, word, 32n));
return decode(shape, prefix, address);
};

Expand All @@ -435,9 +436,13 @@ async function readReference(
}
return value;
}
const length = (await regions.read(`${prefix}-length`, base, 32n)).asUint();
const length = Raw.asUint(
await regions.read(`${prefix}-length`, base, 32n),
);
if (shape.kind !== "array") {
return (await regions.read(`${prefix}-data`, base + 32n, length)).toHex();
return Raw.toHex(
await regions.read(`${prefix}-data`, base + 32n, length),
);
}
const values: RefValue[] = [];
for (let i = 0n; i < length; i++) {
Expand All @@ -447,6 +452,6 @@ async function readReference(
return values;
};

const base = (await regions.read(name)).asUint();
const base = Raw.asUint(await regions.read(name));
return decode(shape, name, base);
}
7 changes: 4 additions & 3 deletions packages/bugc/test/examples/runners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import type * as Evm from "#evm";
import * as Format from "@ethdebug/format";
import { Raw } from "@ethdebug/common";
import { dereference } from "@ethdebug/pointers";
import { bytesToHex } from "ethereum-cryptography/utils";

Expand Down Expand Up @@ -184,7 +185,7 @@ async function checkScalarValue(
}

const data = await view.read(view.regions[0]);
const actual = data.asUint();
const actual = Raw.asUint(data);
const expected = BigInt(expectedValue);

if (actual !== expected) {
Expand Down Expand Up @@ -275,7 +276,7 @@ async function checkRegionValues(

for (let i = 0; i < expectedValue.length; i++) {
const data = await view.read(regions[i]);
const actual = data.asUint();
const actual = Raw.asUint(data);
const expected = BigInt(expectedValue[i]);

if (actual !== expected) {
Expand All @@ -292,7 +293,7 @@ async function checkRegionValues(
} else {
// Check single region
const data = await view.read(regions[0]);
const actual = data.asUint();
const actual = Raw.asUint(data);
const expected = BigInt(expectedValue);

if (actual !== expected) {
Expand Down
1 change: 1 addition & 0 deletions packages/bugc/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
],
"references": [
{ "path": "../format/tsconfig.build.json" },
{ "path": "../common/tsconfig.build.json" },
{ "path": "../pointers/tsconfig.build.json" },
{ "path": "../evm/tsconfig.build.json" }
]
Expand Down
1 change: 1 addition & 0 deletions packages/bugc/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"exclude": ["node_modules", "dist"],
"references": [
{ "path": "../format" },
{ "path": "../common" },
{ "path": "../pointers" },
{ "path": "../evm" }
]
Expand Down
1 change: 1 addition & 0 deletions packages/bugc/tsconfig.typecheck.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"incremental": false,
"rootDir": "../..",
"paths": {
"@ethdebug/common": ["../common/src/index.ts"],
"@ethdebug/evm": ["../evm/src/index.ts"],
"@ethdebug/format": ["../format/src/index.ts"],
"@ethdebug/pointers": ["../pointers/src/index.ts"]
Expand Down
Loading
Loading