Skip to content

Commit

Permalink
Follow xuejie's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Jan 21, 2025
1 parent 5136613 commit 9136fbc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 31 deletions.
22 changes: 6 additions & 16 deletions script/src/scheduler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::cost_model::transferred_byte_cycles;
use crate::syscalls::{
EXEC_LOAD_ELF_V2_CYCLES_BASE, INDEX_OUT_OF_BOUND, INVALID_FD, MAX_FDS_CREATED, MAX_VMS_SPAWNED,
OTHER_END_CLOSED, SPAWN_EXTRA_CYCLES_BASE, SUCCESS, WAIT_FAILURE,
EXEC_LOAD_ELF_V2_CYCLES_BASE, INVALID_FD, MAX_FDS_CREATED, MAX_VMS_SPAWNED, OTHER_END_CLOSED,
SPAWN_EXTRA_CYCLES_BASE, SUCCESS, WAIT_FAILURE,
};
use crate::types::MachineContext;
use crate::verify::TransactionScriptsSyscallsGenerator;
Expand Down Expand Up @@ -357,24 +357,14 @@ where
.add_cycles_no_checking(EXEC_LOAD_ELF_V2_CYCLES_BASE)?;
let old_cycles = old_machine.machine.cycles();
let max_cycles = old_machine.machine.max_cycles();
let (program, _full_length) = {
let program = {
let mut sc = old_context.snapshot2_context().lock().expect("lock");
match sc.load_data(
sc.load_data(
&args.location.data_piece_id,
args.location.offset,
args.location.length,
) {
Ok(val) => val,
Err(Error::SnapshotDataLoadError) => {
// This comes from TxData results in an out of bound error, to
// mimic current behavior, we would return INDEX_OUT_OF_BOUND error.
old_machine
.machine
.set_register(A0, INDEX_OUT_OF_BOUND as u64);
continue;
}
Err(e) => return Err(e),
}
)?
.0
};
let (context, mut new_machine) = self.create_dummy_vm(&vm_id)?;
new_machine.set_max_cycles(max_cycles);
Expand Down
16 changes: 2 additions & 14 deletions script/src/syscalls/exec_v2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::syscalls::{
Place, Source, EXEC, INDEX_OUT_OF_BOUND, SOURCE_ENTRY_MASK, SOURCE_GROUP_FLAG,
};
use crate::syscalls::{EXEC, INDEX_OUT_OF_BOUND};
use crate::types::{DataLocation, DataPieceId, ExecV2Args, Message, VmId};
use ckb_vm::{
registers::{A0, A1, A2, A3, A4, A5, A7},
Expand Down Expand Up @@ -32,18 +30,8 @@ where
return Ok(false);
}
let index = machine.registers()[A0].to_u64();
let mut source = machine.registers()[A1].to_u64();
let source = machine.registers()[A1].to_u64();
let place = machine.registers()[A2].to_u64();
// To keep compatible with the old behavior. When Source is wrong, a
// Vm internal error should be returned.
if let Source::Group(_) = Source::parse_from_u64(source)? {
source = source & SOURCE_ENTRY_MASK | SOURCE_GROUP_FLAG;
} else {
source &= SOURCE_ENTRY_MASK;
}
// To keep compatible with the old behavior.
Place::parse_from_u64(place)?;

let data_piece_id = match DataPieceId::try_from((source, index, place)) {
Ok(id) => id,
Err(_) => {
Expand Down
8 changes: 7 additions & 1 deletion script/src/verify/tests/ckb_latest/features_since_v2021.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,8 +1753,14 @@ fn exec_from_cell_data_source_out_bound() {

#[test]
fn exec_from_witness_place_error() {
let script_version = SCRIPT_VERSION;

let from = ExecFrom::OutOfBound(0, 1, 3, 0);
let res = Err("Place parse_from_u64".to_string());
let res = if script_version <= ScriptVersion::V1 {
Err("Place parse_from_u64".to_string())
} else {
Err("error code 1".to_string())
};
test_exec(0b0000, 1, 2, 1, from, res);
}

Expand Down

0 comments on commit 9136fbc

Please sign in to comment.