Skip to content
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

👷🏻‍♂️ EIP7412 Fix #2

Merged
merged 17 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ ValidateSessionParams:test_validateSessionParams() (gas: 76317)
ValidateSessionParams:test_validateSessionParams_callValue_invalid(uint256) (runs: 256, μ: 107033, ~: 107033)
ValidateSessionParams:test_validateSessionParams_destinationContract_invalid(address) (runs: 256, μ: 30633, ~: 30633)
ValidateSessionParams:test_validateSessionParams_destinationContract_invalid(address) (runs: 256, μ: 30641, ~: 30641)
ValidateSessionParams:test_validateSessionParams_funcCallData_invalid(bytes4) (runs: 256, μ: 24502, ~: 24502)
ValidateSessionParams:test_validateSessionParams_funcCallData_invalid(bytes4) (runs: 256, μ: 39815, ~: 39928)
ValidateSessionParams:test_validateSessionParams_funcCallData_invalid() (gas: 24048)
ValidateSessionParams:test_validateSessionParams_funcCallData_invalid() (gas: 37702)
ValidateSessionParams:test_validateSessionParams_sessionKeyData_invalid(address,address) (runs: 256, μ: 31495, ~: 31495)
ValidateSessionParams:test_validateSessionParams_sessionKeyData_invalid(address,address) (runs: 256, μ: 31633, ~: 31633)
ValidateSessionUserOp:test_validateSessionUserOp() (gas: 308778)
ValidateSessionUserOp:test_validateSessionUserOp() (gas: 71829)
ValidateSessionUserOp:test_validateSessionUserOp_op_callData_invalid(bytes4,address,uint256) (runs: 256, μ: 130244, ~: 130244)
ValidateSessionUserOp:test_validateSessionUserOp_op_callData_invalid(bytes4,address,uint256) (runs: 256, μ: 282952, ~: 282231)
ValidateSessionUserOp:test_validateSessionUserOp_sessionKeyData_invalid(address,address) (runs: 256, μ: 93063, ~: 93082)
ValidateSessionUserOp:test_validateSessionUserOp_sessionKeyData_invalid(address,address) (runs: 256, μ: 95222, ~: 95260)
ValidateSessionUserOp:test_validateSessionUserOp_sessionKeySignature_invalid(uint256) (runs: 256, μ: 82854, ~: 82854)
ValidateSessionUserOp:test_validateSessionUserOp_sessionKeySignature_invalid(uint256) (runs: 256, μ: 83024, ~: 83024)
ValidateSessionUserOp:test_validateSessionUserOp_userOpHash_invalid(bytes32) (runs: 256, μ: 74764, ~: 74764)
ValidateSessionUserOp:test_validateSessionUserOp() (gas: 71771)
ValidateSessionUserOp:test_validateSessionUserOp_op_callData_invalid(address) (runs: 256, μ: 114525, ~: 114525)
ValidateSessionUserOp:test_validateSessionUserOp_op_callData_invalid(address,uint256) (runs: 256, μ: 280385, ~: 282121)
ValidateSessionUserOp:test_validateSessionUserOp_sessionKeyData_invalid(address,address) (runs: 256, μ: 93021, ~: 93040)
ValidateSessionUserOp:test_validateSessionUserOp_sessionKeyData_invalid(address,address) (runs: 256, μ: 95216, ~: 95216)
ValidateSessionUserOp:test_validateSessionUserOp_sessionKeySignature_invalid(uint256) (runs: 256, μ: 82818, ~: 82818)
ValidateSessionUserOp:test_validateSessionUserOp_sessionKeySignature_invalid(uint256) (runs: 256, μ: 83046, ~: 83046)
ValidateSessionUserOp:test_validateSessionUserOp_userOpHash_invalid(bytes32) (runs: 256, μ: 74706, ~: 74706)
ValidateSessionUserOp:test_validateSessionUserOp_userOpHash_invalid(bytes32) (runs: 256, μ: 74934, ~: 74934)
6 changes: 3 additions & 3 deletions deployments/BaseGoerli.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"SMv2SessionValidationModule": "0x690ef7a21816A6570d0b500b805bc7ea190E5188",
"SMv3SessionValidationModule": "0xBEc5605040987e52E99c6F97787c7822814b73ca"
}
"SMv2SessionValidationModule": "0x64Db098EDbB149DBe99900c96CC73b6F9A1Af2db",
"SMv3SessionValidationModule": "0x56f5bb804cc5b0b2dd483028be21b5af1bdc4a32"
}
4 changes: 2 additions & 2 deletions deployments/Optimism.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"SMv2SessionValidationModule": "0xBB959E12f9cDd7ba5EcEC3662063D9B97f44208a",
"SMv3SessionValidationModule": "0xf349243bDe8b0Aeee0e52Cb3553047Be8F9cE57c"
"SMv2SessionValidationModule": "tbd",
"SMv3SessionValidationModule": "tbd"
}
4 changes: 2 additions & 2 deletions deployments/OptimismGoerli.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"SMv2SessionValidationModule": "0x5D283bE42cEA50cC74F6CeD79A9844efa34F8A5D",
"SMv3SessionValidationModule": "0xAE55743B6Df1df7194a708460950851a74910D9F"
"SMv2SessionValidationModule": "0xF4243f4d3F8014DE6A085F901d3Fc32339f7A088",
"SMv3SessionValidationModule": "0xF463a18aC17864bc916BDF1d02911601cA5d8d44"
}
168 changes: 88 additions & 80 deletions lcov.info
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
TN:
SF:script/Deploy.s.sol
FN:62,DeployOptimism.run
FNDA:0,DeployOptimism.run
DA:63,0
DA:64,0
DA:66,0
DA:68,0
FN:48,DeployBaseGoerli.run
FNDA:0,DeployBaseGoerli.run
DA:49,0
DA:50,0
DA:52,0
DA:54,0
FN:34,DeployBase.run
FNDA:0,DeployBase.run
DA:35,0
DA:36,0
DA:38,0
DA:40,0
FN:62,DeployOptimism.run
FNDA:0,DeployOptimism.run
DA:63,0
DA:64,0
DA:66,0
DA:68,0
FN:77,DeployOptimismGoerli.run
FNDA:0,DeployOptimismGoerli.run
DA:78,0
DA:79,0
DA:81,0
DA:83,0
FN:18,Setup.deploySystem
FNDA:0,Setup.deploySystem
DA:19,0
DA:20,0
DA:21,0
DA:22,0
DA:23,0
FN:77,DeployOptimismGoerli.run
FNDA:0,DeployOptimismGoerli.run
DA:78,0
DA:79,0
DA:81,0
DA:83,0
FN:34,DeployBase.run
FNDA:0,DeployBase.run
DA:35,0
DA:36,0
DA:38,0
DA:40,0
FNF:5
FNH:0
LF:21
Expand All @@ -40,74 +40,70 @@ BRH:0
end_of_record
TN:
SF:src/SMv2SessionValidationModule.sol
FN:29,SMv2SessionValidationModule.validateSessionParams
FNDA:1025,SMv2SessionValidationModule.validateSessionParams
DA:36,1025
DA:37,1025
DA:40,1025
BRDA:40,0,0,512
BRDA:40,0,1,513
DA:41,512
DA:45,513
BRDA:45,1,0,256
BRDA:45,1,1,257
DA:46,256
DA:49,257
FN:62,SMv2SessionValidationModule.validateSessionUserOp
FNDA:2049,SMv2SessionValidationModule.validateSessionUserOp
DA:70,2049
DA:71,256
BRDA:69,2,0,256
BRDA:69,2,1,1793
DA:73,256
DA:76,1793
DA:77,1793
DA:79,1793
DA:85,1793
BRDA:85,3,0,512
BRDA:85,3,1,1281
DA:86,512
DA:90,1281
BRDA:90,4,0,256
BRDA:90,4,1,1025
DA:91,256
FN:28,SMv2SessionValidationModule.validateSessionParams
FNDA:770,SMv2SessionValidationModule.validateSessionParams
DA:35,770
DA:36,770
DA:39,770
BRDA:39,0,0,512
BRDA:39,0,1,258
DA:40,512
DA:44,258
BRDA:44,1,0,1
BRDA:44,1,1,257
DA:45,1
DA:48,257
FN:61,SMv2SessionValidationModule.validateSessionUserOp
FNDA:1793,SMv2SessionValidationModule.validateSessionUserOp
DA:69,1793
DA:70,256
BRDA:68,2,0,256
BRDA:68,2,1,1537
DA:72,256
DA:75,1537
DA:76,1537
DA:78,1537
DA:84,1537
BRDA:84,3,0,512
BRDA:84,3,1,1025
DA:85,512
DA:90,1025
DA:92,1025
DA:93,1025
DA:94,1025
DA:96,1025
DA:98,1025
DA:99,1025
DA:100,1025
DA:102,1025
DA:106,1025
BRDA:106,5,0,256
BRDA:106,5,1,769
DA:107,256
DA:112,769
BRDA:100,4,0,256
BRDA:100,4,1,769
DA:101,256
DA:106,769
FNF:2
FNH:2
LF:25
LH:25
BRF:12
BRH:12
LF:23
LH:23
BRF:10
BRH:10
end_of_record
TN:
SF:src/SMv3SessionValidationModule.sol
FN:31,SMv3SessionValidationModule.validateSessionParams
FNDA:2566,SMv3SessionValidationModule.validateSessionParams
DA:38,2566
DA:39,2566
DA:42,2566
FNDA:2311,SMv3SessionValidationModule.validateSessionParams
DA:38,2311
DA:39,2311
DA:42,2311
BRDA:42,0,0,512
BRDA:42,0,1,2054
BRDA:42,0,1,1799
DA:43,512
DA:47,2054
DA:49,2054
DA:50,1541
DA:51,1284
DA:52,1027
DA:53,770
DA:54,513
BRDA:48,1,0,256
DA:47,1799
DA:49,1799
DA:50,1286
DA:51,1029
DA:52,772
DA:53,515
DA:54,258
BRDA:48,1,0,1
BRDA:48,1,1,1798
DA:56,256
DA:56,1
DA:60,1798
BRDA:60,2,0,256
BRDA:60,2,1,1
Expand Down Expand Up @@ -202,6 +198,18 @@ BRF:2
BRH:0
end_of_record
TN:
SF:src/kwenta/smv3/EIP7412.sol
FN:14,EIP7412.fulfillOracleQuery
FNDA:0,EIP7412.fulfillOracleQuery
DA:18,0
FNF:1
FNH:0
LF:1
LH:0
BRF:0
BRH:0
end_of_record
TN:
SF:src/openzeppelin/ECDSA.sol
FN:56,ECDSA.tryRecover
FNDA:1543,ECDSA.tryRecover
Expand Down Expand Up @@ -338,18 +346,18 @@ BRH:0
end_of_record
TN:
SF:test/utils/Bootstrap.sol
FN:40,BootstrapOptimismGoerli.init
FNDA:0,BootstrapOptimismGoerli.init
DA:41,0
DA:44,0
DA:46,0
FN:23,Bootstrap.initializeOptimismGoerli
FNDA:0,Bootstrap.initializeOptimismGoerli
DA:24,0
DA:25,0
DA:28,0
DA:30,0
DA:32,0
FN:40,BootstrapOptimismGoerli.init
FNDA:0,BootstrapOptimismGoerli.init
DA:41,0
DA:44,0
DA:46,0
FNF:2
FNH:0
LF:8
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"homepage": "https://github.com/Kwenta/scw-contracts#readme",
"scripts": {
"compile": "forge build",
"test": "forge test --fork-url $(grep OPTIMISM_GOERLI_RPC_URL .env | cut -d '=' -f2) --etherscan-api-key $(grep OPTIMISM_ETHERSCAN_API_KEY .env | cut -d '=' -f2) --gas-report -vvv",
"test": "forge test --gas-report -vvv",
"format": "forge fmt",
"coverage": "forge coverage --fork-url $(grep OPTIMISM_GOERLI_RPC_URL .env | cut -d '=' -f2)",
"coverage:generate-lcov": "forge coverage --fork-url $(grep OPTIMISM_GOERLI_RPC_URL .env | cut -d '=' -f2) --report lcov",
"coverage": "forge coverage",
"coverage:generate-lcov": "forge coverage --report lcov",
"analysis:slither": "slither .",
"gas-snapshot": "forge snapshot --fork-url $(grep OPTIMISM_GOERLI_RPC_URL .env | cut -d '=' -f2)",
"gas-snapshot": "forge snapshot",
"decode-custom-error": "npx @usecannon/cli decode synthetix-perps-market"
},
"repository": {
Expand Down
5 changes: 4 additions & 1 deletion src/SMv2SessionValidationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ contract SMv2SessionValidationModule is ISessionValidationModule {
bytes calldata _sessionKeyData,
bytes calldata _sessionKeySignature
) external pure override returns (bool) {
/// @dev ensure function selector is `IAccount.execute`
/// @dev ensure function selector either
/// `execute(address,uint256,bytes)`
/// or
/// `execute_ncC(address,uint256,bytes)`
if (
bytes4(_op.callData[0:4]) != EXECUTE_SELECTOR
&& bytes4(_op.callData[0:4]) != EXECUTE_OPTIMIZED_SELECTOR
Expand Down
23 changes: 17 additions & 6 deletions src/SMv3SessionValidationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.18;

import {ECDSA} from "src/openzeppelin/ECDSA.sol";
import {IEngine} from "src/kwenta/smv3/IEngine.sol";
import {IERC7412} from "src/kwenta/smv3/IERC7412.sol";
import {EIP7412} from "src/kwenta/smv3/EIP7412.sol";
import {
ISessionValidationModule,
UserOperation
Expand Down Expand Up @@ -49,18 +49,22 @@ contract SMv3SessionValidationModule is ISessionValidationModule {
funcSelector != IEngine.modifyCollateral.selector
&& funcSelector != IEngine.commitOrder.selector
&& funcSelector != IEngine.invalidateUnorderedNonces.selector
&& funcSelector != IERC7412.fulfillOracleQuery.selector
&& funcSelector != EIP7412.fulfillOracleQuery.selector
&& funcSelector != IEngine.depositEth.selector
&& funcSelector != IEngine.withdrawEth.selector
) {
revert InvalidSMv3Selector();
}

/// @dev ensure call value is zero unless calling IEngine.depositEth
/// @dev ensure call value is zero unless calling IEngine.depositEth or EIP7412.fulfillOracleQuery
if (funcSelector == IEngine.depositEth.selector) {
if (callValue == 0) {
revert InvalidCallValue();
}
} else if (funcSelector == EIP7412.fulfillOracleQuery.selector) {
if (callValue == 0) {
revert InvalidCallValue();
}
} else if (callValue != 0) {
revert InvalidCallValue();
}
Expand All @@ -84,7 +88,10 @@ contract SMv3SessionValidationModule is ISessionValidationModule {
bytes calldata _sessionKeyData,
bytes calldata _sessionKeySignature
) external pure override returns (bool) {
/// @dev ensure function selector is `IAccount.execute`
/// @dev ensure function selector either
/// `execute(address,uint256,bytes)`
JaredBorders marked this conversation as resolved.
Show resolved Hide resolved
/// or
/// `execute_ncC(address,uint256,bytes)`
JaredBorders marked this conversation as resolved.
Show resolved Hide resolved
if (
bytes4(_op.callData[0:4]) != EXECUTE_SELECTOR
&& bytes4(_op.callData[0:4]) != EXECUTE_OPTIMIZED_SELECTOR
Expand Down Expand Up @@ -121,18 +128,22 @@ contract SMv3SessionValidationModule is ISessionValidationModule {
funcSelector != IEngine.modifyCollateral.selector
&& funcSelector != IEngine.commitOrder.selector
&& funcSelector != IEngine.invalidateUnorderedNonces.selector
&& funcSelector != IERC7412.fulfillOracleQuery.selector
&& funcSelector != EIP7412.fulfillOracleQuery.selector
&& funcSelector != IEngine.depositEth.selector
&& funcSelector != IEngine.withdrawEth.selector
) {
revert InvalidSMv3Selector();
}
JaredBorders marked this conversation as resolved.
Show resolved Hide resolved

/// @dev ensure call value is zero unless calling IEngine.depositEth
/// @dev ensure call value is zero unless calling IEngine.depositEth or EIP7412.fulfillOracleQuery
if (funcSelector == IEngine.depositEth.selector) {
JaredBorders marked this conversation as resolved.
Show resolved Hide resolved
if (callValue == 0) {
revert InvalidCallValue();
}
} else if (funcSelector == EIP7412.fulfillOracleQuery.selector) {
if (callValue == 0) {
revert InvalidCallValue();
}
} else if (callValue != 0) {
revert InvalidCallValue();
}
JaredBorders marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading