Skip to content

Commit e63b15d

Browse files
committed
Move length into header byte
1 parent 1a475e2 commit e63b15d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/lib/V2DutchOrderLib.sol

+2-3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ library CosignerExtraDataLib {
8585
bytes32 constant EXCL_FILLER_FLAG_MASK = 0x8000000000000000000000000000000000000000000000000000000000000000;
8686
bytes32 constant INPUT_OVERRIDE_FLAG_MASK = 0x4000000000000000000000000000000000000000000000000000000000000000;
8787
bytes32 constant OUTPUT_OVERRIDE_FLAG_MASK = 0x2000000000000000000000000000000000000000000000000000000000000000;
88+
bytes32 constant OUTPUTS_LENGTH_FLAG_MASK = 0x1F00000000000000000000000000000000000000000000000000000000000000;
8889

8990
// "True" first bit of byte 1 signals that there is an exclusive filler
9091
function hasExclusiveFiller(bytes memory extraData) internal pure returns (bool flag) {
@@ -141,12 +142,10 @@ library CosignerExtraDataLib {
141142
}
142143

143144
if (hasOutputOverrides(extraData)) {
144-
require(extraData.length >= bytesOffset + 32);
145145
uint256 length;
146146
assembly {
147-
length := mload(add(extraData, bytesOffset))
147+
length := shr(248, and(mload(add(extraData, 32)), OUTPUTS_LENGTH_FLAG_MASK))
148148
}
149-
bytesOffset += 32;
150149

151150
// each element of the array is 32 bytes, - 32 bytes for the length offset
152151
require(extraData.length == bytesOffset + (length - 1) * 32);

test/reactors/V2DutchOrderReactor.t.sol

+5-4
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,16 @@ contract V2DutchOrderTest is PermitSignature, DeployPermit2, BaseDutchOrderReact
322322
if (hasExclusiveFiller) firstByte |= 0x80;
323323
if (hasInputOverride) firstByte |= 0x40;
324324
if (hasOutputOverrides) firstByte |= 0x20;
325+
if (hasOutputOverrides) {
326+
require(outputOverrides.length < 32);
327+
firstByte |= bytes1(uint8(outputOverrides.length));
328+
}
325329

326330
if (firstByte == 0x00) return "";
327331

328332
extraData = abi.encodePacked(firstByte);
329333
if (hasExclusiveFiller) extraData = bytes.concat(extraData, abi.encodePacked(exclusiveFiller));
330334
if (hasInputOverride) extraData = bytes.concat(extraData, abi.encodePacked(inputOverride));
331-
if (hasOutputOverrides) {
332-
extraData = bytes.concat(extraData, abi.encodePacked(outputOverrides.length));
333-
extraData = bytes.concat(extraData, abi.encodePacked(outputOverrides));
334-
}
335+
if (hasOutputOverrides) extraData = bytes.concat(extraData, abi.encodePacked(outputOverrides));
335336
}
336337
}

0 commit comments

Comments
 (0)