Skip to content

Commit 98c191a

Browse files
committed
Merge branch 'feat/open-position-wrapper' of https://github.com/cowprotocol/euler-integration-contracts into feat/open-position-wrapper
2 parents 6ca7a2c + ce128ba commit 98c191a

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/CowEvcBaseWrapper.sol

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,27 +109,25 @@ abstract contract CowEvcBaseWrapper is CowWrapper, PreApprovedHashes {
109109
bytes32 structHash;
110110
bytes32 separator = DOMAIN_SEPARATOR;
111111
uint256 paramsSize = PARAMS_SIZE;
112-
assembly ("memory-safe") {
113-
let ptr := mload(0x40)
114-
115-
// Build structHash = keccak256(typeHash || encodeData(struct))
116-
mstore(ptr, typeHash)
117-
// Copy struct data from params to ptr + 0x20
118-
for { let i := 0 } lt(i, paramsSize) { i := add(i, 0x20) } {
119-
mstore(add(add(ptr, 0x20), i), mload(add(params, i)))
120-
}
121-
structHash := keccak256(ptr, add(0x20, paramsSize))
112+
assembly {
113+
// Build structHash = keccak256(typeHash || encodeData(params))
114+
let wordBeforeParamPtr := sub(params, 0x20)
115+
// Subtraction overflow causes the next line to revert with out of gas if params isn't allocated
116+
let wordBeforeParam := mload(wordBeforeParamPtr)
117+
mstore(wordBeforeParamPtr, typeHash)
118+
structHash := keccak256(wordBeforeParamPtr, add(0x20, paramsSize))
119+
// Restore original content
120+
mstore(wordBeforeParamPtr, wordBeforeParam)
122121

123122
// Build digest = keccak256("\x19\x01" || domainSeparator || structHash)
124-
mstore(ptr, "\x19\x01")
123+
let ptr := mload(0x40)
125124
mstore(add(ptr, 0x02), separator)
126125
mstore(add(ptr, 0x22), structHash)
127126
digest := keccak256(ptr, 0x42)
128127
}
129128
}
130129

131-
/// @notice Internal settlement function called by EVC
132-
/// @dev This function more or less serves as a unified set of security checks that serve as a line of defense for the call stack chain.
130+
/// @notice This function is called by EVC and continues the CoW settlement process inside an EVC batch while including any necessary security check.
133131
function evcInternalSettle(
134132
bytes calldata settleData,
135133
bytes calldata wrapperData,
@@ -154,7 +152,8 @@ abstract contract CowEvcBaseWrapper is CowWrapper, PreApprovedHashes {
154152
) internal {
155153
// There are 2 ways that this contract can validate user operations: 1) the user pre-approves a hash with an on-chain call and grants this contract ability to operate on the user's behalf, or 2) they issue a signature which can be used to call EVC.permit()
156154
// In case the user is using a hash (1), then there would be no signature supplied to this call and we have to resolve the hash instead
157-
// If its flow (2), it happens through the call to EVC.permit() elsewhere, and the EVC becomes responsible for the security.
155+
// If its flow (2), it happens through the call to EVC.permit() elsewhere: if the parameters don't match with the user intent, that call is assumed to revert.
156+
// In this case, we need to check that `permit` has been called by the actual wrapper implementation.
158157
bytes32 approvalHash = _getApprovalHash(typeHash, param);
159158
if (signature.length == 0) {
160159
_consumePreApprovedHash(owner, approvalHash);

0 commit comments

Comments
 (0)