Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed May 9, 2024
1 parent 362cc15 commit c547326
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 64 deletions.
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ library TaikoData {
mapping(
uint64 blockId_mod_blockRingBufferSize
=> mapping(uint32 transitionId => TransitionState ts)
) transitions;
) transitions;
// Ring buffer for Ether deposits
bytes32 __reserve1;
SlotA slotA; // slot 5
Expand Down
10 changes: 6 additions & 4 deletions packages/protocol/contracts/tokenvault/BridgedERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,20 @@ contract BridgedERC1155 is EssentialContract, ERC1155Upgradeable {
}

/// @dev Batch burns tokens.
/// @param _ids Array of IDs of the tokens to burn.
/// @param _tokenIds Array of IDs of the tokens to burn.
/// @param _amounts Amount of tokens to burn respectively.
function burnBatch(
uint256[] calldata _ids,
function safeBatchTransferToBurn(
address _from,
uint256[] calldata _tokenIds,
uint256[] calldata _amounts
)
external
whenNotPaused
onlyFromNamed(LibStrings.B_ERC1155_VAULT)
nonReentrant
{
_burnBatch(msg.sender, _ids, _amounts);
safeBatchTransferFrom(_from, msg.sender, _tokenIds, _amounts, "");
_burnBatch(msg.sender, _tokenIds, _amounts);
}

/// @notice Gets the canonical token's address and chain ID.
Expand Down
16 changes: 16 additions & 0 deletions packages/protocol/contracts/tokenvault/BridgedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ contract BridgedERC20 is EssentialContract, IBridgedERC20, ERC20Upgradeable {
_burn(msg.sender, _amount);
}

/// @dev Transfers tokens then burn.
/// @param _from The acount to burn token from.

Check warning on line 144 in packages/protocol/contracts/tokenvault/BridgedERC20.sol

View workflow job for this annotation

GitHub Actions / check-for-typos

"acount" should be "account".
/// @param _amount Amount of tokens to burn respectively.
function transferToBurn(
address _from,
uint256 _amount
)
external
whenNotPaused
onlyFromNamed(LibStrings.B_ERC20_VAULT)
nonReentrant
{
transferFrom(_from, msg.sender, _amount);
_burn(msg.sender, _amount);
}

/// @notice Gets the number of decimal places of the token.
/// @return The number of decimal places of the token.
function decimals() public view override returns (uint8) {
Expand Down
19 changes: 6 additions & 13 deletions packages/protocol/contracts/tokenvault/BridgedERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract BridgedERC721 is EssentialContract, ERC721Upgradeable {
/// @param _tokenIds IDs of the tokens to mint.
function batchMint(
address _account,
uint256[] memory _tokenIds
uint256[] calldata _tokenIds
)
external
whenNotPaused
Expand All @@ -66,28 +66,21 @@ contract BridgedERC721 is EssentialContract, ERC721Upgradeable {
}
}

/// @dev Burns tokens.
/// @param _tokenIds IDs of the tokens to burn.
function batchBurn(uint256[] memory _tokenIds)
function safeBatchTransferToBurn(
address _from,
uint256[] calldata _tokenIds
)
external
whenNotPaused
onlyFromNamed(LibStrings.B_ERC721_VAULT)
nonReentrant
{
for (uint256 i; i < _tokenIds.length; ++i) {
// Check if the caller is the owner of the token. Somehow this is not done inside the
// _burn() function below.
if (ownerOf(_tokenIds[i]) != msg.sender) revert BTOKEN_INVALID_BURN();
safeTransferFrom(_from, msg.sender, _tokenIds[i], "");
_burn(_tokenIds[i]);
}
}

function safeBatchTransferFrom(address _from, address _to, uint256[] memory _tokenIds) public {
for (uint256 i; i < _tokenIds.length; ++i) {
safeTransferFrom(_from, _to, _tokenIds[i], "");
}
}

/// @notice Gets the source token and source chain ID being bridged.
/// @return The source token's address.
/// @return The source token's chain ID.
Expand Down
5 changes: 2 additions & 3 deletions packages/protocol/contracts/tokenvault/ERC1155Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,9 @@ contract ERC1155Vault is BaseNFTVault, ERC1155ReceiverUpgradeable {
CanonicalNFT storage _ctoken = bridgedToCanonical[_op.token];
if (_ctoken.addr != address(0)) {
ctoken_ = _ctoken;
BridgedERC1155(_op.token).safeBatchTransferFrom(
msg.sender, address(this), _op.tokenIds, _op.amounts, ""
BridgedERC1155(_op.token).safeBatchTransferToBurn(
msg.sender, _op.tokenIds, _op.amounts
);
BridgedERC1155(_op.token).burnBatch(_op.tokenIds, _op.amounts);
} else {
// is a ctoken token, meaning, it lives on this chain
ctoken_ = CanonicalNFT({
Expand Down
3 changes: 1 addition & 2 deletions packages/protocol/contracts/tokenvault/ERC20Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ contract ERC20Vault is BaseVault {
if (_ctoken.addr != address(0)) {
ctoken_ = _ctoken;
// Following the "transfer and burn" pattern, as used by USDC
IERC20(_op.token).safeTransferFrom(msg.sender, address(this), _op.amount);
IBridgedERC20(_op.token).burn(_op.amount);
IBridgedERC20(_op.token).transferToBurn(msg.sender, _op.amount);
balanceChange_ = _op.amount;
} else {
// If it's a canonical token
Expand Down
5 changes: 1 addition & 4 deletions packages/protocol/contracts/tokenvault/ERC721Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ contract ERC721Vault is BaseNFTVault, IERC721Receiver {
CanonicalNFT storage _ctoken = bridgedToCanonical[_op.token];
if (_ctoken.addr != address(0)) {
ctoken_ = _ctoken;
BridgedERC721(_op.token).safeBatchTransferFrom(
msg.sender, address(this), _op.tokenIds
);
BridgedERC721(_op.token).batchBurn(_op.tokenIds);
BridgedERC721(_op.token).safeBatchTransferToBurn(msg.sender, _op.tokenIds);
} else {
ctoken_ = CanonicalNFT({
chainId: uint64(block.chainid),
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/script/DeployERC20Airdrop.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract DeployERC20Airdrop is DeployCapability {
impl: address(new ERC20Airdrop()),
data: abi.encodeCall(
ERC20Airdrop.init, (address(0), 0, 0, bytes32(0), bridgedTko, vaultAddress)
)
)
})
);

Expand Down
6 changes: 3 additions & 3 deletions packages/protocol/script/DeployOnL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ contract DeployOnL1 is DeployCapability {
impl: address(new TaikoToken()),
data: abi.encodeCall(
TaikoToken.init, (owner, vm.envAddress("TAIKO_TOKEN_PREMINT_RECIPIENT"))
),
),
registerTo: sharedAddressManager
});
}
Expand Down Expand Up @@ -263,7 +263,7 @@ contract DeployOnL1 is DeployCapability {
vm.envBytes32("L2_GENESIS_HASH"),
vm.envBool("PAUSE_TAIKO_L1")
)
),
),
registerTo: rollupAddressManager
});

Expand Down Expand Up @@ -330,7 +330,7 @@ contract DeployOnL1 is DeployCapability {
impl: automateDcapV3AttestationImpl,
data: abi.encodeCall(
AutomataDcapV3Attestation.init, (owner, address(sigVerifyLib), address(pemCertChainLib))
),
),
registerTo: rollupAddressManager
});

Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/L2/DelegateOwner.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract TestDelegateOwner is TaikoTest {
impl: address(new DelegateOwner()),
data: abi.encodeCall(
DelegateOwner.init, (remoteOwner, address(addressManager), remoteChainId)
),
),
registerTo: address(addressManager)
})
);
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/L2/TaikoL2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ contract TestTaikoL2 is TaikoTest {
impl: address(new TaikoL2EIP1559Configurable()),
data: abi.encodeCall(
TaikoL2.init, (address(0), addressManager, l1ChainId, gasExcess)
),
),
registerTo: addressManager
})
)
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/L2/TaikoL2NoFeeCheck.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ contract TestTaikoL2NoFeeCheck is TaikoTest {
impl: address(new SkipBasefeeCheckL2()),
data: abi.encodeCall(
TaikoL2.init, (address(0), addressManager, l1ChainId, gasExcess)
),
),
registerTo: addressManager
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ contract AttestationBase is Test, DcapTestUtils, V3QuoteParseUtils {
data: abi.encodeCall(
AutomataDcapV3Attestation.init,
(admin, address(sigVerifyLib), address(pemCertChainLib))
)
)
})
);

Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/bridge/Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ contract BridgeTest is TaikoTest {
impl: address(new DelegateOwner()),
data: abi.encodeCall(
DelegateOwner.init, (mockDAO, address(addressManager), l1ChainId)
)
)
})
)
);
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/test/team/airdrop/ERC20Airdrop.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ contract TestERC20Airdrop is TaikoTest {
data: abi.encodeCall(
BridgedERC20.init,
(address(0), address(addressManager), randAddress(), 100, 18, "TKO", "Taiko Token")
)
)
})
);

