Skip to content

Commit c1ec904

Browse files
committed
Remove ethdebug/format/pointer/templates
... and just define ethdebug/format/pointer/template instead
1 parent c36e018 commit c1ec904

File tree

9 files changed

+132
-185
lines changed

9 files changed

+132
-185
lines changed

packages/pointers/src/pointer.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ describe("type guards", () => {
178178
},
179179
{
180180
schema: {
181-
id: "schema:ethdebug/format/pointer/templates"
181+
id: "schema:ethdebug/format/pointer/template"
182182
},
183-
guard: Pointer.isTemplates
183+
guard: Pointer.isTemplate
184184
},
185185
] as const;
186186

packages/pointers/src/test-cases.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
singleSourceCompilation,
33
findExamplePointer,
4-
findExampleTemplates,
54
type ObserveTraceOptions
65
} from "../test/index.js";
76
import { type Cursor, Data } from "./index.js";
@@ -81,8 +80,7 @@ const structStorageTest: ObserveTraceTest<{
8180
};
8281

8382
const stringStorageTest: ObserveTraceTest<string> = {
84-
pointer: findExamplePointer("solidity-string-storage"),
85-
templates: findExampleTemplates(),
83+
pointer: findExamplePointer("string-storage-contract-variable-slot"),
8684

8785
compileOptions: singleSourceCompilation({
8886
path: "StringStorage.sol",

packages/pointers/test/examples.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,3 @@ export const findExamplePointer = (() => {
1616
examplePointers
1717
.find(pointer => JSON.stringify(pointer).includes(text))!;
1818
})();
19-
20-
export const findExampleTemplates = (() => {
21-
const {
22-
schema: {
23-
examples: [exampleTemplates]
24-
}
25-
} = describeSchema({
26-
schema: { id: "schema:ethdebug/format/pointer/templates" }
27-
}) as { schema: { examples: Pointer.Templates[] } };
28-
29-
return (): Pointer.Templates => exampleTemplates;
30-
})();

packages/pointers/test/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export {
1111

1212
export { deployContract, } from "./deploy.js";
1313

14-
export { findExamplePointer, findExampleTemplates } from "./examples.js";
14+
export { findExamplePointer } from "./examples.js";
1515

1616
export {
1717
observeTrace,

packages/web/spec/pointer/templates.mdx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,13 @@ import SchemaViewer from "@site/src/components/SchemaViewer";
66

77
# Pointer templates
88

9-
This format provides the concept of **pointer templates** to allow
9+
This format provides the concept of a **pointer template** to allow
1010
deduplicating representations. Pointer templates are defined to specify the
1111
variables they expect in scope and the pointer definition that uses those
1212
variables.
1313

14-
## Template schema {#template-schema}
15-
16-
The following schema defines how to represent a single pointer template.
17-
See [below](#templates-schema) for how to organize pointer templates by name.
18-
1914
<SchemaViewer
2015
schema={{
21-
id: "schema:ethdebug/format/pointer/templates"
16+
id: "schema:ethdebug/format/pointer/template"
2217
}}
23-
pointer="#/$defs/Template"
24-
/>
25-
26-
## Organizing templates {#templates-schema}
27-
28-
The **ethdebug/format/pointer/templates** schema specifies how to represent
29-
a collection of pointer templates by name.
30-
31-
<SchemaViewer
32-
schema={{ id: "schema:ethdebug/format/pointer/templates" }}
3318
/>

packages/web/src/schemas.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,8 @@ export const schemaIndex: SchemaIndex = {
116116
href: "/spec/pointer/expression"
117117
},
118118

119-
"schema:ethdebug/format/pointer/templates": {
120-
href: "/spec/pointer/templates"
121-
},
122-
123-
"schema:ethdebug/format/pointer/templates#/$defs/Template": {
124-
title: "Pointer template schema",
125-
href: "/spec/pointer/templates#template-schema"
119+
"schema:ethdebug/format/pointer/template": {
120+
href: "/spec/pointer/template"
126121
},
127122

128123
...Object.entries({

schemas/pointer.schema.yaml

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,94 @@ examples:
153153

154154
- # example template reference
155155
define:
156-
"contract-variable-slot": 0
156+
"string-storage-contract-variable-slot": 0
157157
in:
158-
template: "solidity-string-storage"
158+
group:
159+
# for short strings, the length is stored as 2n in the last byte of slot
160+
- name: "length-flag"
161+
location: storage
162+
slot: "string-storage-contract-variable-slot"
163+
offset:
164+
$difference: [$wordsize, 1]
165+
length: 1
166+
167+
# define the region representing the string data itself conditionally
168+
# based on odd or even length data
169+
- if:
170+
$remainder:
171+
- $sum:
172+
- $read: "length-flag"
173+
- 1
174+
- 2
175+
176+
# short string case (flag is even)
177+
then:
178+
define:
179+
"string-length":
180+
$quotient: [{ $read: "length-flag" }, 2]
181+
in:
182+
name: "string"
183+
location: storage
184+
slot: "string-storage-contract-variable-slot"
185+
offset: 0
186+
length: "string-length"
187+
188+
# long string case (flag is odd)
189+
else:
190+
group:
191+
# long strings may use full word to describe length as 2n+1
192+
- name: "long-string-length-data"
193+
location: storage
194+
slot: "string-storage-contract-variable-slot"
195+
offset: 0
196+
length: $wordsize
197+
198+
- define:
199+
"string-length":
200+
$quotient:
201+
- $difference:
202+
- $read: "long-string-length-data"
203+
- 1
204+
- 2
205+
206+
"start-slot":
207+
$keccak256:
208+
- $wordsized: "string-storage-contract-variable-slot"
209+
210+
"total-slots":
211+
# account for both zero and nonzero slot remainders by adding
212+
# $wordsize-1 to the length before dividing
213+
$quotient:
214+
- $sum: ["string-length", { $difference: [$wordsize, 1] }]
215+
- $wordsize
216+
in:
217+
list:
218+
count: "total-slots"
219+
each: "i"
220+
is:
221+
define:
222+
"current-slot":
223+
$sum: ["start-slot", "i"]
224+
"previous-length":
225+
$product: ["i", $wordsize]
226+
in:
227+
# conditional based on whether this is the last slot:
228+
# is the string length longer than the previous length
229+
# plus this whole slot?
230+
if:
231+
$difference:
232+
- "string-length"
233+
- $sum: ["previous-length", "$wordsize"]
234+
then:
235+
# include the whole slot
236+
name: "string"
237+
location: storage
238+
slot: "current-slot"
239+
else:
240+
# include only what's left in the string
241+
name: "string"
242+
location: storage
243+
slot: "current-slot"
244+
offset: 0
245+
length:
246+
$difference: ["string-length", "previous-length"]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
$schema: "https://json-schema.org/draft/2020-12/schema"
2+
$id: "schema:ethdebug/format/pointer/template"
3+
4+
title: ethdebug/format/pointer/template
5+
description: |
6+
A schema for representing a pointer defined in terms of some variables whose
7+
values are to be provided when invoking the template.
8+
9+
type: object
10+
properties:
11+
expect:
12+
title: Template variables
13+
description: |
14+
An array of variable identifiers used in the definition of the
15+
pointer template.
16+
type: array
17+
items:
18+
$ref: "schema:ethdebug/format/pointer/identifier"
19+
additionalItems: false
20+
21+
for:
22+
$ref: "schema:ethdebug/format/pointer"
23+
24+
required:
25+
- expect
26+
- for
27+
28+
additionalProperties: false
29+
30+
examples:
31+
- expect: ["slot"]
32+
for:
33+
location: storage
34+
slot: "slot"

schemas/pointer/templates.schema.yaml

Lines changed: 0 additions & 141 deletions
This file was deleted.

0 commit comments

Comments
 (0)