Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
User + selector for nonce calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xrajath committed Apr 6, 2023
1 parent 15c7135 commit 4049493
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/VertexCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ contract VertexCore is Initializable {
/// @notice Mapping of all authorized strategies.
mapping(VertexStrategy => bool) public authorizedStrategies;

/// @notice Mapping of all current nonces for each policyholder.
/// @notice Mapping of users to function selectors to current nonces for EIP-712 signatures.
/// @dev This is used to prevent replay attacks by incrementing the nonce for each operation (createAction,
/// castApproval and castDisapproval) signed by the policyholder.
mapping(address => uint256) public nonces;
mapping(address => mapping(bytes4 => uint256)) public nonces;

// ======================================================
// ======== Contract Creation and Initialization ========
Expand Down Expand Up @@ -222,7 +222,7 @@ contract VertexCore is Initializable {
selector,
keccak256(data),
user,
_useNonce(user)
_useNonce(user, msg.sig)
)
)
)
Expand Down Expand Up @@ -325,7 +325,9 @@ contract VertexCore is Initializable {
EIP712_DOMAIN_TYPEHASH, keccak256(bytes(name)), keccak256(bytes("1")), block.chainid, address(this)
)
),
keccak256(abi.encode(CAST_APPROVAL_TYPEHASH, actionId, role, keccak256(bytes(reason)), user, _useNonce(user)))
keccak256(
abi.encode(CAST_APPROVAL_TYPEHASH, actionId, role, keccak256(bytes(reason)), user, _useNonce(user, msg.sig))
)
)
);
address signer = ecrecover(digest, v, r, s);
Expand Down Expand Up @@ -374,7 +376,9 @@ contract VertexCore is Initializable {
)
),
keccak256(
abi.encode(CAST_DISAPPROVAL_TYPEHASH, actionId, role, keccak256(bytes(reason)), user, _useNonce(user))
abi.encode(
CAST_DISAPPROVAL_TYPEHASH, actionId, role, keccak256(bytes(reason)), user, _useNonce(user, msg.sig)
)
)
)
);
Expand Down Expand Up @@ -611,10 +615,10 @@ contract VertexCore is Initializable {
if (disapprovalPolicySupply == 0) revert RoleHasZeroSupply(disapprovalRole);
}

function _useNonce(address user) internal returns (uint256 nonce) {
nonce = nonces[user];
function _useNonce(address user, bytes4 selector) internal returns (uint256 nonce) {
nonce = nonces[user][selector];
unchecked {
nonces[user] = nonce + 1;
nonces[user][selector] = nonce + 1;
}
}
}

0 comments on commit 4049493

Please sign in to comment.