-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
W3: Unnecessary computation of calldataHash value in validateRecovery…
…Subject function
- Loading branch information
1 parent
c9028df
commit f80edd7
Showing
8 changed files
with
167 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
test/unit/handlers/EmailRecoverySubjectHandler/parseRecoveryCalldataHash.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.25; | ||
|
||
import { console2 } from "forge-std/console2.sol"; | ||
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; | ||
import { UnitBase } from "../../UnitBase.t.sol"; | ||
import { EmailRecoverySubjectHandler } from "src/handlers/EmailRecoverySubjectHandler.sol"; | ||
|
||
contract EmailRecoverySubjectHandler_parseRecoveryCalldataHash_Test is UnitBase { | ||
using Strings for uint256; | ||
|
||
string calldataHashString; | ||
bytes[] subjectParams; | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
|
||
calldataHashString = uint256(calldataHash).toHexString(32); | ||
|
||
subjectParams = new bytes[](3); | ||
subjectParams[0] = abi.encode(accountAddress); | ||
subjectParams[1] = abi.encode(recoveryModuleAddress); | ||
subjectParams[2] = abi.encode(calldataHashString); | ||
} | ||
|
||
function test_ParseRecoveryCalldataHash_RevertWhen_InvalidTemplateIndex() public { | ||
uint256 invalidTemplateIdx = 1; | ||
vm.expectRevert(EmailRecoverySubjectHandler.InvalidTemplateIndex.selector); | ||
emailRecoveryHandler.parseRecoveryCalldataHash(invalidTemplateIdx, subjectParams); | ||
} | ||
|
||
function test_ParseRecoveryCalldataHash_Succeeds() public { | ||
bytes32 expectedCalldataHash = keccak256(recoveryCalldata); | ||
|
||
bytes32 calldataHash = | ||
emailRecoveryHandler.parseRecoveryCalldataHash(templateIdx, subjectParams); | ||
|
||
assertEq(calldataHash, expectedCalldataHash); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
test/unit/handlers/SafeRecoverySubjectHandler/parseRecoveryCalldataHash.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.25; | ||
|
||
import { console2 } from "forge-std/console2.sol"; | ||
import { SafeUnitBase } from "../../SafeUnitBase.t.sol"; | ||
import { SafeRecoverySubjectHandler } from "src/handlers/SafeRecoverySubjectHandler.sol"; | ||
|
||
contract SafeRecoverySubjectHandler_parseRecoveryCalldataHash_Test is SafeUnitBase { | ||
bytes[] subjectParams; | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
|
||
subjectParams = new bytes[](4); | ||
subjectParams[0] = abi.encode(accountAddress1); | ||
subjectParams[1] = abi.encode(owner1); | ||
subjectParams[2] = abi.encode(newOwner1); | ||
subjectParams[3] = abi.encode(recoveryModuleAddress); | ||
} | ||
|
||
function test_ParseRecoveryCalldataHash_RevertWhen_InvalidTemplateIndex() public { | ||
skipIfNotSafeAccountType(); | ||
|
||
uint256 invalidTemplateIdx = 1; | ||
vm.expectRevert(SafeRecoverySubjectHandler.InvalidTemplateIndex.selector); | ||
safeRecoverySubjectHandler.parseRecoveryCalldataHash(invalidTemplateIdx, subjectParams); | ||
} | ||
|
||
function test_ParseRecoveryCalldataHash_Succeeds() public { | ||
skipIfNotSafeAccountType(); | ||
bytes32 expectedCalldataHash = keccak256(recoveryCalldata); | ||
|
||
bytes32 calldataHash = | ||
safeRecoverySubjectHandler.parseRecoveryCalldataHash(templateIdx, subjectParams); | ||
|
||
assertEq(calldataHash, expectedCalldataHash); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters