- 
        Couldn't load subscription status. 
- Fork 1
Handling ssc cost #2
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
base: v0.7-monad-gas-limit
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -7,6 +7,7 @@ import "../interfaces/IAccount.sol"; | |
| import "../interfaces/IAccountExecute.sol"; | ||
| import "../interfaces/IPaymaster.sol"; | ||
| import "../interfaces/IEntryPoint.sol"; | ||
| import "../interfaces/ISscOpcodes.sol"; | ||
|  | ||
| import "../utils/Exec.sol"; | ||
| import "./StakeManager.sol"; | ||
|  | @@ -28,8 +29,20 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard, | |
|  | ||
| using UserOperationLib for PackedUserOperation; | ||
|  | ||
| int256 constant public SSC_STORAGE_SLOT_COST = 12800000000000000; | ||
| int256 constant public SSC_STORAGE_SLOT_REFUND = 12672000000000000; | ||
|  | ||
| int256 constant public SSC_ACCOUNT_COST = 12800000000000000; | ||
| int256 constant public SSC_ACCOUNT_REFUND = 12672000000000000; | ||
|  | ||
| int256 constant public SSC_CODE_CREATED_COST = 12800000000000000; | ||
|  | ||
| uint256 constant public SSC_MAX_SPEND_FACTOR = 10; | ||
|  | ||
| SenderCreator private immutable _senderCreator = new SenderCreator(); | ||
|  | ||
| ISscOpcodes private immutable _ssc = ISscOpcodes(address(0x665e930982A9a03c844641d453a2C3462ED7Ff41)); | ||
| 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. Deploying bytecode  | ||
|  | ||
| function senderCreator() internal view virtual returns (SenderCreator) { | ||
| return _senderCreator; | ||
| } | ||
|  | @@ -174,10 +187,12 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard, | |
| function handleOps( | ||
| PackedUserOperation[] calldata ops, | ||
| address payable beneficiary | ||
| ) public nonReentrant { | ||
| ) public nonReentrant payable { | ||
| uint256 opslen = ops.length; | ||
| UserOpInfo[] memory opInfos = new UserOpInfo[](opslen); | ||
|  | ||
| int256 preSSC = _netSSC(); | ||
|  | ||
| unchecked { | ||
| for (uint256 i = 0; i < opslen; i++) { | ||
| UserOpInfo memory opInfo = opInfos[i]; | ||
|  | @@ -200,7 +215,12 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard, | |
| collected += _executeUserOp(i, ops[i], opInfos[i]); | ||
| } | ||
|  | ||
| _compensate(beneficiary, collected); | ||
| // this can be negative in cases of refunds | ||
| int256 netSSC = _netSSC() - preSSC; | ||
| // In case of negative netSSC msg.value must be higher than abs(netSSC) | ||
| uint256 sscCompensation = uint256(int256(msg.value) + netSSC); | ||
| 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. The conversion would revert the whole bundle here in case of msg.value is smaller than the refund | ||
|  | ||
| _compensate(beneficiary, collected + sscCompensation); | ||
| } | ||
| } | ||
|  | ||
|  | @@ -303,23 +323,10 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard, | |
| uint256 preOpGas; | ||
| } | ||
|  | ||
| /** | ||
| * Inner function to handle a UserOperation. | ||
| * Must be declared "external" to open a call context, but it can only be called by handleOps. | ||
| * @param callData - The callData to execute. | ||
| * @param opInfo - The UserOpInfo struct. | ||
| * @param context - The context bytes. | ||
| * @return actualGasCost - the actual cost in eth this UserOperation paid for gas | ||
| */ | ||
| function innerHandleOp( | ||
| bytes memory callData, | ||
| UserOpInfo memory opInfo, | ||
| bytes calldata context | ||
| ) external returns (uint256 actualGasCost) { | ||
| uint256 preGas = gasleft(); | ||
| function innerExecuteCall(MemoryUserOp memory mUserOp, bytes memory callData) external { | ||
| require(msg.sender == address(this), "AA92 internal call only"); | ||
| MemoryUserOp memory mUserOp = opInfo.mUserOp; | ||
|  | ||
| int256 preSSC = _netSSC(); | ||
| uint256 callGasLimit = mUserOp.callGasLimit; | ||
| unchecked { | ||
| // handleOps was called with gas limit too low. abort entire bundle. | ||
|  | @@ -335,12 +342,46 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard, | |
| } | ||
| } | ||
| } | ||
| if (callData.length > 0) { | ||
| bool success = Exec.call(mUserOp.sender, 0, callData, callGasLimit); | ||
| if (!success) { | ||
| require(false, string(Exec.getReturnData(REVERT_REASON_MAX_LEN))); | ||
| } else { | ||
| int256 netSSC = _netSSC() - preSSC; | ||
| if (netSSC < 0) { | ||
| // increment deposit for the user's account | ||
| _incrementDeposit(mUserOp.sender, uint256(-netSSC)); | ||
| } else { | ||
| require(uint256(netSSC) <= SSC_MAX_SPEND_FACTOR * callGasLimit * getUserOpGasPrice(mUserOp), "AA97 ssc max cost violation"); | ||
| _decrementDeposit(mUserOp.sender, uint256(netSSC)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|  | ||
| /** | ||
| * Inner function to handle a UserOperation. | ||
| * Must be declared "external" to open a call context, but it can only be called by handleOps. | ||
| * @param callData - The callData to execute. | ||
| * @param opInfo - The UserOpInfo struct. | ||
| * @param context - The context bytes. | ||
| * @return actualGasCost - the actual cost in eth this UserOperation paid for gas | ||
| */ | ||
| function innerHandleOp( | ||
| bytes memory callData, | ||
| UserOpInfo memory opInfo, | ||
| bytes calldata context | ||
| ) external returns (uint256 actualGasCost) { | ||
| uint256 preGas = gasleft(); | ||
| require(msg.sender == address(this), "AA92 internal call only"); | ||
| MemoryUserOp memory mUserOp = opInfo.mUserOp; | ||
|  | ||
| IPaymaster.PostOpMode mode = IPaymaster.PostOpMode.opSucceeded; | ||
| if (callData.length > 0) { | ||
| bool success = Exec.call(mUserOp.sender, 0, callData, callGasLimit); | ||
| (bool success, bytes memory result) = address(this).call( | ||
| abi.encodeWithSelector(this.innerExecuteCall.selector, mUserOp, callData) | ||
| ); | ||
| if (!success) { | ||
| bytes memory result = Exec.getReturnData(REVERT_REASON_MAX_LEN); | ||
| if (result.length > 0) { | ||
| emit UserOperationRevertReason( | ||
| opInfo.userOpHash, | ||
|  | @@ -413,6 +454,15 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard, | |
| } | ||
| } | ||
|  | ||
| /** | ||
| * Calculates total ssc cost / refund | ||
| */ | ||
| function _netSSC() internal view returns (int256) { | ||
| return int256(_ssc.accountsCreated()) * SSC_ACCOUNT_COST - int256(_ssc.accountsCleared()) * SSC_ACCOUNT_REFUND | ||
| + int256(_ssc.slotsCreated()) * SSC_STORAGE_SLOT_COST - int256(_ssc.slotsCleared()) * SSC_STORAGE_SLOT_REFUND | ||
| + int256(_ssc.codeCreated()) * SSC_CODE_CREATED_COST; | ||
| } | ||
|  | ||
| /** | ||
| * Create sender smart contract account if init code is provided. | ||
| * @param opIndex - The operation index. | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // SPDX-License-Identifier: GPL-3.0 | ||
| pragma solidity ^0.8.23; | ||
|  | ||
| interface ISscOpcodes { | ||
| function accountsCreated() external view returns (uint256); // D0 | ||
| function accountsCleared() external view returns (uint256); // D1 | ||
| function slotsCreated() external view returns (uint256); // D2 | ||
| function slotsCleared() external view returns (uint256); // D3 | ||
| function codeCreated() external view returns (uint256); // D4 | ||
| } | 
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.
Have to set correct values