Skip to content

Commit

Permalink
Use ckb-vm's release-0.24 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Jan 17, 2025
1 parent fd52507 commit 0d6496b
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 45 deletions.
38 changes: 28 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ byteorder = "1.3.1"
ckb-types = { path = "../util/types", version = "= 0.121.0-pre" }
ckb-hash = { path = "../util/hash", version = "= 0.121.0-pre" }
# ckb-vm = { version = "= 0.24.12", default-features = false }
ckb-vm = { git = "https://github.com/libraries/ckb-vm", branch="args_reader", default-features = false }
ckb-vm = { git = "https://github.com/nervosnetwork/ckb-vm", branch="release-0.24", default-features = false }
faster-hex = "0.6"
ckb-logger = { path = "../util/logger", version = "= 0.121.0-pre", optional = true }
serde = { version = "1.0", features = ["derive"] }
Expand Down
5 changes: 1 addition & 4 deletions script/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,7 @@ where
let copy_length = u64::min(full_length, real_length);
for i in 0..copy_length {
let fd = inherited_fd[i as usize].0;
let addr = buffer_addr.checked_add(i * 8).ok_or(Error::MemOutOfBound(
buffer_addr,
ckb_vm::error::OutOfBoundKind::Memory,
))?;
let addr = buffer_addr.checked_add(i * 8).ok_or(Error::MemOutOfBound)?;
machine
.machine
.inner_mut()
Expand Down
13 changes: 4 additions & 9 deletions script/src/syscalls/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ use ckb_types::core::error::ARGV_TOO_LONG_TEXT;
use ckb_types::packed::{Bytes as PackedBytes, BytesVec};
use ckb_vm::memory::load_c_string_byte_by_byte;
use ckb_vm::Memory;
use ckb_vm::DEFAULT_MEMORY_SIZE;
use ckb_vm::{
registers::{A0, A1, A2, A3, A4, A5, A7},
Error as VMError, Register, SupportMachine, Syscalls,
};
use ckb_vm::{DEFAULT_STACK_SIZE, RISCV_MAX_MEMORY};
use std::sync::Arc;

const DEFAULT_STACK_SIZE: usize = DEFAULT_MEMORY_SIZE / 4;

#[derive(Debug)]
pub struct Exec<DL> {
data_loader: DL,
Expand Down Expand Up @@ -153,10 +151,7 @@ impl<Mac: SupportMachine, DL: CellDataProvider + Send + Sync> Syscalls<Mac> for
let data = if length == 0 {
data.slice(offset..data_size)
} else {
let end = offset.checked_add(length).ok_or(VMError::MemOutOfBound(
offset as u64,
ckb_vm::error::OutOfBoundKind::Memory,
))?;
let end = offset.checked_add(length).ok_or(VMError::MemOutOfBound)?;
if end > data_size {
machine.set_register(A0, Mac::REG::from_u8(SLICE_OUT_OF_BOUND));
return Ok(true);
Expand Down Expand Up @@ -186,7 +181,7 @@ impl<Mac: SupportMachine, DL: CellDataProvider + Send + Sync> Syscalls<Mac> for

let cycles = machine.cycles();
let max_cycles = machine.max_cycles();
machine.reset(max_cycles)?;
machine.reset(max_cycles);
machine.set_cycles(cycles);

match machine.load_elf(&data, true) {
Expand All @@ -201,7 +196,7 @@ impl<Mac: SupportMachine, DL: CellDataProvider + Send + Sync> Syscalls<Mac> for

match machine.initialize_stack(
argv.into_iter().map(Ok),
(DEFAULT_MEMORY_SIZE - DEFAULT_STACK_SIZE) as u64,
(RISCV_MAX_MEMORY - DEFAULT_STACK_SIZE) as u64,
DEFAULT_STACK_SIZE as u64,
) {
Ok(size) => {
Expand Down
5 changes: 1 addition & 4 deletions script/src/syscalls/exec_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ where
return Ok(true);
}
if length > 0 {
let end = offset.checked_add(length).ok_or(VMError::MemOutOfBound(
offset,
ckb_vm::error::OutOfBoundKind::Memory,
))?;
let end = offset.checked_add(length).ok_or(VMError::MemOutOfBound)?;
if end > full_length {
machine.set_register(A0, Mac::REG::from_u8(SLICE_OUT_OF_BOUND));
return Ok(true);
Expand Down
10 changes: 3 additions & 7 deletions script/src/syscalls/load_cell_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,9 @@ where
}
Err(e) => return Err(e),
};
let content_end =
content_offset
.checked_add(content_size)
.ok_or(VMError::MemOutOfBound(
content_offset,
ckb_vm::error::OutOfBoundKind::Memory,
))?;
let content_end = content_offset
.checked_add(content_size)
.ok_or(VMError::MemOutOfBound)?;
if content_offset >= cell.len() as u64
|| content_end > cell.len() as u64
|| content_size > memory_size
Expand Down
5 changes: 1 addition & 4 deletions script/src/syscalls/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ where
return Ok(true);
}
if length > 0 {
let end = offset.checked_add(length).ok_or(VMError::MemOutOfBound(
offset,
ckb_vm::error::OutOfBoundKind::Memory,
))?;
let end = offset.checked_add(length).ok_or(VMError::MemOutOfBound)?;
if end > full_length {
machine.set_register(A0, Mac::REG::from_u8(SLICE_OUT_OF_BOUND));
return Ok(true);
Expand Down
5 changes: 1 addition & 4 deletions script/src/syscalls/tests/vm_latest/syscalls_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1662,10 +1662,7 @@ fn test_load_overflowed_cell_data_as_code() {
assert!(machine.memory_mut().store_byte(addr, addr_size, 1).is_ok());

let result = load_code.ecall(&mut machine);
assert_eq!(
result.unwrap_err(),
VMError::MemOutOfBound(3, ckb_vm::error::OutOfBoundKind::Memory)
);
assert_eq!(result.unwrap_err(), VMError::MemOutOfBound);
}

fn _test_load_cell_data_on_freezed_memory(data: &[u8]) -> Result<(), TestCaseError> {
Expand Down
2 changes: 1 addition & 1 deletion script/src/verify/tests/ckb_latest/features_since_v2019.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ fn load_code_to_stack_then_reuse_case1_load_and_write() {
let rtx = create_rtx_to_load_code_to_stack_then_reuse(script_version, 0b111, 40960);
let result = verifier.verify_without_limit(script_version, &rtx);
assert!(result.is_err());
let vm_error = VmError::MemWriteOnExecutablePage(1008);
let vm_error = VmError::MemWriteOnExecutablePage;
let script_error = ScriptError::VMInternalError(vm_error);
assert_error_eq!(result.unwrap_err(), script_error.input_lock_script(0));
}
Expand Down
2 changes: 1 addition & 1 deletion script/src/verify/tests/ckb_latest/features_since_v2021.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ fn load_code_into_global() {
let result = verifier.verify_without_limit(script_version, &rtx);
assert_eq!(result.is_ok(), script_version >= ScriptVersion::V1,);
if script_version < ScriptVersion::V0 {
let vm_error = VmError::MemWriteOnFreezedPage(0);
let vm_error = VmError::MemWriteOnFreezedPage;
let script_error = ScriptError::VMInternalError(vm_error);
assert_error_eq!(result.unwrap_err(), script_error.input_lock_script(0));
} else if script_version == ScriptVersion::V1 {
Expand Down

0 comments on commit 0d6496b

Please sign in to comment.