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

Check that the twin address is a contract #653

Merged
merged 4 commits into from
Jul 4, 2023
Merged

Conversation

zajck
Copy link
Member

@zajck zajck commented May 29, 2023

Fix #616

This is branched from #652 which should be merged before this.

@zajck zajck added the v2.3.0 label May 29, 2023
@zajck zajck self-assigned this May 29, 2023
@zajck zajck changed the title Transfer twins check code Check that twin address is a contract May 29, 2023
@zajck zajck changed the title Check that twin address is a contract Check that the twin address is a contract May 29, 2023
@coveralls
Copy link

coveralls commented Jun 20, 2023

Coverage Status

coverage: 99.702% (+0.001%) from 99.701% when pulling 72cb9c6 on transfer-twins-check-code into 586621f on main.

@zajck zajck force-pushed the transfer-twins-check-code branch from 5d6989a to 1c61a4f Compare July 4, 2023 13:45
Copy link
Member

@mischat mischat left a comment

Choose a reason for hiding this comment

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

I have left some comments, would be good to get responses, but i think in the worst case we just create an issue to fix later ... Looks good


if (tokenType == TokenType.FungibleToken) {
// ERC-20 style transfer
data = abi.encodeCall(IERC20.transferFrom, (seller.assistant, sender, twin.amount));
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why we decided to the change this one and not the subsequent similar calls on lines 742 and 751

Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Member Author

Choose a reason for hiding this comment

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

abi.encodeCall was introduced in solidity 8.11. It's a safer alternative to other abi encoders since it checks types at compile time and it's suggested way to use.

We cant use the same on lines 742 and 751 because of the not yet resolved issue with overloaded functions and their selectors: ethereum/solidity#3556

Copy link
Member

Choose a reason for hiding this comment

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

Thanks

twin.tokenId++;
} else {
// Token transfer order is descending
tokenId += twin.supplyAvailable;
Copy link
Member

Choose a reason for hiding this comment

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

This is just an aside, by i prefer the previous syntax here, it was more verbose, i like verbose as I have a simple internal parser ... but anyways, no need to change

Copy link
Member Author

Choose a reason for hiding this comment

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

This reason for this change wasn't even the syntax itself, but I just wanted to remove reading storage twin.tokenId.

tokenId = tokenId + twin.supplyAvailable would be ok for me, too, but now that it's merged already, I won't change it.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, thanks

)
);
);
}
Copy link
Member

Choose a reason for hiding this comment

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

I guess also, that there is no way for us to have an unsupported TokenType at this point? If it is possible, would it be sane to have an else clause and to throw a "unknown token type" kind of revert ? If so, we could always create an issue for the next release

Copy link
Contributor

Choose a reason for hiding this comment

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

there isn't. tokenType is defined when creating a twin, and if a seller passes a value that is not present in the TokenType enum transaction will be reverted.

Copy link
Member

Choose a reason for hiding this comment

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

OK, thanks for the reply @anajuliabit

Copy link
Contributor

@anajuliabit anajuliabit left a comment

Choose a reason for hiding this comment

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

Great job 👍

)
);
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

there isn't. tokenType is defined when creating a twin, and if a seller passes a value that is not present in the TokenType enum transaction will be reverted.

@mischat mischat merged commit 9ad4006 into main Jul 4, 2023
@mischat mischat deleted the transfer-twins-check-code branch July 4, 2023 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix code scanning alert - Low-level calls
4 participants