Skip to content

Commit

Permalink
Prevent silent mint if the token exists already (#928)
Browse files Browse the repository at this point in the history
* Unit tests - price discovery offer

* Prevent silent mint of existing tokens

* Fix failing unit test

* Enable "rewrapping"
  • Loading branch information
zajck committed Apr 8, 2024
1 parent b36d63b commit a0a2aee
Show file tree
Hide file tree
Showing 3 changed files with 336 additions and 176 deletions.
22 changes: 7 additions & 15 deletions contracts/protocol/clients/voucher/BosonVoucher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,7 @@ contract BosonVoucherBase is IBosonVoucher, BeaconClientBase, OwnableUpgradeable
bool committable = isTokenCommittable(_tokenId);

if (committable) {
if (_from == address(this) || _from == owner()) {
// If offer is committable, temporarily update _owners, so transfer succeeds
silentMint(_from, _tokenId);
}

_isCommittable = true;
silentMint(_from, _tokenId);
}

super.transferFrom(_from, _to, _tokenId);
Expand All @@ -411,12 +406,7 @@ contract BosonVoucherBase is IBosonVoucher, BeaconClientBase, OwnableUpgradeable
bool committable = isTokenCommittable(_tokenId);

if (committable) {
if (_from == address(this) || _from == owner()) {
// If offer is committable, temporarily update _owners, so transfer succeeds
silentMint(_from, _tokenId);
}

_isCommittable = true;
silentMint(_from, _tokenId);
}

super.safeTransferFrom(_from, _to, _tokenId, _data);
Expand Down Expand Up @@ -776,10 +766,12 @@ contract BosonVoucherBase is IBosonVoucher, BeaconClientBase, OwnableUpgradeable
* Updates owners, but do not emit Transfer event. Event was already emited during pre-mint.
*/
function silentMint(address _from, uint256 _tokenId) internal {
if (_from != owner() && _from != address(this)) revert NoSilentMintAllowed();
if (!_exists(_tokenId) && (_from == address(this) || _from == owner())) {
// update data, so transfer will succeed
getERC721UpgradeableStorage()._owners[_tokenId] = _from;
}

// update data, so transfer will succeed
getERC721UpgradeableStorage()._owners[_tokenId] = _from;
_isCommittable = true;
}

/*
Expand Down
2 changes: 2 additions & 0 deletions test/protocol/PriceDiscoveryHandlerFacet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,8 @@ describe("IPriceDiscoveryHandlerFacet", function () {
priceDiscovery = new PriceDiscovery(price, Side.Wrapper, wethAddress, wethAddress, calldata);

// Transfer the voucher to weth to pass the "is owner" check
// Use token that was not wrapped yet
tokenId = deriveTokenId(offer.id, 3);
await bosonVoucher.connect(assistant).transferFrom(assistant.address, wethAddress, tokenId);

// Attempt to commit, expecting revert
Expand Down

0 comments on commit a0a2aee

Please sign in to comment.