Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: change some precompile input and output to tuple #1642

Merged
merged 4 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/executor/src/precompiles/call_ckb_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ impl PrecompileContract for CallCkbVM {

fn parse_input(input: &[u8]) -> Result<(CellDep, Vec<Bytes>), PrecompileFailure> {
let payload =
<CallCkbVmPayload as AbiDecode>::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(),
))
}

Expand Down
4 changes: 3 additions & 1 deletion core/executor/src/precompiles/ckb_mbt_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ impl PrecompileContract for CMBTVerify {
}

fn parse_input(input: &[u8]) -> Result<VerifyProofPayload, PrecompileFailure> {
<VerifyProofPayload as AbiDecode>::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> {
Expand Down
2 changes: 1 addition & 1 deletion core/executor/src/precompiles/get_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
))
Expand Down
8 changes: 6 additions & 2 deletions core/executor/src/precompiles/get_header.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -39,10 +40,13 @@ impl PrecompileContract for GetHeader {
return err!("get header return None");
}

let header =
<ckb_light_client_abi::Header as AbiDecode>::decode(header_opt.unwrap()).unwrap();

Ok((
PrecompileOutput {
exit_status: ExitSucceed::Returned,
output: header_opt.unwrap(),
output: AbiEncode::encode((header,)),
},
gas,
))
Expand Down
4 changes: 2 additions & 2 deletions core/executor/src/precompiles/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading