diff --git a/packages/protocol/contracts/L1/libs/LibProving.sol b/packages/protocol/contracts/L1/libs/LibProving.sol index 7658ec0bee0..a8052604405 100644 --- a/packages/protocol/contracts/L1/libs/LibProving.sol +++ b/packages/protocol/contracts/L1/libs/LibProving.sol @@ -166,14 +166,19 @@ library LibProving { pure returns (bytes32 instance) { - if (evidence.prover == LibUtils.ORACLE_PROVER) return 0; - else return keccak256(abi.encode( - evidence.metaHash, - evidence.parentHash, - evidence.blockHash, - evidence.signalRoot, - evidence.graffiti, - evidence.prover - )); + if (evidence.prover == LibUtils.ORACLE_PROVER) { + return 0; + } else { + return keccak256( + abi.encode( + evidence.metaHash, + evidence.parentHash, + evidence.blockHash, + evidence.signalRoot, + evidence.graffiti, + evidence.prover + ) + ); + } } } diff --git a/packages/protocol/contracts/tokenvault/ERC1155Vault.sol b/packages/protocol/contracts/tokenvault/ERC1155Vault.sol index 5e42f772709..d8ebe768317 100644 --- a/packages/protocol/contracts/tokenvault/ERC1155Vault.sol +++ b/packages/protocol/contracts/tokenvault/ERC1155Vault.sol @@ -261,6 +261,10 @@ contract ERC1155Vault is BaseNFTVault, ERC1155ReceiverUpgradeable { || super.supportsInterface(interfaceId); } + /// @dev Encodes sending bridged or canonical ERC1155 tokens to the user. + /// @param user The user's address. + /// @param opt BridgeTransferOp data. + /// @return msgData Encoded message data. function _encodeDestinationCall( address user, BridgeTransferOp memory opt @@ -314,7 +318,9 @@ contract ERC1155Vault is BaseNFTVault, ERC1155ReceiverUpgradeable { ); } - /// @dev Returns the contract address per given canonical token. + /// @dev Retrieve or deploy a bridged ERC1155 token contract. + /// @param ctoken CanonicalNFT data. + /// @return btoken Address of the bridged token contract. function _getOrDeployBridgedToken(CanonicalNFT memory ctoken) private returns (address btoken) @@ -325,18 +331,26 @@ contract ERC1155Vault is BaseNFTVault, ERC1155ReceiverUpgradeable { } } - /// @dev Deploys a new BridgedNFT contract and initializes it. This must be - /// called before the first time a btoken is sent to this chain. + /// @dev Deploy a new BridgedNFT contract and initialize it. + /// This must be called before the first time a bridged token is sent to + /// this chain. + /// @param ctoken CanonicalNFT data. + /// @return btoken Address of the deployed bridged token contract. function _deployBridgedToken(CanonicalNFT memory ctoken) private returns (address btoken) { - ProxiedBridgedERC1155 bridgedToken = new ProxiedBridgedERC1155(); + address bridgedToken = Create2Upgradeable.deploy({ + amount: 0, // amount of Ether to send + salt: keccak256(abi.encode(ctoken)), + bytecode: type(ProxiedBridgedERC1155).creationCode + }); + btoken = LibVaultUtils.deployProxy( address(bridgedToken), owner(), bytes.concat( - bridgedToken.init.selector, + ProxiedBridgedERC1155(bridgedToken).init.selector, abi.encode( address(_addressManager), ctoken.addr, diff --git a/packages/protocol/contracts/tokenvault/ERC20Vault.sol b/packages/protocol/contracts/tokenvault/ERC20Vault.sol index 867a17152d1..45b1eb84f21 100644 --- a/packages/protocol/contracts/tokenvault/ERC20Vault.sol +++ b/packages/protocol/contracts/tokenvault/ERC20Vault.sol @@ -268,6 +268,15 @@ contract ERC20Vault is return interfaceId == type(IRecallableMessageSender).interfaceId; } + /// @dev Encodes sending bridged or canonical ERC20 tokens to the user. + /// @param user The user's address. + /// @param token The token address. + /// @param to To address. + /// @param amount Amount to be sent. + /// @return msgData Encoded message data. + /// @return _balanceChange User token balance actual change after the token + /// transfer. This value is calculated so we do not assume token balance + /// change is the amount of token transfered away. function _encodeDestinationCall( address user, address token, @@ -275,7 +284,7 @@ contract ERC20Vault is uint256 amount ) private - returns (bytes memory msgData, uint256 _amount) + returns (bytes memory msgData, uint256 _balanceChange) { CanonicalERC20 memory ctoken; @@ -284,7 +293,7 @@ contract ERC20Vault is ctoken = bridgedToCanonical[token]; assert(ctoken.addr != address(0)); IMintableERC20(token).burn(msg.sender, amount); - _amount = amount; + _balanceChange = amount; } else { // If it's a canonical token ERC20Upgradeable t = ERC20Upgradeable(token); @@ -298,7 +307,7 @@ contract ERC20Vault is if (token == resolve("taiko_token", true)) { IMintableERC20(token).burn(msg.sender, amount); - _amount = amount; + _balanceChange = amount; } else { uint256 _balance = t.balanceOf(address(this)); t.transferFrom({ @@ -306,15 +315,18 @@ contract ERC20Vault is to: address(this), amount: amount }); - _amount = t.balanceOf(address(this)) - _balance; + _balanceChange = t.balanceOf(address(this)) - _balance; } } msgData = abi.encodeWithSelector( - ERC20Vault.receiveToken.selector, ctoken, user, to, _amount + ERC20Vault.receiveToken.selector, ctoken, user, to, _balanceChange ); } + /// @dev Retrieve or deploy a bridged ERC20 token contract. + /// @param ctoken CanonicalERC20 data. + /// @return btoken Address of the bridged token contract. function _getOrDeployBridgedToken(CanonicalERC20 calldata ctoken) private returns (address btoken) @@ -326,17 +338,26 @@ contract ERC20Vault is } } + /// @dev Deploy a new BridgedERC20 contract and initialize it. + /// This must be called before the first time a bridged token is sent to + /// this chain. + /// @param ctoken CanonicalERC20 data. + /// @return btoken Address of the deployed bridged token contract. function _deployBridgedToken(CanonicalERC20 calldata ctoken) private returns (address btoken) { - ProxiedBridgedERC20 bridgedToken = new ProxiedBridgedERC20(); + address bridgedToken = Create2Upgradeable.deploy({ + amount: 0, // amount of Ether to send + salt: keccak256(abi.encode(ctoken)), + bytecode: type(ProxiedBridgedERC20).creationCode + }); btoken = LibVaultUtils.deployProxy( address(bridgedToken), owner(), bytes.concat( - bridgedToken.init.selector, + ProxiedBridgedERC20(bridgedToken).init.selector, abi.encode( address(_addressManager), ctoken.addr, diff --git a/packages/protocol/contracts/tokenvault/ERC721Vault.sol b/packages/protocol/contracts/tokenvault/ERC721Vault.sol index bf3925405e1..70b2fa029e5 100644 --- a/packages/protocol/contracts/tokenvault/ERC721Vault.sol +++ b/packages/protocol/contracts/tokenvault/ERC721Vault.sol @@ -281,13 +281,17 @@ contract ERC721Vault is BaseNFTVault, IERC721Receiver, IERC165Upgradeable { private returns (address btoken) { - ProxiedBridgedERC721 bridgedToken = new ProxiedBridgedERC721(); + address bridgedToken = Create2Upgradeable.deploy({ + amount: 0, // amount of Ether to send + salt: keccak256(abi.encode(ctoken)), + bytecode: type(ProxiedBridgedERC721).creationCode + }); btoken = LibVaultUtils.deployProxy( address(bridgedToken), owner(), bytes.concat( - bridgedToken.init.selector, + ProxiedBridgedERC721(bridgedToken).init.selector, abi.encode( address(_addressManager), ctoken.addr,