Skip to content

Commit 5784205

Browse files
committed
fix stack too deep
Signed-off-by: Ihor Farion <ihor@umaproject.org>
1 parent c10388e commit 5784205

File tree

2 files changed

+53
-39
lines changed

2 files changed

+53
-39
lines changed

contracts/periphery/mintburn/sponsored-oft/QuoteSignLib.sol

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,33 @@ library QuoteSignLib {
1111

1212
/// @notice Compute the keccak of all `SignedQuoteParams` fields
1313
function hash(SignedQuoteParams calldata p) internal pure returns (bytes32) {
14-
return
15-
keccak256(
16-
abi.encode(
17-
p.srcEid,
18-
p.dstEid,
19-
p.destinationHandler,
20-
p.amountLD,
21-
p.nonce,
22-
p.deadline,
23-
p.maxBpsToSponsor,
24-
p.finalRecipient,
25-
p.finalToken,
26-
p.destinationDex,
27-
p.lzReceiveGasLimit,
28-
p.lzComposeGasLimit,
29-
p.accountCreationMode,
30-
p.executionMode,
31-
keccak256(p.actionData) // Hash the actionData to keep signature size reasonable
32-
)
33-
);
14+
// We split the hashing into two parts to avoid "stack too deep" error
15+
bytes32 hash1 = keccak256(
16+
abi.encode(
17+
p.srcEid,
18+
p.dstEid,
19+
p.destinationHandler,
20+
p.amountLD,
21+
p.nonce,
22+
p.deadline,
23+
p.maxBpsToSponsor,
24+
p.finalRecipient
25+
)
26+
);
27+
28+
bytes32 hash2 = keccak256(
29+
abi.encode(
30+
p.finalToken,
31+
p.destinationDex,
32+
p.lzReceiveGasLimit,
33+
p.lzComposeGasLimit,
34+
p.accountCreationMode,
35+
p.executionMode,
36+
keccak256(p.actionData) // Hash the actionData to keep signature size reasonable
37+
)
38+
);
39+
40+
return keccak256(abi.encode(hash1, hash2));
3441
}
3542

3643
/// @notice Recover the signer for the given params and signature.

script/mintburn/oft/CreateSponsoredDeposit.s.sol

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,32 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s
1919
library DebugQuoteSignLib {
2020
/// @notice Compute the keccak of all `SignedQuoteParams` fields. Accept memory arg
2121
function hashMemory(SignedQuoteParams memory p) internal pure returns (bytes32) {
22-
return
23-
keccak256(
24-
abi.encode(
25-
p.srcEid,
26-
p.dstEid,
27-
p.destinationHandler,
28-
p.amountLD,
29-
p.nonce,
30-
p.deadline,
31-
p.maxBpsToSponsor,
32-
p.finalRecipient,
33-
p.finalToken,
34-
p.lzReceiveGasLimit,
35-
p.lzComposeGasLimit,
36-
p.accountCreationMode,
37-
p.executionMode,
38-
keccak256(p.actionData) // Hash the actionData to keep signature size reasonable
39-
)
40-
);
22+
bytes32 hash1 = keccak256(
23+
abi.encode(
24+
p.srcEid,
25+
p.dstEid,
26+
p.destinationHandler,
27+
p.amountLD,
28+
p.nonce,
29+
p.deadline,
30+
p.maxBpsToSponsor,
31+
p.finalRecipient
32+
)
33+
);
34+
35+
bytes32 hash2 = keccak256(
36+
abi.encode(
37+
p.finalToken,
38+
p.destinationDex,
39+
p.lzReceiveGasLimit,
40+
p.lzComposeGasLimit,
41+
p.accountCreationMode,
42+
p.executionMode,
43+
keccak256(p.actionData) // Hash the actionData to keep signature size reasonable
44+
)
45+
);
46+
47+
return keccak256(abi.encode(hash1, hash2));
4148
}
4249

4350
/// @notice Sign the quote using Foundry's Vm cheatcode and return concatenated bytes signature (r,s,v).

0 commit comments

Comments
 (0)