From 88f5bd3c38504c213bc95ea516fe336746692ed5 Mon Sep 17 00:00:00 2001 From: KaoImin Date: Mon, 18 Dec 2023 17:49:37 +0800 Subject: [PATCH 1/4] refactor: change some precompile input and output to tuple --- core/executor/src/precompiles/ckb_mbt_verify.rs | 4 +++- core/executor/src/precompiles/get_header.rs | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/executor/src/precompiles/ckb_mbt_verify.rs b/core/executor/src/precompiles/ckb_mbt_verify.rs index 349a6d64f..5b9c95bf5 100644 --- a/core/executor/src/precompiles/ckb_mbt_verify.rs +++ b/core/executor/src/precompiles/ckb_mbt_verify.rs @@ -67,7 +67,9 @@ impl PrecompileContract for CMBTVerify { } fn parse_input(input: &[u8]) -> Result { - ::decode(input).map_err(|_| err!(_, "decode input")) + <(VerifyProofPayload,) as AbiDecode>::decode(input) + .map(|r| r.0) + .map_err(|_| err!(_, "decode input")) } fn inner_verify_proof(payload: VerifyProofPayload) -> Result<(), PrecompileFailure> { diff --git a/core/executor/src/precompiles/get_header.rs b/core/executor/src/precompiles/get_header.rs index bca27de2b..dec2de745 100644 --- a/core/executor/src/precompiles/get_header.rs +++ b/core/executor/src/precompiles/get_header.rs @@ -1,10 +1,11 @@ -use ethers::abi::AbiDecode; +use ethers::abi::{AbiDecode, AbiEncode}; use evm::executor::stack::{PrecompileFailure, PrecompileOutput}; use evm::{Context, ExitError, ExitSucceed}; use protocol::types::{H160, H256}; use crate::precompiles::{axon_precompile_address, PrecompileContract}; +use crate::system_contract::ckb_light_client::ckb_light_client_abi; use crate::{err, system_contract::ckb_light_client::CkbHeaderReader, CURRENT_HEADER_CELL_ROOT}; #[derive(Default, Clone)] @@ -39,10 +40,13 @@ impl PrecompileContract for GetHeader { return err!("get header return None"); } + let header = + ::decode(header_opt.unwrap()).unwrap(); + Ok(( PrecompileOutput { exit_status: ExitSucceed::Returned, - output: header_opt.unwrap(), + output: AbiEncode::encode((header,)), }, gas, )) From c2fd683f3c5d69a75b58759a66b4c40d4706745a Mon Sep 17 00:00:00 2001 From: KaoImin Date: Mon, 18 Dec 2023 21:04:57 +0800 Subject: [PATCH 2/4] change get_cell output --- core/executor/src/precompiles/get_cell.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/executor/src/precompiles/get_cell.rs b/core/executor/src/precompiles/get_cell.rs index a1d65fe47..6f95e1ccf 100644 --- a/core/executor/src/precompiles/get_cell.rs +++ b/core/executor/src/precompiles/get_cell.rs @@ -52,7 +52,7 @@ impl PrecompileContract for GetCell { Ok(( PrecompileOutput { exit_status: ExitSucceed::Returned, - output: cell_opt.unwrap().encode(), + output: AbiEncode::encode((cell_opt.unwrap(),)), }, gas, )) From 836f105790ee3c2b71283937649e1f3a801b74c0 Mon Sep 17 00:00:00 2001 From: KaoImin Date: Mon, 18 Dec 2023 21:12:10 +0800 Subject: [PATCH 3/4] fix unit test --- core/executor/src/precompiles/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/executor/src/precompiles/tests.rs b/core/executor/src/precompiles/tests.rs index f40f45777..89833bb51 100644 --- a/core/executor/src/precompiles/tests.rs +++ b/core/executor/src/precompiles/tests.rs @@ -303,11 +303,11 @@ fn test_verify_cmbt_proof() { proof: witness_proof, }; - let input = AbiEncode::encode(raw_tx_payload); + let input = AbiEncode::encode((raw_tx_payload,)); let output = vec![1u8]; test_precompile!(CMBTVerify, &input, output, 56000); - let input = AbiEncode::encode(witness_payload); + let input = AbiEncode::encode((witness_payload,)); let output = vec![1u8]; test_precompile!(CMBTVerify, &input, output, 56000); } From 4748a2efea36a70e3edab21ecf44b11a4c2e9d56 Mon Sep 17 00:00:00 2001 From: KaoImin Date: Mon, 18 Dec 2023 22:44:08 +0800 Subject: [PATCH 4/4] update call ckb vm --- core/executor/src/precompiles/call_ckb_vm.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/executor/src/precompiles/call_ckb_vm.rs b/core/executor/src/precompiles/call_ckb_vm.rs index eb5f2469a..3574b9065 100644 --- a/core/executor/src/precompiles/call_ckb_vm.rs +++ b/core/executor/src/precompiles/call_ckb_vm.rs @@ -55,11 +55,11 @@ impl PrecompileContract for CallCkbVM { fn parse_input(input: &[u8]) -> Result<(CellDep, Vec), PrecompileFailure> { let payload = - ::decode(input).map_err(|_| err!(_, "decode input"))?; + <(CallCkbVmPayload,) as AbiDecode>::decode(input).map_err(|_| err!(_, "decode input"))?; Ok(( - payload.cell, - payload.inputs.into_iter().map(|i| i.0).collect(), + payload.0.cell, + payload.0.inputs.into_iter().map(|i| i.0).collect(), )) }