Skip to content

Commit

Permalink
fix(protocol): revert impl deployment V2 (#14621)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Wang <99078276+dantaik@users.noreply.github.com>
Co-authored-by: Daniel Wang <dong77@gmail.com>
  • Loading branch information
3 people committed Sep 3, 2023
1 parent 148d6aa commit 7e59e0b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 23 deletions.
23 changes: 14 additions & 9 deletions packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);
}
}
}
24 changes: 19 additions & 5 deletions packages/protocol/contracts/tokenvault/ERC1155Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
35 changes: 28 additions & 7 deletions packages/protocol/contracts/tokenvault/ERC20Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,23 @@ 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,
address to,
uint256 amount
)
private
returns (bytes memory msgData, uint256 _amount)
returns (bytes memory msgData, uint256 _balanceChange)
{
CanonicalERC20 memory ctoken;

Expand All @@ -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);
Expand All @@ -298,23 +307,26 @@ 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({
from: msg.sender,
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)
Expand All @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions packages/protocol/contracts/tokenvault/ERC721Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7e59e0b

Please sign in to comment.