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

fix(story-nft): resolve reentrancy vulnerability #98

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions contracts/story-nft/StoryBadgeNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ contract StoryBadgeNFT is IStoryBadgeNFT, BaseStoryNFT, ERC721Holder {
// The given signature must not have been used
if (_usedSignatures[signature]) revert StoryBadgeNFT__SignatureAlreadyUsed();

// Mark the signature as used
_usedSignatures[signature] = true;

// The given signature must be valid
bytes32 digest = keccak256(abi.encodePacked(msg.sender)).toEthSignedMessageHash();
if (!SignatureChecker.isValidSignatureNow(_signer, digest, signature)) revert StoryBadgeNFT__InvalidSignature();
Expand All @@ -88,9 +91,6 @@ contract StoryBadgeNFT is IStoryBadgeNFT, BaseStoryNFT, ERC721Holder {
// Transfer the badge to the recipient
_safeTransfer(address(this), recipient, tokenId);

// Mark the signature as used
_usedSignatures[signature] = true;

emit StoryBadgeNFTMinted(recipient, tokenId, ipId);
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/story-nft/StoryNFTFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ contract StoryNFTFactory is IStoryNFTFactory, AccessManagedUpgradeable, UUPSUpgr
// The given signature must not have been used
if ($.usedSignatures[signature]) revert StoryNFTFactory__SignatureAlreadyUsed(signature);

// Mark the signature as used
$.usedSignatures[signature] = true;

// The given organization name must not have been used
if ($.deployedStoryNftsByOrgName[orgName] != address(0))
revert StoryNFTFactory__OrgAlreadyDeployed(orgName, $.deployedStoryNftsByOrgName[orgName]);
Expand All @@ -152,9 +155,6 @@ contract StoryNFTFactory is IStoryNFTFactory, AccessManagedUpgradeable, UUPSUpgr
$.deployedStoryNftsByOrgTokenId[orgTokenId] = storyNft;
$.deployedStoryNftsByOrgIpId[orgIpId] = storyNft;

// Mark the signature as used
$.usedSignatures[signature] = true;

emit StoryNftDeployed(orgName, orgNft, orgTokenId, orgIpId, storyNft);
}

Expand Down
Loading