From a581ec61521e99d6c065b6f4afa5a00f4846d9ef Mon Sep 17 00:00:00 2001 From: cyl19970726 <15258378443@163.com> Date: Sun, 26 Jun 2022 22:31:12 +0800 Subject: [PATCH 1/3] add w3ip-6 --- W3IPS/w3ip-6.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 W3IPS/w3ip-6.md diff --git a/W3IPS/w3ip-6.md b/W3IPS/w3ip-6.md new file mode 100644 index 0000000..0cc0342 --- /dev/null +++ b/W3IPS/w3ip-6.md @@ -0,0 +1,63 @@ +--- +w3ip: 6 +title: Add external calls within consensus mechanism +author: 0xhhh https://github.com/cyl19970726 +discussions-to: +status: Draft +type: Standards +Track category: Core +created: 2022-06-25 +requires: W3IP-2 +--- + + +## Simple Summary + +Support Web3Q to directly call Ethereum's on-chain data in transactions. + +## Abstract + +Any account can make a cross-chain data call by calling the precompiled contract in the initiated transaction. If the Web3Q Proposer receives a transaction with cross-chain call data, it will put the result of the cross-chain call in `receipt.externalCallResult`, and Participate in the generation of the merkle root of receipt trie, so as to include the result of the cross-chain call into the proposer block. +The validators of Web3Q will re-execute these transactions including the cross-chain call and participate in the generation of a new receipt root with their results. +Then the validator can verify the correctness of the cross-chain call by verifying whether the receipt root is consistent with the receipt root in the proposer block. +Therefore, Web3Q cross-chain call is combined with Web3Q's block generation consensus, and the security of cross-chain call is equivalent to that of Web3Q. + +## Motivation + +1. Web3Q is the sidechain of ethereum, each Web3Q validator needs to run an Ethereum node, so the validators is born with the ability to verify the results of cross-chain calls. +2. The security of Web3Q cross-chain calls is equivalent to the security of web3q, which can greatly improve the cross-chain security of the Web3Q bridge. + +## Specification + +1. Perform cross-chain calls within a contract +We implemented a precompiled contract at address 0x00000000000000000000000000000000033303 to perform cross-chain calls. +At present, we provide a getLogByTxHash method in this precompiled contract to call the log data of ethereum. +``` +getLogByTxHash(uint256 chainId , bytes32 txHash, uint256 logIdx ,uint256 maxDataLen, uint256 confirms) +``` +- chainId: The chainId of the target chain of the cross-chain call. +- txHash: Transaction hash on the target chain. +- logIdx: The index of the log to be obtained in the corresponding transaction. +- maxDataLen: Maximum length of log.data. +- confirms: The number of block confirmations required for this transaction + +2. You can view the result of the cross-chain call via eth.getTransaction and eth.getTransactionReceipt. +Web3Q added an `externalCallResult` property to the results of eth.getTransaction and eth.getTransactionReceipt. + +### Parameters + +| Constant | Value | +| ------------------------- | ---------------- | +| `ExternalCallByteGasCost` | 30 | +| `ExternalCallGas` | 10000 | + +For the gas cost of cross-chain calls, follow the formula below: +```Gas Cost = ExternalCallGas + len(ExternalCallResult) * ExternalCallByteGasCost```. + +## Rationale + +Web3Q cross-chain call is combined with Web3Q's block generation consensus, and the security of cross-chain call is equivalent to that of Web3Q. + +## Copyright + +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). From 2d5de7a9004ee2d3cc0168a3b7a2ed427158bc72 Mon Sep 17 00:00:00 2001 From: cyl19970726 <15258378443@163.com> Date: Mon, 27 Jun 2022 15:49:37 +0800 Subject: [PATCH 2/3] update --- W3IPS/w3ip-6.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/W3IPS/w3ip-6.md b/W3IPS/w3ip-6.md index 0cc0342..36c1702 100644 --- a/W3IPS/w3ip-6.md +++ b/W3IPS/w3ip-6.md @@ -30,8 +30,8 @@ Therefore, Web3Q cross-chain call is combined with Web3Q's block generation cons ## Specification 1. Perform cross-chain calls within a contract -We implemented a precompiled contract at address 0x00000000000000000000000000000000033303 to perform cross-chain calls. -At present, we provide a getLogByTxHash method in this precompiled contract to call the log data of ethereum. +We implemented a precompiled contract at address `0x00000000000000000000000000000000033303` to perform cross-chain calls. +At present, we provide a `getLogByTxHash` method in this precompiled contract to call the log data of ethereum. ``` getLogByTxHash(uint256 chainId , bytes32 txHash, uint256 logIdx ,uint256 maxDataLen, uint256 confirms) ``` @@ -42,7 +42,7 @@ getLogByTxHash(uint256 chainId , bytes32 txHash, uint256 logIdx ,uint256 maxData - confirms: The number of block confirmations required for this transaction 2. You can view the result of the cross-chain call via eth.getTransaction and eth.getTransactionReceipt. -Web3Q added an `externalCallResult` property to the results of eth.getTransaction and eth.getTransactionReceipt. +Web3Q added an `externalCallResult` property to the results of `eth_getTransaction` and `eth_getTransactionReceipt`. ### Parameters From d61dea271e2da93679040d3c08eabfc6f4ddbcf1 Mon Sep 17 00:00:00 2001 From: cyl19970726 <15258378443@163.com> Date: Tue, 28 Jun 2022 10:46:56 +0800 Subject: [PATCH 3/3] update the w3ip-6 --- W3IPS/w3ip-6.md | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/W3IPS/w3ip-6.md b/W3IPS/w3ip-6.md index 36c1702..431a176 100644 --- a/W3IPS/w3ip-6.md +++ b/W3IPS/w3ip-6.md @@ -7,7 +7,7 @@ status: Draft type: Standards Track category: Core created: 2022-06-25 -requires: W3IP-2 +requires: --- @@ -18,6 +18,7 @@ Support Web3Q to directly call Ethereum's on-chain data in transactions. ## Abstract Any account can make a cross-chain data call by calling the precompiled contract in the initiated transaction. If the Web3Q Proposer receives a transaction with cross-chain call data, it will put the result of the cross-chain call in `receipt.externalCallResult`, and Participate in the generation of the merkle root of receipt trie, so as to include the result of the cross-chain call into the proposer block. + The validators of Web3Q will re-execute these transactions including the cross-chain call and participate in the generation of a new receipt root with their results. Then the validator can verify the correctness of the cross-chain call by verifying whether the receipt root is consistent with the receipt root in the proposer block. Therefore, Web3Q cross-chain call is combined with Web3Q's block generation consensus, and the security of cross-chain call is equivalent to that of Web3Q. @@ -29,27 +30,46 @@ Therefore, Web3Q cross-chain call is combined with Web3Q's block generation cons ## Specification -1. Perform cross-chain calls within a contract +### Perform cross-chain calls within a contract We implemented a precompiled contract at address `0x00000000000000000000000000000000033303` to perform cross-chain calls. At present, we provide a `getLogByTxHash` method in this precompiled contract to call the log data of ethereum. ``` getLogByTxHash(uint256 chainId , bytes32 txHash, uint256 logIdx ,uint256 maxDataLen, uint256 confirms) ``` +#### params - chainId: The chainId of the target chain of the cross-chain call. - txHash: Transaction hash on the target chain. - logIdx: The index of the log to be obtained in the corresponding transaction. - maxDataLen: Maximum length of log.data. - confirms: The number of block confirmations required for this transaction +#### returns +##### no happen error +- Encode `log.address` into an `address` type through `abi.encode` +- Encode `log.topics` into an `bytes32[]` type through `abi.encode` +- Encode `log.data` into an `bytes` type through `abi.encode` +##### happen error +- Encode `error msg` into an `string` type through `abi.encode` +#### example: decode result +``` + bytes memory payload = abi.encodeWithSignature("getLogByTxHash(uint256,bytes32,uint256,uint256,uint256)", chainId,txHash,logIdx,maxDataLen,confirms); + (bool succeed,bytes memory log1) = crossChainCallContract.call(payload); + if (!succeed) { + string memory errMsg = abi.decode(log1, (string)); + return; + } + + (address c, bytes32[] memory _topics, bytes memory data) = abi.decode(log1, (address, bytes32[], bytes)); +``` -2. You can view the result of the cross-chain call via eth.getTransaction and eth.getTransactionReceipt. +### view the result of the cross-chain via RPC Web3Q added an `externalCallResult` property to the results of `eth_getTransaction` and `eth_getTransactionReceipt`. ### Parameters | Constant | Value | | ------------------------- | ---------------- | -| `ExternalCallByteGasCost` | 30 | -| `ExternalCallGas` | 10000 | +| `ExternalCallByteGasCost` | 3 | +| `ExternalCallGas` | 200000 | For the gas cost of cross-chain calls, follow the formula below: ```Gas Cost = ExternalCallGas + len(ExternalCallResult) * ExternalCallByteGasCost```.