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
84 changes: 42 additions & 42 deletions apps/order-book/contracts/src/OrderBook.sol.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ declare const entrypoint: import("typewriter").TypewriterSolidityEntrypoint<{
readonly type: "t_uint256";
},
{
readonly astId: 43903;
readonly astId: 43935;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "state";
readonly offset: 0;
readonly slot: "3";
readonly type: "t_struct(State)43420_storage";
readonly type: "t_struct(State)43452_storage";
},
];
readonly types: {
Expand All @@ -48,11 +48,11 @@ declare const entrypoint: import("typewriter").TypewriterSolidityEntrypoint<{
readonly numberOfBytes: "32";
readonly base: "t_struct(Credential)15_storage";
};
readonly "t_array(t_struct(Order)43440_storage)dyn_storage": {
readonly "t_array(t_struct(Order)43472_storage)dyn_storage": {
readonly encoding: "dynamic_array";
readonly label: "struct Order[]";
readonly numberOfBytes: "32";
readonly base: "t_struct(Order)43440_storage";
readonly base: "t_struct(Order)43472_storage";
};
readonly "t_array(t_struct(QueuedMutation)657_storage)dyn_storage": {
readonly encoding: "dynamic_array";
Expand Down Expand Up @@ -89,12 +89,12 @@ declare const entrypoint: import("typewriter").TypewriterSolidityEntrypoint<{
readonly numberOfBytes: "32";
readonly value: "t_struct(Account)26_storage";
};
readonly "t_mapping(t_bytes32,t_struct(Account)43429_storage)": {
readonly "t_mapping(t_bytes32,t_struct(Account)43461_storage)": {
readonly encoding: "mapping";
readonly key: "t_bytes32";
readonly label: "mapping(bytes32 => struct Account)";
readonly numberOfBytes: "32";
readonly value: "t_struct(Account)43429_storage";
readonly value: "t_struct(Account)43461_storage";
};
readonly "t_mapping(t_uint192,t_uint64)": {
readonly encoding: "mapping";
Expand All @@ -103,19 +103,19 @@ declare const entrypoint: import("typewriter").TypewriterSolidityEntrypoint<{
readonly numberOfBytes: "32";
readonly value: "t_uint64";
};
readonly "t_mapping(t_uint64,t_struct(Instrument)43463_storage)": {
readonly "t_mapping(t_uint64,t_struct(Instrument)43495_storage)": {
readonly encoding: "mapping";
readonly key: "t_uint64";
readonly label: "mapping(uint64 => struct Instrument)";
readonly numberOfBytes: "32";
readonly value: "t_struct(Instrument)43463_storage";
readonly value: "t_struct(Instrument)43495_storage";
};
readonly "t_mapping(t_uint64,t_struct(Tick)43474_storage)": {
readonly "t_mapping(t_uint64,t_struct(Tick)43506_storage)": {
readonly encoding: "mapping";
readonly key: "t_uint64";
readonly label: "mapping(uint64 => struct Tick)";
readonly numberOfBytes: "32";
readonly value: "t_struct(Tick)43474_storage";
readonly value: "t_struct(Tick)43506_storage";
};
readonly "t_struct(Account)26_storage": {
readonly encoding: "inplace";
Expand Down Expand Up @@ -148,26 +148,26 @@ declare const entrypoint: import("typewriter").TypewriterSolidityEntrypoint<{
},
];
};
readonly "t_struct(Account)43429_storage": {
readonly "t_struct(Account)43461_storage": {
readonly encoding: "inplace";
readonly label: "struct Account";
readonly numberOfBytes: "64";
readonly members: readonly [
{
readonly astId: 43424;
readonly astId: 43456;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "balances";
readonly offset: 0;
readonly slot: "0";
readonly type: "t_mapping(t_address,t_uint256)";
},
{
readonly astId: 43428;
readonly astId: 43460;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "orders";
readonly offset: 0;
readonly slot: "1";
readonly type: "t_array(t_struct(Order)43440_storage)dyn_storage";
readonly type: "t_array(t_struct(Order)43472_storage)dyn_storage";
},
];
};
Expand Down Expand Up @@ -210,116 +210,116 @@ declare const entrypoint: import("typewriter").TypewriterSolidityEntrypoint<{
},
];
};
readonly "t_struct(Instrument)43463_storage": {
readonly "t_struct(Instrument)43495_storage": {
readonly encoding: "inplace";
readonly label: "struct Instrument";
readonly numberOfBytes: "160";
readonly members: readonly [
{
readonly astId: 43442;
readonly astId: 43474;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "base";
readonly offset: 0;
readonly slot: "0";
readonly type: "t_address";
},
{
readonly astId: 43444;
readonly astId: 43476;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "quote";
readonly offset: 0;
readonly slot: "1";
readonly type: "t_address";
},
{
readonly astId: 43446;
readonly astId: 43478;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "baseLotExp";
readonly offset: 20;
readonly slot: "1";
readonly type: "t_uint8";
},
{
readonly astId: 43448;
readonly astId: 43480;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "quoteLotExp";
readonly offset: 21;
readonly slot: "1";
readonly type: "t_uint8";
},
{
readonly astId: 43450;
readonly astId: 43482;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "bestBid";
readonly offset: 22;
readonly slot: "1";
readonly type: "t_uint64";
},
{
readonly astId: 43452;
readonly astId: 43484;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "bestAsk";
readonly offset: 0;
readonly slot: "2";
readonly type: "t_uint64";
},
{
readonly astId: 43457;
readonly astId: 43489;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "bids";
readonly offset: 0;
readonly slot: "3";
readonly type: "t_mapping(t_uint64,t_struct(Tick)43474_storage)";
readonly type: "t_mapping(t_uint64,t_struct(Tick)43506_storage)";
},
{
readonly astId: 43462;
readonly astId: 43494;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "asks";
readonly offset: 0;
readonly slot: "4";
readonly type: "t_mapping(t_uint64,t_struct(Tick)43474_storage)";
readonly type: "t_mapping(t_uint64,t_struct(Tick)43506_storage)";
},
];
};
readonly "t_struct(Order)43440_storage": {
readonly "t_struct(Order)43472_storage": {
readonly encoding: "inplace";
readonly label: "struct Order";
readonly numberOfBytes: "32";
readonly members: readonly [
{
readonly astId: 43431;
readonly astId: 43463;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "quantity";
readonly offset: 0;
readonly slot: "0";
readonly type: "t_uint64";
},
{
readonly astId: 43433;
readonly astId: 43465;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "instrumentId";
readonly offset: 8;
readonly slot: "0";
readonly type: "t_uint64";
},
{
readonly astId: 43435;
readonly astId: 43467;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "price";
readonly offset: 16;
readonly slot: "0";
readonly type: "t_uint64";
},
{
readonly astId: 43437;
readonly astId: 43469;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "tickVolume";
readonly offset: 24;
readonly slot: "0";
readonly type: "t_uint32";
},
{
readonly astId: 43439;
readonly astId: 43471;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "side";
readonly offset: 28;
Expand Down Expand Up @@ -367,68 +367,68 @@ declare const entrypoint: import("typewriter").TypewriterSolidityEntrypoint<{
},
];
};
readonly "t_struct(State)43420_storage": {
readonly "t_struct(State)43452_storage": {
readonly encoding: "inplace";
readonly label: "struct State";
readonly numberOfBytes: "64";
readonly members: readonly [
{
readonly astId: 43414;
readonly astId: 43446;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "accounts";
readonly offset: 0;
readonly slot: "0";
readonly type: "t_mapping(t_bytes32,t_struct(Account)43429_storage)";
readonly type: "t_mapping(t_bytes32,t_struct(Account)43461_storage)";
},
{
readonly astId: 43419;
readonly astId: 43451;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "instruments";
readonly offset: 0;
readonly slot: "1";
readonly type: "t_mapping(t_uint64,t_struct(Instrument)43463_storage)";
readonly type: "t_mapping(t_uint64,t_struct(Instrument)43495_storage)";
},
];
};
readonly "t_struct(Tick)43474_storage": {
readonly "t_struct(Tick)43506_storage": {
readonly encoding: "inplace";
readonly label: "struct Tick";
readonly numberOfBytes: "64";
readonly members: readonly [
{
readonly astId: 43465;
readonly astId: 43497;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "quantity";
readonly offset: 0;
readonly slot: "0";
readonly type: "t_uint64";
},
{
readonly astId: 43467;
readonly astId: 43499;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "remainingQuantity";
readonly offset: 8;
readonly slot: "0";
readonly type: "t_uint64";
},
{
readonly astId: 43469;
readonly astId: 43501;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "volume";
readonly offset: 16;
readonly slot: "0";
readonly type: "t_uint32";
},
{
readonly astId: 43471;
readonly astId: 43503;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "prev";
readonly offset: 20;
readonly slot: "0";
readonly type: "t_uint64";
},
{
readonly astId: 43473;
readonly astId: 43505;
readonly contract: "src/OrderBook.sol:OrderBook";
readonly label: "next";
readonly offset: 0;
Expand Down
10 changes: 5 additions & 5 deletions apps/token/contracts/src/Token.sol.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ declare const entrypoint: import("typewriter").TypewriterSolidityEntrypoint<{
readonly type: "t_uint256";
},
{
readonly astId: 42145;
readonly astId: 42177;
readonly contract: "src/Token.sol:Token";
readonly label: "state";
readonly offset: 0;
readonly slot: "3";
readonly type: "t_struct(State)42134_storage";
readonly type: "t_struct(State)42166_storage";
},
];
readonly types: {
Expand Down Expand Up @@ -194,21 +194,21 @@ declare const entrypoint: import("typewriter").TypewriterSolidityEntrypoint<{
},
];
};
readonly "t_struct(State)42134_storage": {
readonly "t_struct(State)42166_storage": {
readonly encoding: "inplace";
readonly label: "struct State";
readonly numberOfBytes: "64";
readonly members: readonly [
{
readonly astId: 42129;
readonly astId: 42161;
readonly contract: "src/Token.sol:Token";
readonly label: "totalSupply";
readonly offset: 0;
readonly slot: "0";
readonly type: "t_uint256";
},
{
readonly astId: 42133;
readonly astId: 42165;
readonly contract: "src/Token.sol:Token";
readonly label: "balances";
readonly offset: 0;
Expand Down
16 changes: 16 additions & 0 deletions packages/typewriter/src/Typewriter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ abstract contract Typewriter {
revert LengthMismatch();
}
for (uint256 i; i < batch.mutations.length; i++) {
uint256 freeMemoryPointer = _getFreeMemoryPointer();
_execute(batch.mutations[i], batch.mutationData[i], batch.authorizationData[i]);
_setFreeMemoryPointer(freeMemoryPointer);
Comment on lines +197 to +199

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Memory reuse lacks regression coverage

The new memory-pointer reset has no focused regression test. The Solidity tests execute one mutation at a time, and the benchmark now uses a smaller batch without asserting memory use. Removing the reset could therefore leave these checks passing.

Add a test that checks memory stays bounded across repeated mutations, including queued mutations and different argument sizes.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/typewriter/src/Typewriter.sol
Line: 197-199

Comment:
**Memory reuse lacks regression coverage**

The new memory-pointer reset has no focused regression test. The Solidity tests execute one mutation at a time, and the benchmark now uses a smaller batch without asserting memory use. Removing the reset could therefore leave these checks passing.

Add a test that checks memory stays bounded across repeated mutations, including queued mutations and different argument sizes.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

executionIndex++;
}
}
Expand All @@ -205,13 +207,27 @@ abstract contract Typewriter {

if (queued.enqueuedBlock == 0) revert ForceInclusionAlreadyExecuted(index);

uint256 freeMemoryPointer = _getFreeMemoryPointer();
_execute(queued.mutation, queued.mutationData, queued.authorizationData);
_setFreeMemoryPointer(freeMemoryPointer);
executionIndex++;

delete queue[index];
}
}

function _getFreeMemoryPointer() private pure returns (uint256 pointer) {
assembly ("memory-safe") {
pointer := mload(0x40)
}
}

function _setFreeMemoryPointer(uint256 pointer) private pure {
assembly ("memory-safe") {
mstore(0x40, pointer)
}
}

function enqueue(uint8 mutation, bytes calldata mutationData, bytes calldata authorizationData)
external
returns (uint256)
Expand Down
Loading
Loading