-
Notifications
You must be signed in to change notification settings - Fork 670
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
AA-173: Remove simulation and view-only methods from the EntryPoint contract #321
Merged
+934
−644
Merged
Changes from 31 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
ebbf21a
Makes comments and formatting consistent
gigamesh 64cbdf6
@inheritdoc IEntryPoint
gigamesh d43bc94
Reverts contracts/test/TestHelpers.sol
gigamesh 105d122
fix: entrypoint does not revert even first postOp reverts with short …
leekt 3a6b0a5
lint
leekt 66688cb
gas-report
leekt b56ef7b
Merge branch 'next_v0.7' into gigamesh/comments
forshtat 74ed53b
Update IEntryPoint.sol - add missing 'INonceManager'
forshtat 649daf8
Update EntryPoint.sol - fix lint errors
forshtat aa20d5d
Update gas-checker.txt manually
forshtat e3111fe
Update gas-checker.txt - add newline for the 'diff'
forshtat 10f0502
Merge pull request #235 from gigamesh/gigamesh/comments
forshtat 6a5ce09
Merge branch 'next_v0.7' into develop
forshtat 8116f81
Update gas-checker.txt manually
forshtat 74a3c37
Merge pull request #293 from leekt/develop
forshtat c0dd3ff
WIP: add 'anvil' node to github actions; first test with state override
forshtat 38c14be
Skip anvil-specific test when running against a hardhat node
forshtat 9a9f380
WIP: move simulation-related tests to anvil and run with state override
forshtat 1a701cc
Deploy EntryPointSimulations for Hardhat tests - temporary solution
forshtat 5ecd0f4
Uncomment 'simulateHandleOp' test
forshtat bc69fe7
Update gas checks
forshtat d16f337
Mine and 'evm_revert' a call to "simulateValidation"
forshtat 5b1fb1a
Remove also internal simulation-only functions
forshtat 31dcc37
Fix: even with "state override" keep 'validateSenderAndPaymaster' revert
forshtat 29d56f9
Update gas checks
forshtat 856eb9b
Address PR comments
forshtat eb84c29
support coverage
drortirosh 03eeb19
fix tests
drortirosh 03c3b52
Remove 'test-anvil' step - we will wait for Hardhat to add state diff…
forshtat 2d47f78
Merge branch 'develop' into separate_simulation_entry_point
forshtat d930552
Update 'gas-checker.txt'
forshtat 99a74ce
Address PR comments
forshtat 17e39df
Missed file
forshtat 887bfab
verify that EntryPoint calls never cost less during simulation (#328)
drortirosh 74dc7fb
Add comment that 'EntryPointSimulations' should not be deployed
forshtat 4887d64
Merge branch 'develop' into separate_simulation_entry_point
forshtat e2f4703
waste some gas
drortirosh 28e0fe7
use latest hardhat, with support for eth_call state-override
drortirosh c254faf
lints, coverage
drortirosh ac5a4c9
simulator should not be deployed
drortirosh 4c8a7f1
use "simulateValidation" helper, with state-override
drortirosh 3a6b270
update EIP for simulation
drortirosh 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.12; | ||
|
||
/* solhint-disable avoid-low-level-calls */ | ||
/* solhint-disable no-inline-assembly */ | ||
|
||
import "./EntryPoint.sol"; | ||
import "../interfaces/IEntryPointSimulations.sol"; | ||
|
||
/* | ||
* This contract inherits the EntryPoint and extends it with the view-only methods that are executed by | ||
* the bundler in order to check UserOperation validity and estimate its gas consumption. | ||
*/ | ||
contract EntryPointSimulations is EntryPoint, IEntryPointSimulations { | ||
// solhint-disable-next-line var-name-mixedcase | ||
AggregatorStakeInfo private NOT_AGGREGATED = AggregatorStakeInfo(address(0), StakeInfo(0, 0)); | ||
|
||
/// @inheritdoc IEntryPointSimulations | ||
function simulateValidation( | ||
UserOperation calldata userOp | ||
) | ||
external | ||
returns ( | ||
ValidationResult memory | ||
){ | ||
UserOpInfo memory outOpInfo; | ||
|
||
_simulationOnlyValidations(userOp); | ||
( | ||
uint256 validationData, | ||
uint256 paymasterValidationData | ||
) = _validatePrepayment(0, userOp, outOpInfo); | ||
StakeInfo memory paymasterInfo = _getStakeInfo( | ||
outOpInfo.mUserOp.paymaster | ||
); | ||
StakeInfo memory senderInfo = _getStakeInfo(outOpInfo.mUserOp.sender); | ||
StakeInfo memory factoryInfo; | ||
{ | ||
bytes calldata initCode = userOp.initCode; | ||
address factory = initCode.length >= 20 | ||
? address(bytes20(initCode[0 : 20])) | ||
: address(0); | ||
factoryInfo = _getStakeInfo(factory); | ||
} | ||
|
||
ValidationData memory data = _intersectTimeRange( | ||
validationData, | ||
paymasterValidationData | ||
); | ||
address aggregator = data.aggregator; | ||
bool sigFailed = aggregator == address(1); | ||
ReturnInfo memory returnInfo = ReturnInfo( | ||
outOpInfo.preOpGas, | ||
outOpInfo.prefund, | ||
sigFailed, | ||
data.validAfter, | ||
data.validUntil, | ||
getMemoryBytesFromOffset(outOpInfo.contextOffset) | ||
); | ||
|
||
if (aggregator != address(0) && aggregator != address(1)) { | ||
AggregatorStakeInfo memory aggregatorInfo = AggregatorStakeInfo( | ||
aggregator, | ||
_getStakeInfo(aggregator) | ||
); | ||
return ValidationResult( | ||
returnInfo, | ||
senderInfo, | ||
factoryInfo, | ||
paymasterInfo, | ||
aggregatorInfo | ||
); | ||
} | ||
return ValidationResult( | ||
returnInfo, | ||
senderInfo, | ||
factoryInfo, | ||
paymasterInfo, | ||
NOT_AGGREGATED | ||
); | ||
} | ||
|
||
/// @inheritdoc IEntryPointSimulations | ||
function simulateHandleOp( | ||
UserOperation calldata op, | ||
address target, | ||
bytes calldata targetCallData | ||
) | ||
external nonReentrant | ||
returns ( | ||
ExecutionResult memory | ||
){ | ||
UserOpInfo memory opInfo; | ||
_simulationOnlyValidations(op); | ||
( | ||
uint256 validationData, | ||
uint256 paymasterValidationData | ||
) = _validatePrepayment(0, op, opInfo); | ||
ValidationData memory data = _intersectTimeRange( | ||
validationData, | ||
paymasterValidationData | ||
); | ||
|
||
numberMarker(); | ||
uint256 paid = _executeUserOp(0, op, opInfo); | ||
numberMarker(); | ||
bool targetSuccess; | ||
bytes memory targetResult; | ||
if (target != address(0)) { | ||
(targetSuccess, targetResult) = target.call(targetCallData); | ||
} | ||
return ExecutionResult( | ||
opInfo.preOpGas, | ||
paid, | ||
data.validAfter, | ||
data.validUntil, | ||
targetSuccess, | ||
targetResult | ||
); | ||
} | ||
|
||
function _simulationOnlyValidations( | ||
UserOperation calldata userOp | ||
) private view { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. internal There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed. |
||
try | ||
this._validateSenderAndPaymaster( | ||
userOp.initCode, | ||
userOp.sender, | ||
userOp.paymasterAndData | ||
) | ||
// solhint-disable-next-line no-empty-blocks | ||
{} catch Error(string memory revertReason) { | ||
if (bytes(revertReason).length != 0) { | ||
revert FailedOp(0, revertReason); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Called only during simulation. | ||
* This function always reverts to prevent warm/cold storage differentiation in simulation vs execution. | ||
* @param initCode - The smart account constructor code. | ||
* @param sender - The sender address. | ||
* @param paymasterAndData - The paymaster address followed by the token address to use. | ||
*/ | ||
function _validateSenderAndPaymaster( | ||
bytes calldata initCode, | ||
address sender, | ||
bytes calldata paymasterAndData | ||
) external view { | ||
if (initCode.length == 0 && sender.code.length == 0) { | ||
// it would revert anyway. but give a meaningful message | ||
revert("AA20 account not deployed"); | ||
} | ||
if (paymasterAndData.length >= 20) { | ||
address paymaster = address(bytes20(paymasterAndData[0:20])); | ||
if (paymaster.code.length == 0) { | ||
// It would revert anyway. but give a meaningful message. | ||
revert("AA30 paymaster not deployed"); | ||
} | ||
} | ||
// always revert | ||
revert(""); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better "merge" the 2 separate struct returns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.