-
Notifications
You must be signed in to change notification settings - Fork 147
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
Nft bridge #291
Open
critesjosh
wants to merge
76
commits into
AztecProtocol:master
Choose a base branch
from
critesjosh:nft-bridge
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Nft bridge #291
Changes from all commits
Commits
Show all changes
76 commits
Select commit
Hold shift + click to select a range
5bdf8bf
address registry and nft vault
critesjosh f0296ef
updates
critesjosh 596fe4a
e2e test
critesjosh 4dc874c
update max int
critesjosh 19f3ada
remove deposit param
critesjosh a370585
increase gas
critesjosh 847cc31
e2e working
critesjosh 52e1a43
add input value
critesjosh 63ef608
add registry to constructor
critesjosh 1aa9eb0
del
critesjosh 869e81a
rename
critesjosh eafca9e
deposit + withdraw
critesjosh 86e68f7
add 0 output check
critesjosh 202c05e
update comments
critesjosh d0668a6
add tests
critesjosh 4936461
del
critesjosh 69463ee
cleanup comments
critesjosh 271abda
Merge branch 'AztecProtocol:master' into nft-bridge
critesjosh c3b5ce0
fmt
critesjosh 27c6167
Merge branch 'nft-bridge' of https://github.com/critesjosh/aztec-conn…
critesjosh 0ab5406
add L1 option
critesjosh 1288f97
update inc
critesjosh b845e70
remove comments, fix matchDeposit
critesjosh 217a526
rename id, cleanup
critesjosh 4355353
update tests
critesjosh 6559576
check event
critesjosh cfe88ae
fmt
critesjosh a5d6705
clean up comments
critesjosh a10c6ba
clean up comments
critesjosh 469c372
clean comments
critesjosh 281be8f
clean comments
critesjosh 5c2c0b3
add deposit/withdraw events
critesjosh ad48137
revert reason for invalid input/outputs
critesjosh 3473dd6
deployments
critesjosh 1ae3752
gas benchmarks
critesjosh aa7049e
test deposit/withdraw events
critesjosh 746f595
fmt
critesjosh 0e9ead3
Merge branch 'AztecProtocol:master' into nft-bridge
critesjosh 055c399
natspec comments
critesjosh cdfacf9
Merge branch 'nft-bridge' of https://github.com/critesjosh/aztec-conn…
critesjosh 41004f2
fmt
critesjosh 623725e
add test
critesjosh 55031c9
fix linting
critesjosh 32214eb
fmt
critesjosh ae33651
uint256 addressCount
critesjosh a4dbf00
incorporate lasse's feedback
critesjosh 39984bd
Merge remote-tracking branch 'upstream/master' into nft-bridge
critesjosh d0b3cef
fix test
critesjosh 8367e39
fmt
critesjosh b6e18ea
add transfer functionality
critesjosh 249a917
move asset defs to storage
critesjosh 55f3064
add .env
critesjosh 82f7617
edits
critesjosh 7002556
add .env
critesjosh 22588ab
add .env
critesjosh 4e937c8
add readme
critesjosh 7741364
update address id
critesjosh 73124ef
add readme
critesjosh f6d8757
add content
critesjosh 4f91cf8
update
critesjosh 62f2f20
fmt, lint
critesjosh d65c41c
Merge branch 'nft-bridge' into nft-transfer-bridge
critesjosh 625f166
Merge pull request #2 from critesjosh/nft-transfer-bridge
critesjosh e00d25a
Merge branch 'AztecProtocol:master' into nft-bridge
critesjosh e00d03d
Update .gitignore
critesjosh 5420aed
fix hardcoded nonce
critesjosh 586ef5d
Merge branch 'nft-bridge' of https://github.com/critesjosh/aztec-conn…
critesjosh 9f7be07
remove unreachable code
critesjosh c50d702
test invalid input amount
critesjosh f9fd54e
incorporat e review suggestions
critesjosh e21dd63
Delete .env
critesjosh 7feeec7
Merge branch 'AztecProtocol:master' into nft-bridge
critesjosh 7cef40c
fmt
critesjosh 54833bd
Merge branch 'AztecProtocol:master' into nft-bridge
critesjosh a4e70ca
fmt
critesjosh c5fd393
retry fmt
critesjosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ out/ | |
node_modules/ | ||
yarn-error.log | ||
typechain-types/ | ||
broadcast/ | ||
broadcast/ | ||
.env |
Submodule forge-std
updated
25 files
+10 −44 | .github/workflows/ci.yml | |
+5 −4 | foundry.toml | |
+1 −1 | package.json | |
+1 −16 | src/Common.sol | |
+0 −1 | src/Components.sol | |
+2 −2 | src/Script.sol | |
+1 −1 | src/StdAssertions.sol | |
+0 −90 | src/StdChains.sol | |
+125 −48 | src/StdCheats.sol | |
+16 −124 | src/StdJson.sol | |
+1 −6 | src/StdUtils.sol | |
+3 −3 | src/Test.sol | |
+52 −112 | src/Vm.sol | |
+2 −3 | src/interfaces/IERC1155.sol | |
+0 −1 | src/interfaces/IERC165.sol | |
+0 −1 | src/interfaces/IERC20.sol | |
+1 −2 | src/interfaces/IERC4626.sol | |
+1 −2 | src/interfaces/IERC721.sol | |
+0 −61 | test/StdChains.t.sol | |
+22 −9 | test/StdCheats.t.sol | |
+3 −14 | test/StdUtils.t.sol | |
+0 −10 | test/compilation/CompilationScript.sol | |
+0 −10 | test/compilation/CompilationScriptBase.sol | |
+0 −10 | test/compilation/CompilationTest.sol | |
+0 −10 | test/compilation/CompilationTestBase.sol |
Submodule rollup-encoder
updated
4 files
+0 −1 | .gitmodules | |
+1 −1 | lib/forge-std | |
+15 −2 | src/RollupEncoder.sol | |
+0 −76 | src/libraries/EventsErrorsV2.sol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2022 Aztec. | ||
pragma solidity >=0.8.4; | ||
|
||
import {IERC721} from "../../../lib/openzeppelin-contracts/contracts/interfaces/IERC721.sol"; | ||
import {AztecTypes} from "../../../lib/rollup-encoder/src/libraries/AztecTypes.sol"; | ||
import {ErrorLib} from "../base/ErrorLib.sol"; | ||
import {BridgeBase} from "../base/BridgeBase.sol"; | ||
import {AddressRegistry} from "../registry/AddressRegistry.sol"; | ||
|
||
/** | ||
* @title Basic NFT Vault for Aztec. | ||
* @author Josh Crites, (@critesjosh on Github), Aztec Team | ||
* @notice You can use this contract to hold your NFTs on Aztec. Whoever holds the corresponding virutal asset note can withdraw the NFT. | ||
* @dev This bridge demonstrates basic functionality for an NFT bridge. This may be extended to support more features. | ||
*/ | ||
contract NFTVault is BridgeBase { | ||
struct NFTAsset { | ||
address collection; | ||
uint256 tokenId; | ||
} | ||
|
||
AddressRegistry public immutable REGISTRY; | ||
|
||
mapping(uint256 => NFTAsset) public nftAssets; | ||
|
||
error InvalidVirtualAssetId(); | ||
|
||
event NFTDeposit(uint256 indexed virtualAssetId, address indexed collection, uint256 indexed tokenId); | ||
event NFTWithdraw(uint256 indexed virtualAssetId, address indexed collection, uint256 indexed tokenId); | ||
|
||
/** | ||
* @notice Set the addresses of RollupProcessor and AddressRegistry | ||
* @param _rollupProcessor Address of the RollupProcessor | ||
* @param _registry Address of the AddressRegistry | ||
*/ | ||
constructor(address _rollupProcessor, address _registry) BridgeBase(_rollupProcessor) { | ||
REGISTRY = AddressRegistry(_registry); | ||
} | ||
|
||
/** | ||
* @notice Function for the first step of a NFT deposit, a NFT withdrawal, or transfer to another NFTVault. | ||
* @dev This method can only be called from the RollupProcessor. The first step of the | ||
* deposit flow returns a virutal asset note that will represent the NFT on Aztec. After the | ||
* virutal asset note is received on Aztec, the user calls matchAndPull which deposits the NFT | ||
* into Aztec and matches it with the virtual asset. When the virutal asset is sent to this function | ||
* it is burned and the NFT is sent to the recipient passed in _auxData. | ||
* | ||
* @param _inputAssetA - ETH (Deposit) or VIRTUAL (Withdrawal) | ||
* @param _outputAssetA - VIRTUAL (Deposit) or 0 ETH (Withdrawal) | ||
* @param _totalInputValue - must be 1 wei (Deposit) or 1 VIRTUAL (Withdrawal) | ||
* @param _interactionNonce - A globally unique identifier of this interaction/`convert(...)` call | ||
* corresponding to the returned virtual asset id | ||
* @param _auxData - corresponds to the Ethereum address id in the AddressRegistry.sol for withdrawals | ||
* @return outputValueA - 1 VIRTUAL asset (Deposit) or 0 ETH (Withdrawal) | ||
* | ||
*/ | ||
|
||
function convert( | ||
AztecTypes.AztecAsset calldata _inputAssetA, | ||
AztecTypes.AztecAsset calldata, | ||
AztecTypes.AztecAsset calldata _outputAssetA, | ||
AztecTypes.AztecAsset calldata, | ||
uint256 _totalInputValue, | ||
uint256 _interactionNonce, | ||
uint64 _auxData, | ||
address | ||
) | ||
external | ||
payable | ||
override(BridgeBase) | ||
onlyRollup | ||
returns (uint256 outputValueA, uint256 outputValueB, bool isAsync) | ||
{ | ||
if ( | ||
_inputAssetA.assetType == AztecTypes.AztecAssetType.NOT_USED | ||
|| _inputAssetA.assetType == AztecTypes.AztecAssetType.ERC20 | ||
) revert ErrorLib.InvalidInputA(); | ||
if ( | ||
_outputAssetA.assetType == AztecTypes.AztecAssetType.NOT_USED | ||
|| _outputAssetA.assetType == AztecTypes.AztecAssetType.ERC20 | ||
) revert ErrorLib.InvalidOutputA(); | ||
if (_totalInputValue != 1) { | ||
revert ErrorLib.InvalidInputAmount(); | ||
} | ||
if ( | ||
_inputAssetA.assetType == AztecTypes.AztecAssetType.ETH | ||
&& _outputAssetA.assetType == AztecTypes.AztecAssetType.VIRTUAL | ||
) { | ||
return (1, 0, false); | ||
} else if (_inputAssetA.assetType == AztecTypes.AztecAssetType.VIRTUAL) { | ||
NFTAsset memory token = nftAssets[_inputAssetA.id]; | ||
if (token.collection == address(0x0)) { | ||
revert ErrorLib.InvalidInputA(); | ||
} | ||
|
||
address to = REGISTRY.addresses(_auxData); | ||
if (to == address(0x0)) { | ||
revert ErrorLib.InvalidAuxData(); | ||
} | ||
delete nftAssets[_inputAssetA.id]; | ||
emit NFTWithdraw(_inputAssetA.id, token.collection, token.tokenId); | ||
|
||
if (_outputAssetA.assetType == AztecTypes.AztecAssetType.ETH) { | ||
IERC721(token.collection).transferFrom(address(this), to, token.tokenId); | ||
return (0, 0, false); | ||
} else { | ||
IERC721(token.collection).approve(to, token.tokenId); | ||
NFTVault(to).matchAndPull(_interactionNonce, token.collection, token.tokenId); | ||
return (1, 0, false); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @notice Function for the second step of a NFT deposit or for transfers from other NFTVaults. | ||
* @dev For a deposit, this method is called by an Ethereum L1 account that owns the NFT to deposit. | ||
* The user must approve this bridge contract to transfer the users NFT before this function | ||
* is called. This function assumes the NFT contract complies with the ERC721 standard. | ||
* For a transfer from another NFTVault, this method is called by the NFTVault that is sending the NFT. | ||
* | ||
* @param _virtualAssetId - the virutal asset id of the note returned in the deposit step of the convert function | ||
* @param _collection - collection address of the NFT | ||
* @param _tokenId - the token id of the NFT | ||
*/ | ||
|
||
function matchAndPull(uint256 _virtualAssetId, address _collection, uint256 _tokenId) external { | ||
if (nftAssets[_virtualAssetId].collection != address(0x0)) { | ||
revert InvalidVirtualAssetId(); | ||
} | ||
nftAssets[_virtualAssetId] = NFTAsset({collection: _collection, tokenId: _tokenId}); | ||
IERC721(_collection).transferFrom(msg.sender, address(this), _tokenId); | ||
emit NFTDeposit(_virtualAssetId, _collection, _tokenId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2022 Aztec. | ||
pragma solidity >=0.8.4; | ||
|
||
import {AztecTypes} from "../../../lib/rollup-encoder/src/libraries/AztecTypes.sol"; | ||
import {ErrorLib} from "../base/ErrorLib.sol"; | ||
import {BridgeBase} from "../base/BridgeBase.sol"; | ||
|
||
/** | ||
* @title Aztec Address Registry. | ||
* @author Josh Crites (@critesjosh on Github), Aztec team | ||
* @notice This contract can be used to anonymously register an ethereum address with an id. | ||
* This is useful for reducing the amount of data required to pass an ethereum address through auxData. | ||
* @dev Use this contract to lookup ethereum addresses by id. | ||
*/ | ||
contract AddressRegistry is BridgeBase { | ||
uint256 public addressCount; | ||
mapping(uint256 => address) public addresses; | ||
|
||
event AddressRegistered(uint256 indexed index, address indexed entity); | ||
|
||
/** | ||
* @notice Set address of rollup processor | ||
* @param _rollupProcessor Address of rollup processor | ||
*/ | ||
constructor(address _rollupProcessor) BridgeBase(_rollupProcessor) {} | ||
|
||
/** | ||
* @notice Function for getting VIRTUAL assets (step 1) to register an address and registering an address (step 2). | ||
* @dev This method can only be called from the RollupProcessor. The first step to register an address is for a user to | ||
* get the type(uint160).max value of VIRTUAL assets back from the bridge. The second step is for the user | ||
* to send an amount of VIRTUAL assets back to the bridge. The amount that is sent back is equal to the number of the | ||
* ethereum address that is being registered (e.g. uint160(0x2e782B05290A7fFfA137a81a2bad2446AD0DdFEB)). | ||
* | ||
* @param _inputAssetA - ETH (step 1) or VIRTUAL (step 2) | ||
* @param _outputAssetA - VIRTUAL (steps 1 and 2) | ||
* @param _totalInputValue - must be 1 wei (ETH) (step 1) or address value (step 2) | ||
* @return outputValueA - type(uint160).max (step 1) or 0 VIRTUAL (step 2) | ||
* | ||
*/ | ||
|
||
function convert( | ||
AztecTypes.AztecAsset calldata _inputAssetA, | ||
AztecTypes.AztecAsset calldata, | ||
AztecTypes.AztecAsset calldata _outputAssetA, | ||
AztecTypes.AztecAsset calldata, | ||
uint256 _totalInputValue, | ||
uint256, | ||
uint64, | ||
address | ||
) external payable override(BridgeBase) onlyRollup returns (uint256 outputValueA, uint256, bool) { | ||
if ( | ||
_inputAssetA.assetType == AztecTypes.AztecAssetType.NOT_USED | ||
|| _inputAssetA.assetType == AztecTypes.AztecAssetType.ERC20 | ||
) revert ErrorLib.InvalidInputA(); | ||
if (_outputAssetA.assetType != AztecTypes.AztecAssetType.VIRTUAL) { | ||
revert ErrorLib.InvalidOutputA(); | ||
} | ||
if (_inputAssetA.assetType == AztecTypes.AztecAssetType.ETH) { | ||
if (_totalInputValue != 1) { | ||
revert ErrorLib.InvalidInputAmount(); | ||
critesjosh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return (type(uint160).max, 0, false); | ||
} else if (_inputAssetA.assetType == AztecTypes.AztecAssetType.VIRTUAL) { | ||
address toRegister = address(uint160(_totalInputValue)); | ||
registerAddress(toRegister); | ||
return (0, 0, false); | ||
} | ||
} | ||
|
||
/** | ||
* @notice Register an address at the registry | ||
* @dev This function can be called directly from another Ethereum account. This can be done in | ||
* one step, in one transaction. Coming from Ethereum directly, this method is not as privacy | ||
* preserving as registering an address through the bridge. | ||
* | ||
* @param _to - The address to register | ||
* @return addressCount - the index of address that has been registered | ||
*/ | ||
|
||
function registerAddress(address _to) public returns (uint256) { | ||
uint256 userIndex = addressCount++; | ||
addresses[userIndex] = _to; | ||
emit AddressRegistered(userIndex, _to); | ||
return userIndex; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2022 Aztec. | ||
pragma solidity >=0.8.4; | ||
|
||
import {BaseDeployment} from "../base/BaseDeployment.s.sol"; | ||
import {NFTVault} from "../../bridges/nft-basic/NFTVault.sol"; | ||
import {AddressRegistry} from "../../bridges/registry/AddressRegistry.sol"; | ||
|
||
contract NFTVaultDeployment is BaseDeployment { | ||
function deploy(address _addressRegistry) public returns (address) { | ||
emit log("Deploying NFTVault bridge"); | ||
|
||
vm.broadcast(); | ||
NFTVault bridge = new NFTVault(ROLLUP_PROCESSOR, _addressRegistry); | ||
|
||
emit log_named_address("NFTVault bridge deployed to", address(bridge)); | ||
|
||
return address(bridge); | ||
} | ||
|
||
function deployAndList(address _addressRegistry) public returns (address) { | ||
address bridge = deploy(_addressRegistry); | ||
|
||
uint256 addressId = listBridge(bridge, 135500); | ||
emit log_named_uint("NFTVault bridge address id", addressId); | ||
|
||
return bridge; | ||
} | ||
|
||
function deployAndListAddressRegistry() public returns (address) { | ||
emit log("Deploying AddressRegistry bridge"); | ||
|
||
AddressRegistry bridge = new AddressRegistry(ROLLUP_PROCESSOR); | ||
|
||
emit log_named_address("AddressRegistry bridge deployed to", address(bridge)); | ||
|
||
uint256 addressId = listBridge(address(bridge), 120500); | ||
emit log_named_uint("AddressRegistry bridge address id", addressId); | ||
|
||
return address(bridge); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2022 Aztec. | ||
pragma solidity >=0.8.4; | ||
|
||
import {BaseDeployment} from "../base/BaseDeployment.s.sol"; | ||
import {AddressRegistry} from "../../bridges/registry/AddressRegistry.sol"; | ||
|
||
contract AddressRegistryDeployment is BaseDeployment { | ||
function deploy() public returns (address) { | ||
emit log("Deploying AddressRegistry bridge"); | ||
|
||
vm.broadcast(); | ||
AddressRegistry bridge = new AddressRegistry(ROLLUP_PROCESSOR); | ||
|
||
emit log_named_address("AddressRegistry bridge deployed to", address(bridge)); | ||
|
||
return address(bridge); | ||
} | ||
|
||
function deployAndList() public returns (address) { | ||
address bridge = deploy(); | ||
|
||
uint256 addressId = listBridge(bridge, 120500); | ||
emit log_named_uint("AddressRegistry bridge address id", addressId); | ||
|
||
return bridge; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LHerskind, @benesjan pointed out a griefing attack vector here. someone can register any NFT with any
virtualAssetId
. So if you get a virtual asset id with the intention of registering your NFT, i could just register any NFT in its place, so you can't deposit your NFT--that virtual asset id has been taken. There may be incentive to do this if we build a bridge for NFTs w/ governance rights, or something similar.For a solution, we could have a depositor specify the collection address of the NFT that they want to deposit in step 1 of the deposit flow--they would pass the
id
(from the AddressRegistry) of the address of the collection inauxData
, and during the deposit step theconvert
function would update the collection address in the correspondingnftAssets
mapping. TheNFTAsset
struct would also include aisMatchPending
flag, which would be set to true during the first step of the deposit flow as well.Then in
matchAndPull
, there would be a check to make surenftAssets[_virtualAssetId].collection == _collection
andisMatchPending == true
. Then thenftAssets
mapping entry would be updated with the tokenId and setisMatchPending
to false. This way the only "attack" would be for you to deposit an NFT from the same collection to my aztec account, costing me nothing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, ye, good point. It makes the onboarding a bit more annoying, but ye for high-value cases you could be pretty annoying by frontrunning every time someone tries to
matchAndPull
🤖. It will probably still be a vector for some of the NFTs where many "collections" live under the same address from the same brand. Can't remember the name, but believe one of the larger ones did so, artblocks if I recall correctly. But still much more limited.The other attack still cost you something as you would lose gas money, but that should be small in comparison to the amount to grieve you for any non-valueless NFT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatives
we could require that the collection and the tokenId are passed in step 1 of the deposit, so it's not ambiguous which token the virtual asset is for. Then we wouldn't need the
isMatchPending
flag, since the virtual asset is only good for 1 token.we could add another field to
NFTAsset
that specifies anaddress
that can deposit NFTs to that virtual asset.I think 1 might be the best solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no
isMatchPending
in the NFTVault contract.If you are using the
auxData
you would be able to fit most thing in, but sometokenId
s would not fit.I think going with sol 1 is probably a good way to handle it yes. If you update
NFTAsset
to be a struct of 3 elements, you can write the collection andtokenId
directly and then it is just the flag for it being "deposited" that needs to be updated when matched? So storage wise should not be too different in costs. If we are anyway using theauxData
such that not all can fit in, these 3 elements can also fit into one slot, so gas costs gets a bit lower with the restriction that addressable NFT space.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I was just building off of the solution suggested in the first comment.
If we have users specify the collection and
tokenId
, do you think we need theisInEscrow
flag?With the restriction of specifying all of the token info in the first step of a deposit, a virtual asset id will always only be associated with 1 NFT. You'd be able to tell if the NFT was in escrow by looking up the owner of the NFT on the NFT contract. It might be a bit more convenient to do it with the
isInEscrow
flag in the NFTVault, but not sure if it is worth it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also just thinking that if we pass the current NFT owner, collection and tokenId into the deposit flow, we can deposit the NFT into aztec in 1 transaction.
The owner will need to approve the bridge to do a
transferFrom
beforehand, but they could pass the owner totransferFrom
as an id from the address registry as well.This would be a better UX, but would be more restrictive in terms of input options.
owner
andcollection
could each be 20 bits and offer ~1 million options each.tokenId
could be 24 bits and offer ~17 million options.Do you foresee any problems with this approach? I think the UX improvements would be worth the input limitations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the owner approves the NFT beforehand. Anyone can claim it. The contract should only ever pull NFTs or tokens from
msg.sender
, otherwise, you could use the rollup to steal the approved NFTs where the thief even will be hidden while doing it.