Skip to content

Commit

Permalink
Fix natspecs and tiny refactor to follow checks-effects-interactions (#…
Browse files Browse the repository at this point in the history
…180)

Fixes some natspecs, removes some outdated documentation, and moves the `setNonceInternal` call in `setActiveNonceAndCallback` to until after all the checks are done.
  • Loading branch information
kevincheng96 authored Mar 15, 2024
1 parent 77fd71e commit 8d25fdf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/quark-core/src/QuarkStateManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ contract QuarkStateManager {
if (scriptAddress == address(0)) {
revert NoActiveNonce();
}
// the last 20 bytes is the address
return scriptAddress;
}

Expand Down Expand Up @@ -133,6 +132,7 @@ contract QuarkStateManager {
* @param nonce Nonce to activate for the transaction
* @param scriptAddress Address of script to invoke with nonce lock
* @param scriptCalldata Calldata for script call to invoke with nonce lock
* @return Return value from the executed operation
* @dev The script is expected to clearNonce() if it wishes to be replayable
*/
function setActiveNonceAndCallback(uint96 nonce, address scriptAddress, bytes calldata scriptCalldata)
Expand All @@ -147,15 +147,15 @@ contract QuarkStateManager {
revert NonceAlreadySet();
}

// spend the nonce; only if the callee chooses to clear it will it get un-set and become replayable
setNonceInternal(bucket, setMask);

address cachedScriptAddress = nonceScriptAddress[msg.sender][nonce];
// if the nonce has been used before, check if the script address matches, and revert if not
if ((cachedScriptAddress != address(0)) && (cachedScriptAddress != scriptAddress)) {
revert NonceScriptMismatch();
}

// spend the nonce; only if the callee chooses to clear it will it get un-set and become replayable
setNonceInternal(bucket, setMask);

// set the nonce-script pair active and yield to the wallet callback
NonceScript memory previousNonceScript = activeNonceScript[msg.sender];
activeNonceScript[msg.sender] = NonceScript({nonce: nonce, scriptAddress: scriptAddress});
Expand Down
4 changes: 2 additions & 2 deletions src/quark-core/src/QuarkWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ contract QuarkWallet is IERC1271 {
* @param v EIP-712 signature v value
* @param r EIP-712 signature r value
* @param s EIP-712 signature s value
* @return return value from the executed operation
* @return Return value from the executed operation
*/
function executeQuarkOperation(QuarkOperation calldata op, uint8 v, bytes32 r, bytes32 s)
external
Expand Down Expand Up @@ -214,7 +214,7 @@ contract QuarkWallet is IERC1271 {
* smart contract
* @param hash Hash of the signed data
* @param signature Signature byte array associated with data
* @return bytes4 Returns the ERC-1271 "magic value" that indicates that the signature is valid
* @return The ERC-1271 "magic value" that indicates the signature is valid
*/
function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4) {
/*
Expand Down

0 comments on commit 8d25fdf

Please sign in to comment.