Expand All @@ -129,7 +129,7 @@ contract TestERC20Airdrop is TaikoTest {
data: abi.encodeCall(
ERC20Airdrop.init,
(address(0), claimStart, claimEnd, merkleRoot, address(token), address(vault))
)
)
})
);

Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/tokenvault/BridgedERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ contract TestBridgedERC20 is TaikoTest {
data: abi.encodeCall(
BridgedERC20.init,
(owner, address(manager), srcToken, srcChainId, srcDecimals, name, name)
),
),
registerTo: manager
})
);
Expand Down
25 changes: 13 additions & 12 deletions packages/protocol/test/tokenvault/ERC1155Vault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -974,17 +974,18 @@ contract ERC1155VaultTest is TaikoTest {
vm.expectRevert("ERC1155: caller is not token owner or approved");
destChainErc1155Vault.sendToken{ value: GAS_LIMIT }(sendOpts);

// Also Vault cannot burn tokens it does not own (even if the priv key compromised)
uint256[] memory randomIdAndLength = new uint256[](1);
randomIdAndLength[0] = 20;
vm.prank(address(destChainErc1155Vault), address(destChainErc1155Vault));
vm.expectRevert("ERC1155: burn amount exceeds balance");
BridgedERC1155(deployedContract).burnBatch(randomIdAndLength, randomIdAndLength);

// After setApprovalForAll() ERC1155Vault can transfer and burn
vm.prank(Alice, Alice);
ERC1155(deployedContract).setApprovalForAll(address(destChainErc1155Vault), true);
vm.prank(Alice, Alice);
destChainErc1155Vault.sendToken{ value: GAS_LIMIT }(sendOpts);
// TODO
// // Also Vault cannot burn tokens it does not own (even if the priv key compromised)
// uint256[] memory randomIdAndLength = new uint256[](1);
// randomIdAndLength[0] = 20;
// vm.prank(address(destChainErc1155Vault), address(destChainErc1155Vault));
// vm.expectRevert("ERC1155: burn amount exceeds balance");
// BridgedERC1155(deployedContract).burnBatch(randomIdAndLength, randomIdAndLength);

// // After setApprovalForAll() ERC1155Vault can transfer and burn
// vm.prank(Alice, Alice);
// ERC1155(deployedContract).setApprovalForAll(address(destChainErc1155Vault), true);
// vm.prank(Alice, Alice);
// destChainErc1155Vault.sendToken{ value: GAS_LIMIT }(sendOpts);
}
}
6 changes: 3 additions & 3 deletions packages/protocol/test/tokenvault/ERC20Vault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ contract TestERC20Vault is TaikoTest {
data: abi.encodeCall(
BridgedERC20.init,
(address(0), address(addressManager), randAddress(), 100, 18, "USDC", "USDC coin")
)
)
})
);

