Skip to content

Commit

Permalink
Merge pull request estarriolvetch#46 from niccolopetti/v0.8
Browse files Browse the repository at this point in the history
Added slither github action to v8 and minor changes
  • Loading branch information
estarriolvetch authored Nov 15, 2023
2 parents fce10d4 + b91f65c commit 7307f33
Show file tree
Hide file tree
Showing 53 changed files with 153 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [14.x]
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/slither-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Slither Analysis
on: [push]
jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Run Slither
uses: crytic/slither-action@v0.3.0
id: slither
with:
slither-args: --exclude-dependencies --filter-paths "(mock|benchmark)"
sarif: results.sarif
fail-on: none

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{ steps.slither.outputs.sarif }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ yarn add --dev erc721psi
```
## Usage
```solidity
pragma solidity ^0.8.0;
pragma solidity ^0.8.18;
import "erc721psi/contracts/ERC721Psi.sol";
Expand Down
25 changes: 13 additions & 12 deletions contracts/ERC721Psi.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

pragma solidity ^0.8.0;
pragma solidity ^0.8.18;

import "@openzeppelin/contracts/utils/Strings.sol";
import "solady/src/utils/LibBitmap.sol";
Expand Down Expand Up @@ -116,7 +116,7 @@ contract ERC721Psi is IERC721Psi {
returns (uint)
{
if(owner == address(0)) revert BalanceQueryForZeroAddress();

//slither-disable-next-line uninitialized-local
uint count;
for( uint i = _startTokenId(); i < _nextTokenId(); ++i ){
if(_exists(i)){
Expand Down Expand Up @@ -265,16 +265,16 @@ contract ERC721Psi is IERC721Psi {
address from,
address to,
uint256 tokenId,
bytes memory _data
bytes memory data
) public payable virtual override {
_safeTransfer(from, to, tokenId, _data);
_safeTransfer(from, to, tokenId, data);
}

/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
* `data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
Expand All @@ -292,10 +292,10 @@ contract ERC721Psi is IERC721Psi {
address from,
address to,
uint256 tokenId,
bytes memory _data
bytes memory data
) internal virtual {
_transfer(from, to, tokenId);
if (!_checkOnERC721Received(from, to, tokenId, 1, _data)) {
if (!_checkOnERC721Received(from, to, tokenId, 1, data)) {
revert TransferToNonERC721ReceiverImplementer();
}
}
Expand Down Expand Up @@ -352,11 +352,11 @@ contract ERC721Psi is IERC721Psi {
function _safeMint(
address to,
uint256 quantity,
bytes memory _data
bytes memory data
) internal virtual {
_mint(to, quantity);
uint256 end = _currentIndex;
if (!_checkOnERC721Received(address(0), to, end - quantity, quantity, _data)) {
if (!_checkOnERC721Received(address(0), to, end - quantity, quantity, data)) {
revert TransferToNonERC721ReceiverImplementer();
}
// Reentrancy protection.
Expand Down Expand Up @@ -484,20 +484,20 @@ contract ERC721Psi is IERC721Psi {
* @param to target address that will receive the tokens
* @param startTokenId uint256 the first ID of the tokens to be transferred
* @param quantity uint256 amount of the tokens to be transfered.
* @param _data bytes optional data to send along with the call
* @param data bytes optional data to send along with the call
* @return r bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 startTokenId,
uint256 quantity,
bytes memory _data
bytes memory data
) private returns (bool r) {
if (to.code.length > 0) {
r = true;
for(uint256 tokenId = startTokenId; tokenId < startTokenId + quantity; tokenId++){
try ERC721Psi__IERC721Receiver(to).onERC721Received( _msgSenderERC721Psi(), from, tokenId, _data) returns (bytes4 retval) {
try ERC721Psi__IERC721Receiver(to).onERC721Received( _msgSenderERC721Psi(), from, tokenId, data) returns (bytes4 retval) {
r = r && retval == ERC721Psi__IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
Expand Down Expand Up @@ -534,6 +534,7 @@ contract ERC721Psi is IERC721Psi {
*/
function tokensOfOwner(address owner) external view virtual returns (uint256[] memory) {
unchecked {
//slither-disable-next-line uninitialized-local
uint256 tokenIdsIdx;
uint256 tokenIdsLength = balanceOf(owner);
uint256[] memory tokenIds = new uint256[](tokenIdsLength);
Expand Down
25 changes: 13 additions & 12 deletions contracts/ERC721PsiUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

pragma solidity ^0.8.0;
pragma solidity ^0.8.18;

import "./interface/IERC721Psi.sol";
import {ERC721PsiStorage} from "./storage/ERC721PsiStorage.sol";
Expand Down Expand Up @@ -109,7 +109,7 @@ contract ERC721PsiUpgradeable is ERC721PsiInitializable, IERC721Psi {
returns (uint)
{
if(owner == address(0)) revert BalanceQueryForZeroAddress();

//slither-disable-next-line uninitialized-local
uint count;
for( uint i = _startTokenId(); i < _nextTokenId(); ++i ){
if(_exists(i)){
Expand Down Expand Up @@ -259,16 +259,16 @@ contract ERC721PsiUpgradeable is ERC721PsiInitializable, IERC721Psi {
address from,
address to,
uint256 tokenId,
bytes memory _data
bytes memory data
) public payable virtual override {
_safeTransfer(from, to, tokenId, _data);
_safeTransfer(from, to, tokenId, data);
}

/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
* `data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
Expand All @@ -286,10 +286,10 @@ contract ERC721PsiUpgradeable is ERC721PsiInitializable, IERC721Psi {
address from,
address to,
uint256 tokenId,
bytes memory _data
bytes memory data
) internal virtual {
_transfer(from, to, tokenId);
if (!_checkOnERC721Received(from, to, tokenId, 1, _data)) {
if (!_checkOnERC721Received(from, to, tokenId, 1, data)) {
revert TransferToNonERC721ReceiverImplementer();
}
}
Expand Down Expand Up @@ -346,11 +346,11 @@ contract ERC721PsiUpgradeable is ERC721PsiInitializable, IERC721Psi {
function _safeMint(
address to,
uint256 quantity,
bytes memory _data
bytes memory data
) internal virtual {
_mint(to, quantity);
uint256 end = ERC721PsiStorage.layout()._currentIndex;
if (!_checkOnERC721Received(address(0), to, end - quantity, quantity, _data)) {
if (!_checkOnERC721Received(address(0), to, end - quantity, quantity, data)) {
revert TransferToNonERC721ReceiverImplementer();
}
// Reentrancy protection.
Expand Down Expand Up @@ -478,20 +478,20 @@ contract ERC721PsiUpgradeable is ERC721PsiInitializable, IERC721Psi {
* @param to target address that will receive the tokens
* @param startTokenId uint256 the first ID of the tokens to be transferred
* @param quantity uint256 amount of the tokens to be transfered.
* @param _data bytes optional data to send along with the call
* @param data bytes optional data to send along with the call
* @return r bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 startTokenId,
uint256 quantity,
bytes memory _data
bytes memory data
) private returns (bool r) {
if (to.code.length > 0) {
r = true;
for(uint256 tokenId = startTokenId; tokenId < startTokenId + quantity; tokenId++){
try ERC721PsiUpgradeable__IERC721Receiver(to).onERC721Received( _msgSenderERC721Psi(), from, tokenId, _data) returns (bytes4 retval) {
try ERC721PsiUpgradeable__IERC721Receiver(to).onERC721Received( _msgSenderERC721Psi(), from, tokenId, data) returns (bytes4 retval) {
r = r && retval == ERC721PsiUpgradeable__IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
Expand Down Expand Up @@ -528,6 +528,7 @@ contract ERC721PsiUpgradeable is ERC721PsiInitializable, IERC721Psi {
*/
function tokensOfOwner(address owner) external view virtual returns (uint256[] memory) {
unchecked {
//slither-disable-next-line uninitialized-local
uint256 tokenIdsIdx;
uint256 tokenIdsLength = balanceOf(owner);
uint256[] memory tokenIds = new uint256[](tokenIdsLength);
Expand Down
6 changes: 3 additions & 3 deletions contracts/benchmark/ERC721AMock.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Creators: Chiru Labs

pragma solidity ^0.8.0;
pragma solidity ^0.8.18;

import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/utils/ReentrancyGuard.sol';
Expand Down Expand Up @@ -31,9 +31,9 @@ contract ERC721AMock is ERC721A {
function safeMint(
address to,
uint256 quantity,
bytes memory _data
bytes memory data
) public {
_safeMint(to, quantity, _data);
_safeMint(to, quantity, data);
}

function benchmarkOwnerOf(uint256 tokenId) public returns (address owner) {
Expand Down
4 changes: 2 additions & 2 deletions contracts/benchmark/ERC721EnumerableMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ contract ERC721EnumerableMock is ERC721Enumerable {
function safeMint(
address to,
uint256 tokenId,
bytes memory _data
bytes memory data
) public {
_safeMint(to, tokenId, _data);
_safeMint(to, tokenId, data);
}


Expand Down
2 changes: 1 addition & 1 deletion contracts/extension/ERC721PsiAddressData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
pragma solidity ^0.8.0;
pragma solidity ^0.8.18;

import "../ERC721Psi.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/extension/ERC721PsiAddressDataUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
pragma solidity ^0.8.0;
pragma solidity ^0.8.18;

import "../ERC721PsiUpgradeable.sol";
import {ERC721PsiAddressDataStorage} from "../storage/ERC721PsiAddressDataStorage.sol";
Expand Down
6 changes: 3 additions & 3 deletions contracts/extension/ERC721PsiBatchMetaData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

pragma solidity ^0.8.0;
pragma solidity ^0.8.18;


import "../ERC721Psi.sol";
Expand All @@ -23,10 +23,10 @@ abstract contract ERC721PsiBatchMetaData is ERC721Psi {
function _safeMint(
address to,
uint256 quantity,
bytes memory _data
bytes memory data
) internal virtual override {
_metaDataBatchHead.set(_nextTokenId());
super._safeMint(to, quantity, _data);
super._safeMint(to, quantity, data);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions contracts/extension/ERC721PsiBatchMetaDataUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

pragma solidity ^0.8.0;
pragma solidity ^0.8.18;


import "../ERC721PsiUpgradeable.sol";
Expand All @@ -23,10 +23,10 @@ abstract contract ERC721PsiBatchMetaDataUpgradeable is ERC721PsiUpgradeable {
function _safeMint(
address to,
uint256 quantity,
bytes memory _data
bytes memory data
) internal virtual override {
ERC721PsiBatchMetaDataStorage.layout()._metaDataBatchHead.set(_nextTokenId());
super._safeMint(to, quantity, _data);
super._safeMint(to, quantity, data);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/extension/ERC721PsiBurnable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
pragma solidity ^0.8.0;
pragma solidity ^0.8.18;

import "solady/src/utils/LibBitmap.sol";
import "../ERC721Psi.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/extension/ERC721PsiBurnableUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
pragma solidity ^0.8.0;
pragma solidity ^0.8.18;

import "solady/src/utils/LibBitmap.sol";
import "../ERC721PsiUpgradeable.sol";
Expand Down
11 changes: 6 additions & 5 deletions contracts/extension/ERC721PsiRandomSeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
pragma solidity ^0.8.0;
pragma solidity ^0.8.18;

import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/vrf/VRFConsumerBaseV2.sol";
Expand All @@ -19,10 +19,11 @@ import "./ERC721PsiBatchMetaData.sol";

abstract contract ERC721PsiRandomSeed is IERC721RandomSeed, ERC721PsiBatchMetaData, VRFConsumerBaseV2 {
// Chainklink VRF V2
///@custom:security non-reentrant
VRFCoordinatorV2Interface immutable COORDINATOR;
uint32 immutable callbackGasLimit;
uint16 immutable requestConfirmations;
uint16 constant numWords = 1;
uint16 constant NUM_WORDS = 1;

mapping(uint256 => uint256) private requestIdToTokenId;
mapping(uint256 => uint256) private batchSeed;
Expand Down Expand Up @@ -55,7 +56,7 @@ abstract contract ERC721PsiRandomSeed is IERC721RandomSeed, ERC721PsiBatchMetaDa
function _safeMint(
address to,
uint256 quantity,
bytes memory _data
bytes memory data
) internal virtual override {
uint256 nextTokenId = _nextTokenId();

Expand All @@ -64,12 +65,12 @@ abstract contract ERC721PsiRandomSeed is IERC721RandomSeed, ERC721PsiBatchMetaDa
_subscriptionId(),
requestConfirmations,
callbackGasLimit,
numWords
NUM_WORDS
);

emit RandomnessRequest(requestId);
requestIdToTokenId[requestId] = nextTokenId;
super._safeMint(to, quantity, _data);
super._safeMint(to, quantity, data);
_processRandomnessRequest(requestId, nextTokenId);
}

Expand Down
Loading

0 comments on commit 7307f33

Please sign in to comment.