From 0006ae4e511b2fa5a2f577a0d24c47ac1f9ecaab Mon Sep 17 00:00:00 2001 From: Alexander Biryukov Date: Wed, 28 Aug 2024 16:54:47 +0400 Subject: [PATCH] execute --- src/proofSubmitter/ProofSubmitter.sol | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/proofSubmitter/ProofSubmitter.sol b/src/proofSubmitter/ProofSubmitter.sol index 32d9ec3..f1a3a15 100644 --- a/src/proofSubmitter/ProofSubmitter.sol +++ b/src/proofSubmitter/ProofSubmitter.sol @@ -7,6 +7,7 @@ import "./Erc4337Account.sol"; import "./IProofSubmitter.sol"; import "../proofSubmitterFactory/IProofSubmitterFactory.sol"; import "../lib/eigenLayer/IEigenPodManager.sol"; +import "../lib/@openzeppelin/contracts/utils/Address.sol"; contract ProofSubmitter is Erc4337Account, IProofSubmitter { @@ -25,6 +26,14 @@ contract ProofSubmitter is Erc4337Account, IProofSubmitter { _; } + /// @notice If caller is any account other than the EntryPoint or the owner, revert + modifier onlyEntryPointOrOwner() { + if (msg.sender != entryPoint && msg.sender != owner()) { + revert ProofSubmitter__CallerNeitherEntryPointNorOwner(msg.sender); + } + _; + } + /// @notice If caller not factory, revert modifier onlyFactory() { if (msg.sender != address(i_factory)) { @@ -65,6 +74,26 @@ contract ProofSubmitter is Erc4337Account, IProofSubmitter { emit ProofSubmitter__OperatorDismissed(_operator); } + /** + * execute a transaction (called directly from owner, or by entryPoint) + */ + function execute(address target, bytes calldata data) external onlyEntryPointOrOwner { + Address.functionCall(target, data); + } + + /** + * execute a sequence of transactions + */ + function executeBatch(address[] calldata targets, bytes[] calldata data) external onlyEntryPointOrOwner { + if (targets.length != data.length) { + revert ProofSubmitter__WrongArrayLengths(targets.length, data.length); + } + + for (uint256 i = 0; i < targets.length; i++) { + Address.functionCall(targets[i], data[i]); + } + } + function _call(address target, bytes memory data) internal { (bool success, bytes memory result) = target.call(data); if (!success) {