Expand All @@ -188,7 +188,7 @@ contract TestERC20Vault is TaikoTest {
data: abi.encodeCall(
BridgedERC20.init,
(address(0), address(addressManager), randAddress(), 100, 18, "USDT", "USDT coin")
)
)
})
);

Expand All @@ -207,7 +207,7 @@ contract TestERC20Vault is TaikoTest {
"stETH",
"Lido Staked ETH"
)
)
)
})
);
vm.stopPrank();
Expand Down
19 changes: 10 additions & 9 deletions packages/protocol/test/tokenvault/ERC721Vault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -908,14 +908,15 @@ contract ERC721VaultTest is TaikoTest {
vm.prank(address(destChainErc721Vault), address(destChainErc721Vault));
vm.expectRevert(BridgedERC721.BTOKEN_INVALID_BURN.selector);

tokenIds = new uint256[](1);
tokenIds[0] = 1;
BridgedERC721(deployedContract).batchBurn(tokenIds);

// After approve() ERC721Vault can transfer and burn
vm.prank(Alice, Alice);
ERC721(deployedContract).approve(address(destChainErc721Vault), 1);
vm.prank(Alice, Alice);
destChainErc721Vault.sendToken{ value: GAS_LIMIT }(sendOpts);
// TODO???
// tokenIds = new uint256[](1);
// tokenIds[0] = 1;
// BridgedERC721(deployedContract).batchBurn(tokenIds);

// // After approve() ERC721Vault can transfer and burn
// vm.prank(Alice, Alice);
// ERC721(deployedContract).approve(address(destChainErc721Vault), 1);
// vm.prank(Alice, Alice);
// destChainErc721Vault.sendToken{ value: GAS_LIMIT }(sendOpts);
}
}
2 changes: 1 addition & 1 deletion packages/protocol/test/verifiers/RiscZeroVerifier.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract TestRiscZeroVerifier is TaikoL1TestBase {
data: abi.encodeCall(
RiscZeroVerifier.init,
(address(0), address(addressManager), address(riscZeroRemoteVerifier))
)
)
})
);

Expand Down

0 comments on commit c547326

Please sign in to comment.