-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from 0xPolygonHermez/feature/claimCompressorO…
…ngoing Feature/claim compressor ongoing
- Loading branch information
Showing
9 changed files
with
1,346 additions
and
24 deletions.
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
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,164 @@ | ||
// SPDX-License-Identifier: AGPL-3.0 | ||
|
||
import "../PolygonZkEVMBridgeV2.sol"; | ||
pragma solidity 0.8.20; | ||
|
||
/** | ||
* Contract for compressing and decompressing claim data | ||
*/ | ||
contract BridgeReceiverMock { | ||
uint256 internal constant _DEPOSIT_CONTRACT_TREE_DEPTH = 32; | ||
|
||
event FallbackEvent(bytes calldataBytes); | ||
|
||
/** | ||
* @dev Emitted when bridge assets or messages to another network | ||
*/ | ||
event ClaimAsset( | ||
bytes32[_DEPOSIT_CONTRACT_TREE_DEPTH] smtProofLocalExitRoot, | ||
bytes32[_DEPOSIT_CONTRACT_TREE_DEPTH] smtProofRollupExitRoot, | ||
uint256 globalIndex, | ||
bytes32 mainnetExitRoot, | ||
bytes32 rollupExitRoot, | ||
uint32 originNetwork, | ||
address originTokenAddress, | ||
uint32 destinationNetwork, | ||
address destinationAddress, | ||
uint256 amount, | ||
bytes metadata | ||
); | ||
|
||
/** | ||
* @dev Emitted when bridge assets or messages to another network | ||
*/ | ||
event ClaimMessage( | ||
bytes32[_DEPOSIT_CONTRACT_TREE_DEPTH] smtProofLocalExitRoot, | ||
bytes32[_DEPOSIT_CONTRACT_TREE_DEPTH] smtProofRollupExitRoot, | ||
uint256 globalIndex, | ||
bytes32 mainnetExitRoot, | ||
bytes32 rollupExitRoot, | ||
uint32 originNetwork, | ||
address originTokenAddress, | ||
uint32 destinationNetwork, | ||
address destinationAddress, | ||
uint256 amount, | ||
bytes metadata | ||
); | ||
|
||
/** | ||
* @notice Verify merkle proof and withdraw tokens/ether | ||
* @param smtProofLocalExitRoot Smt proof to proof the leaf against the network exit root | ||
* @param smtProofRollupExitRoot Smt proof to proof the rollupLocalExitRoot against the rollups exit root | ||
* @param globalIndex Global index is defined as: | ||
* | 191 bits | 1 bit | 32 bits | 32 bits | | ||
* | 0 | mainnetFlag | rollupIndex | localRootIndex | | ||
* note that only the rollup index will be used only in case the mainnet flag is 0 | ||
* note that global index do not assert the unused bits to 0. | ||
* This means that when synching the events, the globalIndex must be decoded the same way that in the Smart contract | ||
* to avoid possible synch attacks | ||
* @param mainnetExitRoot Mainnet exit root | ||
* @param rollupExitRoot Rollup exit root | ||
* @param originNetwork Origin network | ||
* @param originTokenAddress Origin token address, 0 address is reserved for ether | ||
* @param destinationNetwork Network destination | ||
* @param destinationAddress Address destination | ||
* @param amount Amount of tokens | ||
* @param metadata Abi encoded metadata if any, empty otherwise | ||
*/ | ||
function claimAsset( | ||
bytes32[_DEPOSIT_CONTRACT_TREE_DEPTH] calldata smtProofLocalExitRoot, | ||
bytes32[_DEPOSIT_CONTRACT_TREE_DEPTH] calldata smtProofRollupExitRoot, | ||
uint256 globalIndex, | ||
bytes32 mainnetExitRoot, | ||
bytes32 rollupExitRoot, | ||
uint32 originNetwork, | ||
address originTokenAddress, | ||
uint32 destinationNetwork, | ||
address destinationAddress, | ||
uint256 amount, | ||
bytes calldata metadata | ||
) external { | ||
emit ClaimAsset( | ||
smtProofLocalExitRoot, | ||
smtProofRollupExitRoot, | ||
globalIndex, | ||
mainnetExitRoot, | ||
rollupExitRoot, | ||
originNetwork, | ||
originTokenAddress, | ||
destinationNetwork, | ||
destinationAddress, | ||
amount, | ||
metadata | ||
); | ||
} | ||
|
||
/** | ||
* @notice Verify merkle proof and execute message | ||
* If the receiving address is an EOA, the call will result as a success | ||
* Which means that the amount of ether will be transferred correctly, but the message | ||
* will not trigger any execution | ||
* @param smtProofLocalExitRoot Smt proof to proof the leaf against the exit root | ||
* @param smtProofRollupExitRoot Smt proof to proof the rollupLocalExitRoot against the rollups exit root | ||
* @param globalIndex Global index is defined as: | ||
* | 191 bits | 1 bit | 32 bits | 32 bits | | ||
* | 0 | mainnetFlag | rollupIndex | localRootIndex | | ||
* note that only the rollup index will be used only in case the mainnet flag is 0 | ||
* note that global index do not assert the unused bits to 0. | ||
* This means that when synching the events, the globalIndex must be decoded the same way that in the Smart contract | ||
* to avoid possible synch attacks | ||
* @param mainnetExitRoot Mainnet exit root | ||
* @param rollupExitRoot Rollup exit root | ||
* @param originNetwork Origin network | ||
* @param originAddress Origin address | ||
* @param destinationNetwork Network destination | ||
* @param destinationAddress Address destination | ||
* @param amount message value | ||
* @param metadata Abi encoded metadata if any, empty otherwise | ||
*/ | ||
function claimMessage( | ||
bytes32[_DEPOSIT_CONTRACT_TREE_DEPTH] calldata smtProofLocalExitRoot, | ||
bytes32[_DEPOSIT_CONTRACT_TREE_DEPTH] calldata smtProofRollupExitRoot, | ||
uint256 globalIndex, | ||
bytes32 mainnetExitRoot, | ||
bytes32 rollupExitRoot, | ||
uint32 originNetwork, | ||
address originAddress, | ||
uint32 destinationNetwork, | ||
address destinationAddress, | ||
uint256 amount, | ||
bytes calldata metadata | ||
) external { | ||
// assembly { | ||
// let ptr := mload(0x40) | ||
|
||
// let size := add(calldatasize(), 28) // 4 bytes calldata | ||
|
||
// mstore(ptr, 0x20) // dataPos | ||
|
||
// mstore(add(ptr, 0x20), size) // data len | ||
|
||
// calldatacopy(add(ptr, 0x40), 0, size) // data | ||
|
||
// return(ptr, add(size, 0x40)) | ||
// } | ||
|
||
emit ClaimMessage( | ||
smtProofLocalExitRoot, | ||
smtProofRollupExitRoot, | ||
globalIndex, | ||
mainnetExitRoot, | ||
rollupExitRoot, | ||
originNetwork, | ||
originAddress, | ||
destinationNetwork, | ||
destinationAddress, | ||
amount, | ||
metadata | ||
); | ||
} | ||
|
||
fallback() external { | ||
emit FallbackEvent(msg.data); | ||
} | ||
} |
Oops, something went wrong.