-
-
Notifications
You must be signed in to change notification settings - Fork 102
Add Exact Execution Single & Batch Enforcer #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
795cbb8
feat: add exact calldata batch enforcer
McOso 12cb05b
feat: add exact execution batch enforcer
McOso 8278a77
chore: add exec batch to deploys
McOso a6f45bf
feat: add single execution exact match enforcer
McOso d9546da
fix: simplify exec batch logic check
McOso 62fde59
Missing deployment script
hanzel98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,64 @@ | ||
| // SPDX-License-Identifier: MIT AND Apache-2.0 | ||
| pragma solidity 0.8.23; | ||
|
|
||
| import { ExecutionLib } from "@erc7579/lib/ExecutionLib.sol"; | ||
| import { ModeLib } from "@erc7579/lib/ModeLib.sol"; | ||
|
|
||
| import { CaveatEnforcer } from "./CaveatEnforcer.sol"; | ||
| import { ModeCode, Execution } from "../utils/Types.sol"; | ||
|
|
||
| /** | ||
| * @title ExactCalldataBatchEnforcer | ||
| * @notice Ensures that the provided batch execution calldata matches exactly the expected calldata for each execution. | ||
| * @dev This caveat enforcer operates only in batch execution mode. | ||
| */ | ||
| contract ExactCalldataBatchEnforcer is CaveatEnforcer { | ||
| using ExecutionLib for bytes; | ||
| using ModeLib for ModeCode; | ||
|
|
||
| ////////////////////////////// Public Methods ////////////////////////////// | ||
|
|
||
| /** | ||
| * @notice Validates that each execution's calldata in the batch matches the expected calldata. | ||
| * @param _terms The encoded expected Executions. | ||
| * @param _mode The execution mode, which must be batch. | ||
| * @param _executionCallData The batch execution calldata. | ||
| */ | ||
| function beforeHook( | ||
| bytes calldata _terms, | ||
| bytes calldata, | ||
| ModeCode _mode, | ||
| bytes calldata _executionCallData, | ||
| bytes32, | ||
| address, | ||
| address | ||
| ) | ||
| public | ||
| pure | ||
| override | ||
| onlyBatchExecutionMode(_mode) | ||
| { | ||
| Execution[] calldata executions_ = _executionCallData.decodeBatch(); | ||
| Execution[] memory termsExecutions_ = getTermsInfo(_terms); | ||
|
|
||
| // Validate that the number of executions matches the number of expected calldata | ||
| require(executions_.length == termsExecutions_.length, "ExactCalldataBatchEnforcer:invalid-batch-size"); | ||
|
|
||
| // Check each execution's calldata matches exactly | ||
| for (uint256 i = 0; i < executions_.length; i++) { | ||
| require( | ||
| keccak256(termsExecutions_[i].callData) == keccak256(executions_[i].callData), | ||
| "ExactCalldataBatchEnforcer:invalid-calldata" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @notice Extracts the expected executions from the provided terms. | ||
| * @param _terms The encoded expected Executions. | ||
| * @return executions_ Array of expected Executions. | ||
| */ | ||
| function getTermsInfo(bytes calldata _terms) public pure returns (Execution[] memory executions_) { | ||
| executions_ = _terms.decodeBatch(); | ||
| } | ||
| } | ||
This file contains hidden or 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,62 @@ | ||
| // SPDX-License-Identifier: MIT AND Apache-2.0 | ||
| pragma solidity 0.8.23; | ||
|
|
||
| import { ExecutionLib } from "@erc7579/lib/ExecutionLib.sol"; | ||
| import { ModeLib } from "@erc7579/lib/ModeLib.sol"; | ||
|
|
||
| import { CaveatEnforcer } from "./CaveatEnforcer.sol"; | ||
| import { ModeCode, Execution } from "../utils/Types.sol"; | ||
|
|
||
| /** | ||
| * @title ExactExecutionBatchEnforcer | ||
| * @notice Ensures that each execution in the batch matches exactly with the expected execution (target, value, and calldata). | ||
| * @dev This caveat enforcer operates only in batch execution mode. | ||
| */ | ||
| contract ExactExecutionBatchEnforcer is CaveatEnforcer { | ||
| using ExecutionLib for bytes; | ||
| using ModeLib for ModeCode; | ||
|
|
||
| ////////////////////////////// Public Methods ////////////////////////////// | ||
|
|
||
| /** | ||
| * @notice Validates that each execution in the batch matches exactly with the expected execution. | ||
| * @param _terms The encoded expected Executions. | ||
| * @param _mode The execution mode, which must be batch. | ||
| * @param _executionCallData The batch execution calldata. | ||
| */ | ||
| function beforeHook( | ||
| bytes calldata _terms, | ||
| bytes calldata, | ||
| ModeCode _mode, | ||
| bytes calldata _executionCallData, | ||
| bytes32, | ||
| address, | ||
| address | ||
| ) | ||
| public | ||
| pure | ||
| override | ||
| onlyBatchExecutionMode(_mode) | ||
| { | ||
| Execution[] calldata executions_ = _executionCallData.decodeBatch(); | ||
| Execution[] memory termsExecutions_ = getTermsInfo(_terms); | ||
|
|
||
| // Validate that the number of executions matches | ||
| require(executions_.length == termsExecutions_.length, "ExactExecutionBatchEnforcer:invalid-batch-size"); | ||
|
|
||
| // Encode both sets of executions and compare the hashes | ||
| require( | ||
| keccak256(abi.encode(executions_)) == keccak256(abi.encode(termsExecutions_)), | ||
| "ExactExecutionBatchEnforcer:invalid-execution" | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @notice Extracts the expected executions from the provided terms. | ||
| * @param _terms The encoded expected Executions. | ||
| * @return executions_ Array of expected Executions. | ||
| */ | ||
| function getTermsInfo(bytes calldata _terms) public pure returns (Execution[] memory executions_) { | ||
| executions_ = _terms.decodeBatch(); | ||
| } | ||
| } |
This file contains hidden or 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,59 @@ | ||
| // SPDX-License-Identifier: MIT AND Apache-2.0 | ||
| pragma solidity 0.8.23; | ||
|
|
||
| import { ExecutionLib } from "@erc7579/lib/ExecutionLib.sol"; | ||
| import { ModeLib } from "@erc7579/lib/ModeLib.sol"; | ||
|
|
||
| import { CaveatEnforcer } from "./CaveatEnforcer.sol"; | ||
| import { ModeCode, Execution } from "../utils/Types.sol"; | ||
|
|
||
| /** | ||
| * @title ExactExecutionEnforcer | ||
| * @notice Ensures that the provided execution matches exactly with the expected execution (target, value, and calldata). | ||
| * @dev This caveat enforcer operates only in single execution mode. | ||
| */ | ||
| contract ExactExecutionEnforcer is CaveatEnforcer { | ||
| using ExecutionLib for bytes; | ||
| using ModeLib for ModeCode; | ||
|
|
||
| ////////////////////////////// Public Methods ////////////////////////////// | ||
|
|
||
| /** | ||
| * @notice Validates that the execution matches exactly with the expected execution. | ||
| * @param _terms The encoded expected Execution. | ||
| * @param _mode The execution mode, which must be single. | ||
| * @param _executionCallData The execution calldata. | ||
| */ | ||
| function beforeHook( | ||
| bytes calldata _terms, | ||
| bytes calldata, | ||
| ModeCode _mode, | ||
| bytes calldata _executionCallData, | ||
| bytes32, | ||
| address, | ||
| address | ||
| ) | ||
| public | ||
| pure | ||
| override | ||
| onlySingleExecutionMode(_mode) | ||
| { | ||
| // Decode execution data | ||
| (address execTarget_, uint256 execValue_, bytes calldata execCallData_) = _executionCallData.decodeSingle(); | ||
|
|
||
| require( | ||
| address(bytes20(_terms[0:20])) == execTarget_ && uint256(bytes32(_terms[20:52])) == execValue_ | ||
| && keccak256(_terms[52:]) == keccak256(execCallData_), | ||
| "ExactExecutionEnforcer:invalid-execution" | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @notice Extracts the expected execution from the provided terms. | ||
| * @param _terms The encoded expected Execution. | ||
| * @return execution_ The expected Execution. | ||
| */ | ||
| function getTermsInfo(bytes calldata _terms) public pure returns (Execution memory execution_) { | ||
| (execution_.target, execution_.value, execution_.callData) = _terms.decodeSingle(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.