Skip to content

Commit eb0fccb

Browse files
committed
consolidations: return request type byte at start of output
1 parent 2d37a31 commit eb0fccb

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/consolidations/main.eas

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#define INPUT_SIZE 96 ;; the size of (source ++ target)
3030
#define RECORD_SIZE 116 ;; the size of (address ++ source ++ target)
3131

32+
#define REQUEST_TYPE 0x02
33+
3234
;; -----------------------------------------------------------------------------
3335
;; PROGRAM START ---------------------------------------------------------------
3436
;; -----------------------------------------------------------------------------
@@ -213,7 +215,13 @@ read_requests:
213215
push MAX_PER_BLOCK ;; [count, head_idx, tail_idx]
214216

215217
begin_loop:
216-
push0 ;; [i, count, head_idx, tail_idx]
218+
;; Store request type prefix into the output buffer.
219+
push1 REQUEST_TYPE ;; [type, count, head_idx, tail_idx]
220+
push 0 ;; [offset, type, count, head_idx, tail_idx]
221+
mstore8 ;; [count, head_idx, tail_idx]
222+
223+
;; Push initial loop index.
224+
push 0 ;; [i, count, head_idx, tail_idx]
217225

218226
accum_loop:
219227
;; This loop will read each request and byte bang it into a RECORD_SIZE byte chunk.
@@ -227,7 +235,9 @@ accum_loop:
227235
;; Precompute record_offset = i*RECORD_SIZE.
228236
dup1 ;; [i, i, count, head_idx, tail_idx]
229237
push RECORD_SIZE ;; [size, i, i, count, head_idx, tail_idx]
230-
mul ;; [record_offset, i, count, head_idx, tail_idx]
238+
mul ;; [offset, i, count, head_idx, tail_idx]
239+
push 1 ;; [1, offset, i, count, head_idx, tail_idx]
240+
add ;; [record_offset, i, count, head_idx, tail_idx]
231241

232242
;; Determine the storage slot of the address for this iteration. This value is
233243
;; also the base for the other storage slots containing the source and the target
@@ -389,7 +399,9 @@ store_excess:
389399

390400
;; Return the requests.
391401
push RECORD_SIZE ;; [record_size, count]
392-
mul ;; [size]
402+
mul ;; [size, count]
403+
push 1 ;; [1, size, count]
404+
add ;; [size+1, count]
393405
push0 ;; [0, size]
394406
return ;; []
395407

test/Consolidation.t.sol.in

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ contract ConsolidationTest is Test {
4949
assertExcess(0);
5050

5151
bytes memory req = getRequests();
52-
assertEq(req.length, 116);
53-
assertEq(toFixed(req, 20, 52), toFixed(data, 0, 32));
54-
assertEq(toFixed(req, 52, 84), toFixed(data, 32, 64));
55-
assertEq(toFixed(req, 84, 116), toFixed(data, 64, 96));
56-
assertStorage(count_slot, 0, "unexpected request count");
52+
assertEq(req.length, 117);
53+
assertEq(uint8(req[0]), 0x02);
54+
assertEq(slice(req, 21, 117), data, "wrong output request data");
55+
assertStorage(count_slot, 0, "unexpected request count in storage");
5756
assertExcess(0);
5857
}
5958

@@ -192,9 +191,9 @@ contract ConsolidationTest is Test {
192191
// uint8(index), repeating.
193192
function checkConsolidations(uint256 startIndex, uint256 count) internal returns (uint256) {
194193
bytes memory requests = getRequests();
195-
assertEq(requests.length, count*116);
194+
assertEq(requests.length, count*116 + 1);
196195
for (uint256 i = 0; i < count; i++) {
197-
uint256 offset = i*116;
196+
uint256 offset = i*116 + 1;
198197
assertEq(toFixed(requests, offset, offset+20) >> 96, uint256(startIndex+i), "unexpected request address returned");
199198
assertEq(toFixed(requests, offset+20, offset+52), toFixed(makeConsolidation(startIndex+i), 0, 32), "unexpected source[0:32] returned");
200199
assertEq(toFixed(requests, offset+52, offset+84), toFixed(makeConsolidation(startIndex+i), 32, 64), "unexpected source[32:48] ++ target[0:16] returned");

0 commit comments

Comments
 (0)