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

Add ERC3156 extension of ERC20 (flash minting and lending) #2543

Merged
merged 25 commits into from Apr 6, 2021

Conversation

Amxx
Copy link
Collaborator

@Amxx Amxx commented Feb 26, 2021

Fixes #2540

PR Checklist

  • Tests
  • Documentation
  • Changelog entry

@Amxx Amxx changed the title add ERC3156 extension of ERC20 Add ERC3156 extension of ERC20 Feb 26, 2021
@Amxx Amxx marked this pull request as ready for review March 1, 2021 21:35
affiliatedkat
affiliatedkat previously approved these changes Mar 10, 2021
Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

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

This is good with some minor changes.

contracts/token/ERC20/README.adoc Outdated Show resolved Hide resolved
contracts/token/ERC20/README.adoc Outdated Show resolved Hide resolved
contracts/token/ERC20/README.adoc Outdated Show resolved Hide resolved
contracts/token/ERC20/extensions/draft-IERC3156.sol Outdated Show resolved Hide resolved
contracts/token/ERC20/extensions/draft-ERC20FlashMint.sol Outdated Show resolved Hide resolved
contracts/token/ERC20/extensions/draft-ERC20FlashMint.sol Outdated Show resolved Hide resolved
test/token/ERC20/extensions/draft-ERC20FlashMint.test.js Outdated Show resolved Hide resolved
test/token/ERC20/extensions/draft-ERC20FlashMint.test.js Outdated Show resolved Hide resolved
contracts/mocks/ERC3156FlashBorrowerMock.sol Show resolved Hide resolved
Copy link
Contributor

@alcueca alcueca left a comment

Choose a reason for hiding this comment

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

Two corrections in comments, plus a question of the reason for one require in the borrower mock.

contracts/token/ERC20/README.adoc Outdated Show resolved Hide resolved
contracts/token/ERC20/README.adoc Outdated Show resolved Hide resolved
uint256 fee,
bytes calldata data
) public override returns (bytes32) {
require(msg.sender == token);
Copy link
Contributor

Choose a reason for hiding this comment

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

This check is useless if you don't verify that you trust msg.sender.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is just a mock, its not designed to be used outside our testing suit anyway.

The argument used to be that doing a functionCall with arbitrary data to an arbitrary address (line 38) is bad, and we should not show that. Someone could use this endpoint with an arbitrary token address, 0 amount, 0 fee, and an arbitrary payload, which could transfer token held by the receiver.

I "fixed" that by saying that (within our testsuite) only the token should advertize onFlashLoan ... which is not how the ERC might me used in the broader sens, but corresponds to the usage we push in this example.

TLDR: I disagree, it prevents line 38 being used to do arbitrary calls to arbitrary address ... anyone using this method to do anything nasty will only be able to do it to themselves.

Copy link
Contributor

Choose a reason for hiding this comment

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

What I'm concerned about is that coding flash borrowers that are safe is not trivial. Coders using the OZ flash lending implementation might come into the OZ repo to see how you did it, and they will find an unsafe implementation of a flash borrower.

Going that extra mile and making sure that your flash borrower is a decent example on how to code one would be useful for the community.

My mock flash borrower is not great itself, but it could quickly be polished up, and I was able to fully test the reference implementation with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I share these concerns. I think the mock should be either absurdly wrong or have a huge warning, or it should be correct.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I hear your concern, and I do agree we should have extensive documentation in this source code saying this is just for testing, and should not be considered a good example of how to do FlashBorrower.

That being said, I'm having a hard time to see which security issues are not covered by the require(msg.sender == token) check. Do you have anything in mind ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, you might be right. I can't think of any scenario where require (token == msg.sender) let's a malicious lender through. It might be protection enough for a borrower that only accepts loans from flash minters, and not from generic flash lenders.

A bit of weird scenario to discriminate lenders on their internal implementation, but maybe not unsafe.

Amxx and others added 3 commits March 25, 2021 14:56
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
@frangio frangio changed the title Add ERC3156 extension of ERC20 Add ERC3156 extension of ERC20 (flash minting and lending) Apr 6, 2021
Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

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

Looks good!

@frangio frangio enabled auto-merge (squash) April 6, 2021 03:07
@frangio frangio merged commit 5bd798c into OpenZeppelin:master Apr 6, 2021
@Amxx Amxx deleted the feature/ERC3156 branch April 7, 2021 16:25
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.

Add EIP3156 FlashLoan support (ERC20 extension)
4 participants