Skip to content

Commit

Permalink
feat(simple-loan): use reentrancy guard at loan updating functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ashhanai committed Dec 17, 2024
1 parent 1f1a1cc commit 6f390c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/loan/terms/simple/loan/PWNSimpleLoan.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.16;

import { MultiToken, IMultiTokenCategoryRegistry } from "MultiToken/MultiToken.sol";

import { ReentrancyGuard } from "openzeppelin/security/ReentrancyGuard.sol";
import { Math } from "openzeppelin/utils/math/Math.sol";
import { SafeCast } from "openzeppelin/utils/math/SafeCast.sol";

Expand All @@ -26,7 +27,7 @@ import { Expired, AddressMissingHubTag } from "pwn/PWNErrors.sol";
* @notice Contract managing a simple loan in PWN protocol.
* @dev Acts as a vault for every loan created by this contract.
*/
contract PWNSimpleLoan is PWNVault, IERC5646, IPWNLoanMetadataProvider {
contract PWNSimpleLoan is PWNVault, ReentrancyGuard, IERC5646, IPWNLoanMetadataProvider {
using MultiToken for address;

string public constant VERSION = "1.2.2";
Expand Down Expand Up @@ -373,7 +374,7 @@ contract PWNSimpleLoan is PWNVault, IERC5646, IPWNLoanMetadataProvider {
LenderSpec calldata lenderSpec,
CallerSpec calldata callerSpec,
bytes calldata extra
) external returns (uint256 loanId) {
) external nonReentrant returns (uint256 loanId) {
// Check provided proposal contract
if (!hub.hasTag(proposalSpec.proposalContract, PWNHubTags.LOAN_PROPOSAL)) {
revert AddressMissingHubTag({ addr: proposalSpec.proposalContract, tag: PWNHubTags.LOAN_PROPOSAL });
Expand Down Expand Up @@ -680,7 +681,7 @@ contract PWNSimpleLoan is PWNVault, IERC5646, IPWNLoanMetadataProvider {
* a vault, waiting on a LOAN token holder to claim it. The function assumes a prior token approval to a contract address.
* @param loanId Id of a loan that is being repaid.
*/
function repayLOAN(uint256 loanId) external {
function repayLOAN(uint256 loanId) external nonReentrant {
LOAN storage loan = LOANs[loanId];

_checkLoanCanBeRepaid(loan.status, loan.defaultTimestamp);
Expand Down Expand Up @@ -788,7 +789,7 @@ contract PWNSimpleLoan is PWNVault, IERC5646, IPWNLoanMetadataProvider {
* Claim will transfer the repaid credit or collateral to a LOAN token holder address and burn the LOAN token.
* @param loanId Id of a loan that is being claimed.
*/
function claimLOAN(uint256 loanId) external {
function claimLOAN(uint256 loanId) external nonReentrant {
LOAN storage loan = LOANs[loanId];

// Check that caller is LOAN token holder
Expand Down Expand Up @@ -934,7 +935,7 @@ contract PWNSimpleLoan is PWNVault, IERC5646, IPWNLoanMetadataProvider {
function extendLOAN(
ExtensionProposal calldata extension,
bytes calldata signature
) external {
) external nonReentrant {
LOAN storage loan = LOANs[extension.loanId];

// Check that loan is in the right state
Expand Down
4 changes: 2 additions & 2 deletions test/unit/PWNSimpleLoan.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import { DummyPoolAdapter } from "test/helper/DummyPoolAdapter.sol";

abstract contract PWNSimpleLoanTest is Test {

bytes32 internal constant LOANS_SLOT = bytes32(uint256(0)); // `LOANs` mapping position
bytes32 internal constant EXTENSION_PROPOSALS_MADE_SLOT = bytes32(uint256(1)); // `extensionProposalsMade` mapping position
bytes32 internal constant LOANS_SLOT = bytes32(uint256(1)); // `LOANs` mapping position
bytes32 internal constant EXTENSION_PROPOSALS_MADE_SLOT = bytes32(uint256(2)); // `extensionProposalsMade` mapping position

PWNSimpleLoan loan;
address hub = makeAddr("hub");
Expand Down

0 comments on commit 6f390c8

Please sign in to comment.