Skip to content

Commit 5ee569a

Browse files
authored
Optimise output hash (openintentsframework#32)
1 parent 1744632 commit 5ee569a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/input/types/MandateOutputType.sol

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ library MandateOutputType {
5555
) internal pure returns (bytes32) {
5656
unchecked {
5757
bytes memory currentHash = new bytes(32 * outputs.length);
58-
58+
uint256 p;
59+
assembly ("memory-safe") {
60+
p := add(currentHash, 0x20)
61+
}
5962
for (uint256 i = 0; i < outputs.length; ++i) {
6063
bytes32 outputHash = hashOutput(outputs[i]);
6164
assembly ("memory-safe") {
62-
mstore(add(add(currentHash, 0x20), mul(i, 0x20)), outputHash)
65+
mstore(add(p, mul(i, 0x20)), outputHash)
6366
}
6467
}
6568
return keccak256(currentHash);
@@ -90,11 +93,14 @@ library MandateOutputType {
9093
) internal pure returns (bytes32) {
9194
unchecked {
9295
bytes memory currentHash = new bytes(32 * outputs.length);
93-
96+
uint256 p;
97+
assembly ("memory-safe") {
98+
p := add(currentHash, 0x20)
99+
}
94100
for (uint256 i = 0; i < outputs.length; ++i) {
95101
bytes32 outputHash = hashOutputM(outputs[i]);
96102
assembly ("memory-safe") {
97-
mstore(add(add(currentHash, 0x20), mul(i, 0x20)), outputHash)
103+
mstore(add(p, mul(i, 0x20)), outputHash)
98104
}
99105
}
100106
return keccak256(currentHash);

0 commit comments

Comments
 (0)