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

3078 - Series indexer contract #44

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Conversation

lpopo0856
Copy link
Contributor

Implement version 1

Better naming

f
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

solhint

⚠️ [solhint] reported by reviewdog 🐶
GC: Use Custom Errors instead of require statements

require(proposedArtistAddr != address(0), "Invalid address");


⚠️ [solhint] reported by reviewdog 🐶
GC: Use Custom Errors instead of require statements

require(!seriesPendingCoArtist[seriesID][proposedArtistID], "Already proposed");


⚠️ [solhint] reported by reviewdog 🐶
GC: Use Custom Errors instead of require statements

require(seriesPendingCoArtist[seriesID][proposedArtistID], "No proposal exists");


⚠️ [solhint] reported by reviewdog 🐶
GC: Use Custom Errors instead of require statements

require(artistID != 0, "Not an artist");


⚠️ [solhint] reported by reviewdog 🐶
GC: Use Custom Errors instead of require statements

require(seriesPendingCoArtist[seriesID][artistID], "No pending proposal");


⚠️ [solhint] reported by reviewdog 🐶
GC: Use Custom Errors instead of require statements

require(artistID != 0, "Not an artist");


⚠️ [solhint] reported by reviewdog 🐶
GC: Use Custom Errors instead of require statements

require(!ownerRightsRevokedForArtistID[artistID], "Already revoked");


⚠️ [solhint] reported by reviewdog 🐶
GC: Use Custom Errors instead of require statements

require(artistID != 0, "Not an artist");


⚠️ [solhint] reported by reviewdog 🐶
GC: Use Custom Errors instead of require statements

require(ownerRightsRevokedForArtistID[artistID], "Not revoked");


⚠️ [solhint] reported by reviewdog 🐶
GC: Use Custom Errors instead of require statements

require(newAddress != address(0), "Invalid new address");


⚠️ [solhint] reported by reviewdog 🐶
Error message for require is too long: 37 counted / 32 allowed

require(addressToArtistID[newAddress] == 0, "Address already assigned to an artist");


⚠️ [solhint] reported by reviewdog 🐶
GC: String exceeds 32 bytes

require(addressToArtistID[newAddress] == 0, "Address already assigned to an artist");


⚠️ [solhint] reported by reviewdog 🐶
GC: Use Custom Errors instead of require statements

require(addressToArtistID[newAddress] == 0, "Address already assigned to an artist");


⚠️ [solhint] reported by reviewdog 🐶
GC: Use Custom Errors instead of require statements

require(oldAddress != address(0), "Invalid artistID");


⚠️ [solhint] reported by reviewdog 🐶
GC: Use Custom Errors instead of require statements

require(isCallerArtist || isOwnerWithRights, "Not authorized to update address");


⚠️ [solhint] reported by reviewdog 🐶
Error message for revert is too long: 39 counted / 32 allowed

revert("One of the artists revoked owner rights");


⚠️ [solhint] reported by reviewdog 🐶
GC: String exceeds 32 bytes

revert("One of the artists revoked owner rights");


⚠️ [solhint] reported by reviewdog 🐶
GC: Use Custom Errors instead of revert statements

revert("One of the artists revoked owner rights");

@lpopo0856 lpopo0856 force-pushed the 3078-series-index-contract branch from a8851ad to abf3af4 Compare December 13, 2024 11:44

contract SeriesIndexer is Ownable.Ownable {
// Counter
uint256 private nextSeriesID = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the length of existing series map so we don't need to maintain this counter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this's not possible since the mapping in solidity is a simple hash table without key management.

contract SeriesIndexer is Ownable.Ownable {
// Counter
uint256 private nextSeriesID = 1;
uint256 private nextArtistID = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same has above comment but for the artist map.

uint256 private nextArtistID = 1;

struct Series {
string metadata;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this field is for series metadata source, so it should store the uri so the name should be metadataURI


struct Series {
string metadata;
string contractTokenData;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above comment, it should be tokenDataURI

// Artist Management
mapping(uint256 => address) private artistIDToAddress;
mapping(address => uint256) private addressToArtistID;
mapping(uint256 => bool) private ownerRightsRevokedForArtistID;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be on series level instead of artist level. We could also provide a feature for revoking all series from an artist.

// Internal Helper Functions
// ------------------------

function _checkOwnerOrArtist(uint256 seriesID) internal view {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should pass the address instead of assume the msg.sender. The caller should determine which one should be passed, that will be more extensible and readable. If we just want to stick with the msg.sender, we might need a better name like _checkMsgSenderIsOwnerOrArtist

}
}

function _checkArtist(uint256 seriesID) internal view {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same here.

uint256 indexed seriesID,
uint256[] artistIDs,
string metadata,
string seriesContractTokenCID
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer using something like URI instead of CID that we need to stick to ipfs. Using URI could be better for extensibility later on.

Comment on lines 211 to 212
require(length <= 50, "Batch size too large"); // Prevent DOS attacks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean for prevent DOS attacks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that mean if someone try to put really large number of list, the contract will deny to service. It's not quite of an attack I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the words is removed anyway

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that could be out of gas since it could reach the block gas limit so i don't consider it as "denial of service"

seriesExists(seriesID)
onlyOwnerOrArtist(seriesID)
{
Series storage series = seriesDetails[seriesID];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use memory

Series storage series = seriesDetails[seriesID];
for (uint256 i = 0; i < series.artistIDs.length; i++) {
uint256 artistID = series.artistIDs[i];
isArtistIDInSeries[seriesID][artistID] = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be redundant since we did it in the _removeSeriesFromArtist

for (uint256 i = 0; i < series.artistIDs.length; i++) {
uint256 artistID = series.artistIDs[i];
isArtistIDInSeries[seriesID][artistID] = false;
_removeSeriesFromArtist(artistID, seriesID);
Copy link
Member

@jollyjoker992 jollyjoker992 Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we call the function _removeArtistFromSeries as well if we tend to remove the artist from series?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, you did it when deleting the storage below.


_ensureArtistHasID(proposedArtistAddr);
uint256 proposedArtistID = addressToArtistID[proposedArtistAddr];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you don't check the proposed address has been already artist for this series.

}

Series storage series = seriesDetails[seriesID];
series.artistIDs.push(artistID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic could be presented already in _addArtistsToSeries, could it be reused?

if (artistID == 0) {
revert NotAnArtistError(msg.sender);
}
if (!ownerRightsRevokedForArtistID[artistID]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant parentheses

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol" as Ownable;
import "@openzeppelin/contracts/utils/structs/BitMaps.sol";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [solhint] reported by reviewdog 🐶
global import of path @openzeppelin/contracts/utils/structs/BitMaps.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

@lpopo0856 lpopo0856 force-pushed the 3078-series-index-contract branch from 7591cdd to ca84544 Compare December 26, 2024 13:56
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [solhint] reported by reviewdog 🐶
global import of path @openzeppelin/contracts/access/Ownable.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants