From b800758a461451ee8207269ec1d88b8e635599f2 Mon Sep 17 00:00:00 2001 From: mohanson Date: Fri, 17 Jan 2025 14:44:03 +0800 Subject: [PATCH 1/2] Backport #450 --- .github/workflows/develop.yml | 6 +-- benches/vm_benchmark.rs | 42 +++++++++--------- examples/check_real_memory.rs | 4 +- examples/ckb-vm-runner.rs | 4 +- src/lib.rs | 4 +- src/machine/asm/mod.rs | 8 +++- src/machine/mod.rs | 80 +++++++++++++++++++++++++++++++---- src/machine/trace.rs | 8 +++- src/memory/mod.rs | 17 ++++++++ tests/machine_build.rs | 16 ++++--- tests/test_asm.rs | 50 +++++++++++----------- tests/test_auipc_fusion.rs | 4 +- tests/test_dy_memory.rs | 4 +- tests/test_misc.rs | 10 ++--- tests/test_reset.rs | 8 ++-- tests/test_resume.rs | 18 +++++--- tests/test_resume2.rs | 61 +++++++++++++++++--------- tests/test_simple.rs | 8 ++-- tests/test_versions.rs | 16 +++---- 19 files changed, 244 insertions(+), 124 deletions(-) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index cf404dca..3d879bac 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -69,7 +69,7 @@ jobs: ln -snf .. ckb-vm-test-suite/ckb-vm docker run --rm -v `pwd`:/code nervos/ckb-riscv-gnu-toolchain:bionic-20210804 cp -r /riscv /code/riscv cd ckb-vm-test-suite - git checkout 441e0f2149c097ccad133b040544dca13caeb01e + git checkout 898edc351eeb4de974ca4f0ff8d1e4943a95aecb git submodule update --init --recursive RISCV=`pwd`/../riscv ./test.sh @@ -136,13 +136,13 @@ jobs: ln -snf .. ckb-vm-test-suite/ckb-vm docker run --rm -v `pwd`:/code nervos/ckb-riscv-gnu-toolchain:bionic-20210804 cp -r /riscv /code/riscv cd ckb-vm-test-suite - git checkout 441e0f2149c097ccad133b040544dca13caeb01e + git checkout 898edc351eeb4de974ca4f0ff8d1e4943a95aecb git submodule update --init --recursive RISCV=`pwd`/../riscv ./test.sh --build-only cd .. - name: Run test suite run: | - sudo apt install -y qemu binfmt-support qemu-user-static + sudo apt install -y qemu-system binfmt-support qemu-user-static sudo apt install -y gcc-multilib sudo apt install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu clang docker run --rm --privileged multiarch/qemu-user-static --reset -p yes diff --git a/benches/vm_benchmark.rs b/benches/vm_benchmark.rs index 7a80ed5b..36675fb5 100644 --- a/benches/vm_benchmark.rs +++ b/benches/vm_benchmark.rs @@ -17,12 +17,13 @@ use std::fs; fn interpret_benchmark(c: &mut Criterion) { c.bench_function("interpret secp256k1_bench", |b| { let buffer = fs::read("benches/data/secp256k1_bench").unwrap().into(); - let args: Vec = vec!["secp256k1_bench", - "033f8cf9c4d51a33206a6c1c6b27d2cc5129daa19dbd1fc148d395284f6b26411f", - "304402203679d909f43f073c7c1dcf8468a485090589079ee834e6eed92fea9b09b06a2402201e46f1075afa18f306715e7db87493e7b7e779569aa13c64ab3d09980b3560a3", - "foo", - "bar"].into_iter().map(|a| a.into()).collect(); - + let args: Vec = vec![ + "secp256k1_bench", + "033f8cf9c4d51a33206a6c1c6b27d2cc5129daa19dbd1fc148d395284f6b26411f", + "304402203679d909f43f073c7c1dcf8468a485090589079ee834e6eed92fea9b09b06a2402201e46f1075afa18f306715e7db87493e7b7e779569aa13c64ab3d09980b3560a3", + "foo", + "bar" + ].into_iter().map(|a| a.into()).collect(); b.iter(|| run::>(&buffer, &args[..], RISCV_MAX_MEMORY).unwrap()); }); } @@ -31,17 +32,18 @@ fn interpret_benchmark(c: &mut Criterion) { fn asm_benchmark(c: &mut Criterion) { c.bench_function("interpret secp256k1_bench via assembly", |b| { let buffer = fs::read("benches/data/secp256k1_bench").unwrap().into(); - let args: Vec = vec!["secp256k1_bench", - "033f8cf9c4d51a33206a6c1c6b27d2cc5129daa19dbd1fc148d395284f6b26411f", - "304402203679d909f43f073c7c1dcf8468a485090589079ee834e6eed92fea9b09b06a2402201e46f1075afa18f306715e7db87493e7b7e779569aa13c64ab3d09980b3560a3", - "foo", - "bar"].into_iter().map(|a| a.into()).collect(); - + let args = [ + "secp256k1_bench", + "033f8cf9c4d51a33206a6c1c6b27d2cc5129daa19dbd1fc148d395284f6b26411f", + "304402203679d909f43f073c7c1dcf8468a485090589079ee834e6eed92fea9b09b06a2402201e46f1075afa18f306715e7db87493e7b7e779569aa13c64ab3d09980b3560a3", + "foo", + "bar", + ].into_iter().map(|a| Ok(a.into())); b.iter(|| { let asm_core = AsmCoreMachine::new(ISA_IMC, VERSION0, u64::max_value()); let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); - machine.load_program(&buffer, &args[..]).unwrap(); + machine.load_program(&buffer, args.clone()).unwrap(); machine.run().unwrap() }); }); @@ -51,17 +53,19 @@ fn asm_benchmark(c: &mut Criterion) { fn mop_benchmark(c: &mut Criterion) { c.bench_function("interpret secp256k1_bench via assembly mop", |b| { let buffer = fs::read("benches/data/secp256k1_bench").unwrap().into(); - let args: Vec = vec!["secp256k1_bench", - "033f8cf9c4d51a33206a6c1c6b27d2cc5129daa19dbd1fc148d395284f6b26411f", - "304402203679d909f43f073c7c1dcf8468a485090589079ee834e6eed92fea9b09b06a2402201e46f1075afa18f306715e7db87493e7b7e779569aa13c64ab3d09980b3560a3", - "foo", - "bar"].into_iter().map(|a| a.into()).collect(); + let args = [ + "secp256k1_bench", + "033f8cf9c4d51a33206a6c1c6b27d2cc5129daa19dbd1fc148d395284f6b26411f", + "304402203679d909f43f073c7c1dcf8468a485090589079ee834e6eed92fea9b09b06a2402201e46f1075afa18f306715e7db87493e7b7e779569aa13c64ab3d09980b3560a3", + "foo", + "bar", + ].into_iter().map(|a| Ok(a.into())); b.iter(|| { let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_B | ISA_MOP, VERSION2, u64::max_value()); let core = DefaultMachineBuilder::>::new(asm_core) .build(); let mut machine = AsmMachine::new(core); - machine.load_program(&buffer, &args).unwrap(); + machine.load_program(&buffer, args.clone()).unwrap(); machine.run().unwrap() }); }); diff --git a/examples/check_real_memory.rs b/examples/check_real_memory.rs index 99720f38..87d22a9a 100644 --- a/examples/check_real_memory.rs +++ b/examples/check_real_memory.rs @@ -173,7 +173,7 @@ fn check_asm(memory_size: usize) -> Result<(), ()> { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&BIN_PATH_BUFFER, &vec![BIN_NAME.clone().into()]) + .load_program(&BIN_PATH_BUFFER, [Ok(BIN_NAME.clone().into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_ok()); @@ -198,7 +198,7 @@ fn check_asm_in_thread(memory_size: usize) -> Result<(), ()> { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&BIN_PATH_BUFFER, &vec![BIN_NAME.clone().into()]) + .load_program(&BIN_PATH_BUFFER, [Ok(BIN_NAME.clone().into())].into_iter()) .unwrap(); let thread_join_handle = thread::spawn(move || { let result = machine.run(); diff --git a/examples/ckb-vm-runner.rs b/examples/ckb-vm-runner.rs index 960fb3fa..f299ae9d 100644 --- a/examples/ckb-vm-runner.rs +++ b/examples/ckb-vm-runner.rs @@ -49,7 +49,7 @@ fn main_asm(code: Bytes, args: Vec) -> Result<(), Box) -> Result<(), Box>( memory_size, ); let mut machine = TraceMachine::new(DefaultMachineBuilder::new(core_machine).build()); - machine.load_program(program, args)?; + machine.load_program(program, args.iter().map(|e| Ok(e.clone())))?; machine.run() } diff --git a/src/machine/asm/mod.rs b/src/machine/asm/mod.rs index b062c9ab..6556326d 100644 --- a/src/machine/asm/mod.rs +++ b/src/machine/asm/mod.rs @@ -482,7 +482,11 @@ impl AsmMachine { self.machine.inner.max_cycles = cycles; } - pub fn load_program(&mut self, program: &Bytes, args: &[Bytes]) -> Result { + pub fn load_program( + &mut self, + program: &Bytes, + args: impl ExactSizeIterator>, + ) -> Result { self.machine.load_program(program, args) } @@ -490,7 +494,7 @@ impl AsmMachine { &mut self, program: &Bytes, metadata: &ProgramMetadata, - args: &[Bytes], + args: impl ExactSizeIterator>, ) -> Result { self.machine .load_program_with_metadata(program, metadata, args) diff --git a/src/machine/mod.rs b/src/machine/mod.rs index 6ee98df1..8f4cb1d5 100644 --- a/src/machine/mod.rs +++ b/src/machine/mod.rs @@ -12,7 +12,7 @@ use super::debugger::Debugger; use super::decoder::{build_decoder, Decoder}; use super::elf::{parse_elf, LoadingAction, ProgramMetadata}; use super::instructions::{execute, Instruction, Register}; -use super::memory::Memory; +use super::memory::{load_c_string_byte_by_byte, Memory}; use super::syscalls::Syscalls; use super::{ registers::{A0, A7, REGISTER_ABI_NAMES, SP}, @@ -171,7 +171,7 @@ pub trait SupportMachine: CoreMachine { fn initialize_stack( &mut self, - args: &[Bytes], + args: impl ExactSizeIterator>, stack_start: u64, stack_size: u64, ) -> Result { @@ -183,7 +183,7 @@ pub trait SupportMachine: CoreMachine { // reading "argc" will return an unexpected data. This situation is not very common. // // See https://github.com/nervosnetwork/ckb-vm/issues/106 for more details. - if self.version() >= VERSION1 && args.is_empty() { + if self.version() >= VERSION1 && args.len() == 0 { let argc_size = u64::from(Self::REG::BITS / 8); let origin_sp = stack_start + stack_size; let unaligned_sp_address = origin_sp - argc_size; @@ -200,15 +200,21 @@ pub trait SupportMachine: CoreMachine { // of each argv object. let mut values = vec![Self::REG::from_u64(args.len() as u64)]; for arg in args { + let arg = arg?; let len = Self::REG::from_u64(arg.len() as u64 + 1); let address = self.registers()[SP].overflowing_sub(&len); - self.memory_mut().store_bytes(address.to_u64(), arg)?; + self.memory_mut().store_bytes(address.to_u64(), &arg)?; self.memory_mut() .store_byte(address.to_u64() + arg.len() as u64, 1, 0)?; values.push(address.clone()); - self.set_register(SP, address); + self.set_register(SP, address.clone()); + + if self.version() >= VERSION2 && address.to_u64() < stack_start { + // Provides an early exit to large argv array. + return Err(Error::MemOutOfStack); + } } if self.version() >= VERSION1 { // There are 2 standard requirements of the initialized stack: @@ -246,7 +252,7 @@ pub trait SupportMachine: CoreMachine { self.set_register(SP, address); } if self.registers()[SP].to_u64() < stack_start { - // args exceed stack size + // Args exceed stack size. return Err(Error::MemOutOfStack); } Ok(stack_start + stack_size - self.registers()[SP].to_u64()) @@ -572,7 +578,11 @@ impl Display for DefaultMachine { } impl DefaultMachine { - pub fn load_program(&mut self, program: &Bytes, args: &[Bytes]) -> Result { + pub fn load_program( + &mut self, + program: &Bytes, + args: impl ExactSizeIterator>, + ) -> Result { let elf_bytes = self.load_elf(program, true)?; let stack_bytes = self.initialize(args)?; let bytes = elf_bytes.checked_add(stack_bytes).ok_or_else(|| { @@ -587,7 +597,7 @@ impl DefaultMachine { &mut self, program: &Bytes, metadata: &ProgramMetadata, - args: &[Bytes], + args: impl ExactSizeIterator>, ) -> Result { let elf_bytes = self.load_binary(program, metadata, true)?; let stack_bytes = self.initialize(args)?; @@ -599,7 +609,10 @@ impl DefaultMachine { Ok(bytes) } - fn initialize(&mut self, args: &[Bytes]) -> Result { + fn initialize( + &mut self, + args: impl ExactSizeIterator>, + ) -> Result { for syscall in &mut self.syscalls { syscall.initialize(&mut self.inner)?; } @@ -759,6 +772,55 @@ impl Pause { } } +pub struct FlattenedArgsReader<'a, M: Memory> { + memory: &'a mut M, + argc: M::REG, + argv: M::REG, + cidx: M::REG, +} +impl<'a, M: Memory> FlattenedArgsReader<'a, M> { + pub fn new(memory: &'a mut M, argc: M::REG, argv: M::REG) -> Self { + Self { + memory, + argc, + argv, + cidx: M::REG::zero(), + } + } +} +impl<'a, M: Memory> Iterator for FlattenedArgsReader<'a, M> { + type Item = Result; + fn next(&mut self) -> Option { + if self.cidx.ge(&self.argc).to_u8() == 1 { + return None; + } + let addr = match M::REG::BITS { + 32 => self.memory.load32(&self.argv), + 64 => self.memory.load64(&self.argv), + _ => unreachable!(), + }; + if let Err(err) = addr { + return Some(Err(err)); + }; + let addr = addr.unwrap(); + let cstr = load_c_string_byte_by_byte(self.memory, &addr); + if let Err(err) = cstr { + return Some(Err(err)); + }; + let cstr = cstr.unwrap(); + self.cidx = self.cidx.overflowing_add(&M::REG::from_u8(1)); + self.argv = self + .argv + .overflowing_add(&M::REG::from_u8(M::REG::BITS / 8)); + Some(Ok(cstr)) + } +} +impl<'a, M: Memory> ExactSizeIterator for FlattenedArgsReader<'a, M> { + fn len(&self) -> usize { + self.argc.to_u64() as usize + } +} + #[cfg(test)] mod tests { use std::sync::atomic::AtomicU8; diff --git a/src/machine/trace.rs b/src/machine/trace.rs index ca3904eb..bf3dc919 100644 --- a/src/machine/trace.rs +++ b/src/machine/trace.rs @@ -113,7 +113,11 @@ impl TraceMachine { } } - pub fn load_program(&mut self, program: &Bytes, args: &[Bytes]) -> Result { + pub fn load_program( + &mut self, + program: &Bytes, + args: impl ExactSizeIterator>, + ) -> Result { self.machine.load_program(program, args) } @@ -121,7 +125,7 @@ impl TraceMachine { &mut self, program: &Bytes, metadata: &ProgramMetadata, - args: &[Bytes], + args: impl ExactSizeIterator>, ) -> Result { self.machine .load_program_with_metadata(program, metadata, args) diff --git a/src/memory/mod.rs b/src/memory/mod.rs index aed0a131..964bbc8a 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -144,3 +144,20 @@ pub fn memset(slice: &mut [u8], value: u8) { ptr::write_bytes(p, value, slice.len()); } } + +pub fn load_c_string_byte_by_byte( + memory: &mut M, + addr: &M::REG, +) -> Result { + let mut buffer = Vec::new(); + let mut addr = addr.clone(); + loop { + let byte = memory.load8(&addr)?.to_u8(); + if byte == 0 { + break; + } + buffer.push(byte); + addr = addr.overflowing_add(&M::REG::from_u8(1)); + } + Ok(Bytes::from(buffer)) +} diff --git a/tests/machine_build.rs b/tests/machine_build.rs index 9ae2ad51..462c3355 100644 --- a/tests/machine_build.rs +++ b/tests/machine_build.rs @@ -39,7 +39,7 @@ pub fn asm_v1_imcb(path: &str) -> AsmMachine { .build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec![Bytes::from("main")]) + .load_program(&buffer, [Ok(Bytes::from("main"))].into_iter()) .unwrap(); machine } @@ -60,7 +60,7 @@ pub fn int_v1_imcb( .build(), ); machine - .load_program(&buffer, &vec![Bytes::from("main")]) + .load_program(&buffer, [Ok(Bytes::from("main"))].into_iter()) .unwrap(); machine } @@ -81,7 +81,9 @@ pub fn asm_mop(path: &str, args: Vec, version: u32) -> AsmMachine { let mut machine = AsmMachine::new(core); let mut argv = vec![Bytes::from("main")]; argv.extend_from_slice(&args); - machine.load_program(&buffer, &argv).unwrap(); + machine + .load_program(&buffer, argv.into_iter().map(Ok)) + .unwrap(); machine } @@ -111,7 +113,9 @@ pub fn int_mop( ); let mut argv = vec![Bytes::from("main")]; argv.extend_from_slice(&args); - machine.load_program(&buffer, &argv).unwrap(); + machine + .load_program(&buffer, argv.into_iter().map(Ok)) + .unwrap(); machine } @@ -125,7 +129,7 @@ pub fn asm_v2_imacb(path: &str) -> AsmMachine { .build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec![Bytes::from("main")]) + .load_program(&buffer, [Ok(Bytes::from("main"))].into_iter()) .unwrap(); machine } @@ -146,7 +150,7 @@ pub fn int_v2_imacb( .build(), ); machine - .load_program(&buffer, &vec![Bytes::from("main")]) + .load_program(&buffer, [Ok(Bytes::from("main"))].into_iter()) .unwrap(); machine } diff --git a/tests/test_asm.rs b/tests/test_asm.rs index b114b62b..e5e8b58e 100644 --- a/tests/test_asm.rs +++ b/tests/test_asm.rs @@ -19,7 +19,7 @@ pub fn test_asm_simple64() { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["simple".into()]) + .load_program(&buffer, [Ok("simple".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_ok()); @@ -58,7 +58,7 @@ pub fn test_asm_with_custom_syscall() { .build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["syscall".into()]) + .load_program(&buffer, [Ok("syscall".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_ok()); @@ -94,7 +94,7 @@ pub fn test_asm_ebreak() { .build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["ebreak".into()]) + .load_program(&buffer, [Ok("ebreak".into())].into_iter()) .unwrap(); assert_eq!(value.load(Ordering::Relaxed), 1); let result = machine.run(); @@ -111,7 +111,7 @@ pub fn test_asm_simple_cycles() { .build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["syscall".into()]) + .load_program(&buffer, [Ok("syscall".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_ok()); @@ -130,7 +130,7 @@ pub fn test_asm_simple_max_cycles_reached() { .build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["syscall".into()]) + .load_program(&buffer, [Ok("syscall".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_err()); @@ -144,7 +144,7 @@ pub fn test_asm_trace() { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["simple".into()]) + .load_program(&buffer, [Ok("simple".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_err()); @@ -158,7 +158,7 @@ pub fn test_asm_jump0() { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["jump0_64".into()]) + .load_program(&buffer, [Ok("jump0_64".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_err()); @@ -174,7 +174,7 @@ pub fn test_asm_write_large_address() { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["write_large_address64".into()]) + .load_program(&buffer, [Ok("write_large_address64".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_err()); @@ -188,7 +188,7 @@ pub fn test_misaligned_jump64() { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["misaligned_jump64".into()]) + .load_program(&buffer, [Ok("misaligned_jump64".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_ok()); @@ -201,7 +201,7 @@ pub fn test_mulw64() { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["mulw64".into()]) + .load_program(&buffer, [Ok("mulw64".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_ok()); @@ -215,7 +215,7 @@ pub fn test_invalid_read64() { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["invalid_read64".into()]) + .load_program(&buffer, [Ok("invalid_read64".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_err()); @@ -229,7 +229,7 @@ pub fn test_asm_load_elf_crash_64() { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["load_elf_crash_64".into()]) + .load_program(&buffer, [Ok("load_elf_crash_64".into())].into_iter()) .unwrap(); let result = machine.run(); assert_eq!(result.err(), Some(Error::MemWriteOnExecutablePage)); @@ -242,7 +242,7 @@ pub fn test_asm_wxorx_crash_64() { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["wxorx_crash_64".into()]) + .load_program(&buffer, [Ok("wxorx_crash_64".into())].into_iter()) .unwrap(); let result = machine.run(); assert_eq!(result.err(), Some(Error::MemOutOfBound)); @@ -255,7 +255,7 @@ pub fn test_asm_alloc_many() { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["alloc_many".into()]) + .load_program(&buffer, [Ok("alloc_many".into())].into_iter()) .unwrap(); let result = machine.run(); assert_eq!(result.unwrap(), 0); @@ -270,7 +270,7 @@ pub fn test_asm_chaos_seed() { let core1 = DefaultMachineBuilder::>::new(asm_core1).build(); let mut machine1 = AsmMachine::new(core1); machine1 - .load_program(&buffer, &vec!["read_memory".into()]) + .load_program(&buffer, [Ok("read_memory".into())].into_iter()) .unwrap(); let result1 = machine1.run(); let exit1 = result1.unwrap(); @@ -281,7 +281,7 @@ pub fn test_asm_chaos_seed() { let core2 = DefaultMachineBuilder::>::new(asm_core2).build(); let mut machine2 = AsmMachine::new(core2); machine2 - .load_program(&buffer, &vec!["read_memory".into()]) + .load_program(&buffer, [Ok("read_memory".into())].into_iter()) .unwrap(); let result2 = machine2.run(); let exit2 = result2.unwrap(); @@ -299,7 +299,7 @@ pub fn test_asm_rvc_pageend() { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["rvc_pageend".into()]) + .load_program(&buffer, [Ok("rvc_pageend".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_ok()); @@ -340,7 +340,7 @@ pub fn test_asm_outofcycles_in_syscall() { .build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["syscall".into()]) + .load_program(&buffer, [Ok("syscall".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_err()); @@ -359,7 +359,7 @@ pub fn test_asm_cycles_overflow() { let mut machine = AsmMachine::new(core); machine.machine.set_cycles(u64::MAX - 10); machine - .load_program(&buffer, &vec!["simple64".into()]) + .load_program(&buffer, [Ok("simple64".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_err()); @@ -378,7 +378,7 @@ pub fn test_decoder_instructions_cache_pc_out_of_bound_timeout() { let mut machine = AsmMachine::new(core); machine.machine.set_cycles(u64::MAX - 10); machine - .load_program(&buffer, &vec!["simple64".into()]) + .load_program(&buffer, [Ok("simple64".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_err()); @@ -391,7 +391,7 @@ pub fn test_asm_step() { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["simple64".into()]) + .load_program(&buffer, [Ok("simple64".into())].into_iter()) .unwrap(); let result = || -> Result { @@ -414,7 +414,7 @@ fn test_asm_thread_safe() { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["mulw64".into()]) + .load_program(&buffer, [Ok("mulw64".into())].into_iter()) .unwrap(); let thread_join_handle = thread::spawn(move || { let result = machine.run(); @@ -430,7 +430,9 @@ fn test_zero_address() { let asm_core = AsmCoreMachine::new(ISA_IMC, VERSION1, u64::max_value()); let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); - machine.load_program(&buffer, &vec!["zero".into()]).unwrap(); + machine + .load_program(&buffer, [Ok("zero".into())].into_iter()) + .unwrap(); let result = machine.run(); assert!(result.is_ok()); assert_eq!(result.unwrap(), 0); @@ -442,6 +444,6 @@ pub fn test_big_binary() { let asm_core = AsmCoreMachine::new_with_memory(ISA_IMC, VERSION2, u64::max_value(), 1024 * 512); let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); - let result = machine.load_program(&buffer, &vec!["simple".into()]); + let result = machine.load_program(&buffer, [Ok("simple".into())].into_iter()); assert_eq!(result, Err(Error::MemOutOfBound)); } diff --git a/tests/test_auipc_fusion.rs b/tests/test_auipc_fusion.rs index b179d85e..2cafd79e 100644 --- a/tests/test_auipc_fusion.rs +++ b/tests/test_auipc_fusion.rs @@ -58,7 +58,7 @@ pub fn test_rust_auipc_fusion() { DefaultCoreMachine::>::new(ISA_IMC, VERSION1, u64::max_value()); let mut machine = DefaultMachineBuilder::new(core_machine).build(); machine - .load_program(&buffer, &vec!["auipc_no_sign_extend".into()]) + .load_program(&buffer, [Ok("auipc_no_sign_extend".into())].into_iter()) .unwrap(); let mut decoder = AuxDecoder::new(build_decoder::(machine.isa(), machine.version())); @@ -89,7 +89,7 @@ pub fn test_asm_auipc_fusion() { let core = DefaultMachineBuilder::>::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["auipc_no_sign_extend".into()]) + .load_program(&buffer, [Ok("auipc_no_sign_extend".into())].into_iter()) .unwrap(); let mut decoder = AuxDecoder::new(build_decoder::( diff --git a/tests/test_dy_memory.rs b/tests/test_dy_memory.rs index 1652010c..12ba3e76 100644 --- a/tests/test_dy_memory.rs +++ b/tests/test_dy_memory.rs @@ -27,7 +27,7 @@ fn run_memory_suc(memory_size: usize, bin_path: String, bin_name: String) { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec![bin_name.into()]) + .load_program(&buffer, [Ok(bin_name.into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_ok()); @@ -63,7 +63,7 @@ fn test_memory_out_of_bounds() { let core = DefaultMachineBuilder::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec!["alloc_many".into()]) + .load_program(&buffer, [Ok("alloc_many".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_err()); diff --git a/tests/test_misc.rs b/tests/test_misc.rs index 5bab12e6..dd259435 100644 --- a/tests/test_misc.rs +++ b/tests/test_misc.rs @@ -61,7 +61,7 @@ pub fn test_custom_syscall() { .syscall(Box::new(CustomSyscall {})) .build(); machine - .load_program(&buffer, &vec!["syscall".into()]) + .load_program(&buffer, [Ok("syscall".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_ok()); @@ -96,7 +96,7 @@ pub fn test_ebreak() { })) .build(); machine - .load_program(&buffer, &vec!["ebreak".into()]) + .load_program(&buffer, [Ok("ebreak".into())].into_iter()) .unwrap(); assert_eq!(value.load(Ordering::Relaxed), 1); let result = machine.run(); @@ -212,7 +212,7 @@ pub fn test_flat_crash_64() { let core_machine = DefaultCoreMachine::>::new(ISA_IMC, VERSION0, u64::max_value()); let mut machine = DefaultMachineBuilder::new(core_machine).build(); - let result = machine.load_program(&buffer, &vec!["flat_crash_64".into()]); + let result = machine.load_program(&buffer, [Ok("flat_crash_64".into())].into_iter()); assert_eq!(result.err(), Some(Error::MemOutOfBound)); } @@ -363,7 +363,7 @@ pub fn test_rvc_pageend() { DefaultCoreMachine::>::new(ISA_IMC, VERSION0, u64::max_value()); let mut machine = DefaultMachineBuilder::new(core_machine).build(); machine - .load_program(&buffer, &vec!["rvc_end".into()]) + .load_program(&buffer, [Ok("rvc_end".into())].into_iter()) .unwrap(); let anchor_pc: u64 = 69630; @@ -417,7 +417,7 @@ pub fn test_outofcycles_in_syscall() { .syscall(Box::new(OutOfCyclesSyscall {})) .build(); machine - .load_program(&buffer, &vec!["syscall".into()]) + .load_program(&buffer, [Ok("syscall".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_err()); diff --git a/tests/test_reset.rs b/tests/test_reset.rs index 11f00e2b..b9c1e557 100644 --- a/tests/test_reset.rs +++ b/tests/test_reset.rs @@ -30,7 +30,7 @@ impl Syscalls for CustomSyscall { let code = Bytes::from(code_data); machine.load_elf(&code, true).unwrap(); machine.initialize_stack( - &[], + [].into_iter(), (RISCV_MAX_MEMORY - DEFAULT_STACK_SIZE) as u64, DEFAULT_STACK_SIZE as u64, )?; @@ -52,7 +52,7 @@ fn test_reset_int() { .instruction_cycle_func(Box::new(constant_cycles)) .syscall(Box::new(CustomSyscall {})) .build(); - machine.load_program(&code, &vec![]).unwrap(); + machine.load_program(&code, [].into_iter()).unwrap(); let result = machine.run(); let cycles = machine.cycles(); assert!(result.is_ok()); @@ -76,7 +76,7 @@ fn test_reset_int_with_trace() { .syscall(Box::new(CustomSyscall {})) .build(), ); - machine.load_program(&code, &vec![]).unwrap(); + machine.load_program(&code, [].into_iter()).unwrap(); let result = machine.run(); let cycles = machine.machine.cycles(); assert!(result.is_ok()); @@ -96,7 +96,7 @@ fn test_reset_asm() { .syscall(Box::new(CustomSyscall {})) .build(); let mut machine = AsmMachine::new(core); - machine.load_program(&code, &vec![]).unwrap(); + machine.load_program(&code, [].into_iter()).unwrap(); let result = machine.run(); let cycles = machine.machine.cycles(); diff --git a/tests/test_resume.rs b/tests/test_resume.rs index 0d589abd..825bae60 100644 --- a/tests/test_resume.rs +++ b/tests/test_resume.rs @@ -55,7 +55,7 @@ pub fn resume_asm_2_asm(version: u32, except_cycles: u64) { // The cycles required for complete execution is 4194622 let mut machine1 = MachineTy::Asm.build(version, except_cycles - 30); machine1 - .load_program(&buffer, &vec!["alloc_many".into()]) + .load_program(&buffer, [Ok("alloc_many".into())].into_iter()) .unwrap(); let result1 = machine1.run(); let cycles1 = machine1.cycles(); @@ -77,7 +77,7 @@ pub fn resume_asm_2_asm_2_asm(version: u32, except_cycles: u64) { let mut machine1 = MachineTy::Asm.build(version, 1000000); machine1 - .load_program(&buffer, &vec!["alloc_many".into()]) + .load_program(&buffer, [Ok("alloc_many".into())].into_iter()) .unwrap(); let result1 = machine1.run(); let cycles1 = machine1.cycles(); @@ -107,7 +107,7 @@ pub fn resume_asm_2_interpreter(version: u32, except_cycles: u64) { let mut machine1 = MachineTy::Asm.build(version, except_cycles - 30); machine1 - .load_program(&buffer, &vec!["alloc_many".into()]) + .load_program(&buffer, [Ok("alloc_many".into())].into_iter()) .unwrap(); let result1 = machine1.run(); let cycles1 = machine1.cycles(); @@ -130,7 +130,7 @@ pub fn resume_interpreter_2_interpreter(version: u32, except_cycles: u64) { let mut machine1 = MachineTy::Interpreter.build(version, except_cycles - 30); machine1 - .load_program(&buffer, &vec!["alloc_many".into()]) + .load_program(&buffer, [Ok("alloc_many".into())].into_iter()) .unwrap(); let result1 = machine1.run(); let cycles1 = machine1.cycles(); @@ -152,7 +152,7 @@ pub fn resume_interpreter_2_asm(version: u32, except_cycles: u64) { let mut machine1 = MachineTy::Interpreter.build(version, except_cycles - 30); machine1 - .load_program(&buffer, &vec!["alloc_many".into()]) + .load_program(&buffer, [Ok("alloc_many".into())].into_iter()) .unwrap(); let result1 = machine1.run(); let cycles1 = machine1.cycles(); @@ -174,7 +174,7 @@ pub fn resume_interpreter_with_trace_2_asm_inner(version: u32, except_cycles: u6 let mut machine1 = MachineTy::InterpreterWithTrace.build(version, except_cycles - 30); machine1 - .load_program(&buffer, &vec!["alloc_many".into()]) + .load_program(&buffer, [Ok("alloc_many".into())].into_iter()) .unwrap(); let result1 = machine1.run(); let cycles1 = machine1.cycles(); @@ -251,7 +251,11 @@ enum Machine { } impl Machine { - fn load_program(&mut self, program: &Bytes, args: &[Bytes]) -> Result { + fn load_program( + &mut self, + program: &Bytes, + args: impl ExactSizeIterator>, + ) -> Result { use Machine::*; match self { Asm(inner) => inner.load_program(program, args), diff --git a/tests/test_resume2.rs b/tests/test_resume2.rs index be79b280..24a17fe4 100644 --- a/tests/test_resume2.rs +++ b/tests/test_resume2.rs @@ -62,15 +62,13 @@ fn test_resume2_secp256k1_asm_2_interpreter_2_asm() { let mut machine1 = MachineTy::Asm.build(data_source.clone(), version); machine1.set_max_cycles(100000); - machine1 - .load_program(&vec![ - "secp256k1_bench".into(), - "033f8cf9c4d51a33206a6c1c6b27d2cc5129daa19dbd1fc148d395284f6b26411f".into(), - "304402203679d909f43f073c7c1dcf8468a485090589079ee834e6eed92fea9b09b06a2402201e46f1075afa18f306715e7db87493e7b7e779569aa13c64ab3d09980b3560a3".into(), - "foo".into(), - "bar".into(), - ]) - .unwrap(); + machine1.load_program([ + "secp256k1_bench", + "033f8cf9c4d51a33206a6c1c6b27d2cc5129daa19dbd1fc148d395284f6b26411f", + "304402203679d909f43f073c7c1dcf8468a485090589079ee834e6eed92fea9b09b06a2402201e46f1075afa18f306715e7db87493e7b7e779569aa13c64ab3d09980b3560a3", + "foo", + "bar", + ].into_iter().map(|e| Ok(e.into()))).unwrap(); let result1 = machine1.run(); assert_eq!(result1.unwrap_err(), Error::CyclesExceeded); let snapshot1 = machine1.snapshot().unwrap(); @@ -115,7 +113,7 @@ fn test_resume2_load_data_asm_2_interpreter() { let mut machine1 = MachineTy::Asm.build(data_source.clone(), version); machine1.set_max_cycles(300000); machine1 - .load_program(&vec!["resume2_load_data".into()]) + .load_program([Ok("resume2_load_data".into())].into_iter()) .unwrap(); let result1 = machine1.run(); assert!(result1.is_err()); @@ -149,7 +147,7 @@ fn test_resume2_load_data_interpreter_2_asm() { let mut machine1 = MachineTy::Interpreter.build(data_source.clone(), version); machine1.set_max_cycles(300000); machine1 - .load_program(&vec!["resume2_load_data".into()]) + .load_program([Ok("resume2_load_data".into())].into_iter()) .unwrap(); let result1 = machine1.run(); assert!(result1.is_err()); @@ -179,7 +177,9 @@ pub fn resume_asm_2_asm(version: u32, except_cycles: u64) { // The cycles required for complete execution is 4194622 let mut machine1 = MachineTy::Asm.build(data_source.clone(), version); machine1.set_max_cycles(except_cycles - 30); - machine1.load_program(&vec!["alloc_many".into()]).unwrap(); + machine1 + .load_program([Ok("alloc_many".into())].into_iter()) + .unwrap(); let result1 = machine1.run(); assert!(result1.is_err()); assert_eq!(result1.unwrap_err(), Error::CyclesExceeded); @@ -199,7 +199,9 @@ pub fn resume_asm_2_asm_2_asm(version: u32, except_cycles: u64) { let mut machine1 = MachineTy::Asm.build(data_source.clone(), version); machine1.set_max_cycles(1000000); - machine1.load_program(&vec!["alloc_many".into()]).unwrap(); + machine1 + .load_program([Ok("alloc_many".into())].into_iter()) + .unwrap(); let result1 = machine1.run(); assert!(result1.is_err()); assert_eq!(result1.unwrap_err(), Error::CyclesExceeded); @@ -227,7 +229,9 @@ pub fn resume_asm_2_interpreter(version: u32, except_cycles: u64) { let mut machine1 = MachineTy::Asm.build(data_source.clone(), version); machine1.set_max_cycles(except_cycles - 30); - machine1.load_program(&vec!["alloc_many".into()]).unwrap(); + machine1 + .load_program([Ok("alloc_many".into())].into_iter()) + .unwrap(); let result1 = machine1.run(); assert!(result1.is_err()); assert_eq!(result1.unwrap_err(), Error::CyclesExceeded); @@ -248,7 +252,9 @@ pub fn resume_interpreter_2_interpreter(version: u32, except_cycles: u64) { let mut machine1 = MachineTy::Interpreter.build(data_source.clone(), version); machine1.set_max_cycles(except_cycles - 30); - machine1.load_program(&vec!["alloc_many".into()]).unwrap(); + machine1 + .load_program([Ok("alloc_many".into())].into_iter()) + .unwrap(); let result1 = machine1.run(); assert!(result1.is_err()); assert_eq!(result1.unwrap_err(), Error::CyclesExceeded); @@ -268,7 +274,9 @@ pub fn resume_interpreter_2_asm(version: u32, except_cycles: u64) { let mut machine1 = MachineTy::Interpreter.build(data_source.clone(), version); machine1.set_max_cycles(except_cycles - 30); - machine1.load_program(&vec!["alloc_many".into()]).unwrap(); + machine1 + .load_program([Ok("alloc_many".into())].into_iter()) + .unwrap(); let result1 = machine1.run(); assert!(result1.is_err()); assert_eq!(result1.unwrap_err(), Error::CyclesExceeded); @@ -288,7 +296,9 @@ pub fn resume_interpreter_with_trace_2_asm_inner(version: u32, except_cycles: u6 let mut machine1 = MachineTy::InterpreterWithTrace.build(data_source.clone(), version); machine1.set_max_cycles(except_cycles - 30); - machine1.load_program(&vec!["alloc_many".into()]).unwrap(); + machine1 + .load_program([Ok("alloc_many".into())].into_iter()) + .unwrap(); let result1 = machine1.run(); assert!(result1.is_err()); assert_eq!(result1.unwrap_err(), Error::CyclesExceeded); @@ -442,7 +452,10 @@ enum Machine { } impl Machine { - fn load_program(&mut self, args: &[Bytes]) -> Result { + fn load_program( + &mut self, + args: impl ExactSizeIterator>, + ) -> Result { use Machine::*; match self { Asm(inner, context) => { @@ -607,7 +620,9 @@ pub fn test_sc_after_snapshot2() { let mut machine1 = MachineTy::Interpreter.build(data_source.clone(), VERSION2); machine1.set_max_cycles(5); - machine1.load_program(&vec!["main".into()]).unwrap(); + machine1 + .load_program([Ok("main".into())].into_iter()) + .unwrap(); let result1 = machine1.run(); assert!(result1.is_err()); assert_eq!(result1.unwrap_err(), Error::CyclesExceeded); @@ -628,7 +643,9 @@ pub fn test_store_bytes_twice() { let mut machine = MachineTy::Asm.build(data_source.clone(), VERSION2); machine.set_max_cycles(u64::MAX); - machine.load_program(&vec!["main".into()]).unwrap(); + machine + .load_program([Ok("main".into())].into_iter()) + .unwrap(); match machine { Machine::Asm(ref mut inner, ref ctx) => { @@ -661,7 +678,9 @@ pub fn test_mixing_snapshot2_writes_with_machine_raw_writes() { let mut machine = MachineTy::Asm.build(data_source.clone(), VERSION2); machine.set_max_cycles(u64::MAX); - machine.load_program(&vec!["main".into()]).unwrap(); + machine + .load_program([Ok("main".into())].into_iter()) + .unwrap(); match machine { Machine::Asm(ref mut inner, ref ctx) => { diff --git a/tests/test_simple.rs b/tests/test_simple.rs index 1c9f6bc9..5c6d3cd1 100644 --- a/tests/test_simple.rs +++ b/tests/test_simple.rs @@ -42,7 +42,7 @@ pub fn test_simple_cycles() { .instruction_cycle_func(Box::new(dummy_cycle_func)) .build(); machine - .load_program(&buffer, &vec!["simple".into()]) + .load_program(&buffer, [Ok("simple".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_ok()); @@ -61,7 +61,7 @@ pub fn test_simple_max_cycles_reached() { .instruction_cycle_func(Box::new(dummy_cycle_func)) .build(); machine - .load_program(&buffer, &vec!["simple".into()]) + .load_program(&buffer, [Ok("simple".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_err()); @@ -83,7 +83,7 @@ pub fn test_simple_loaded_bytes() { DefaultCoreMachine::>::new(ISA_IMC, VERSION0, u64::max_value()); let mut machine = DefaultMachineBuilder::new(core_machine).build(); let bytes = machine - .load_program(&buffer, &vec!["simple".into()]) + .load_program(&buffer, [Ok("simple".into())].into_iter()) .unwrap(); assert_eq!(bytes, 3831); } @@ -99,7 +99,7 @@ pub fn test_simple_cycles_overflow() { .build(); machine.set_cycles(u64::MAX - 10); machine - .load_program(&buffer, &vec!["simple".into()]) + .load_program(&buffer, [Ok("simple".into())].into_iter()) .unwrap(); let result = machine.run(); assert!(result.is_err()); diff --git a/tests/test_versions.rs b/tests/test_versions.rs index 40921bcd..160accb4 100644 --- a/tests/test_versions.rs +++ b/tests/test_versions.rs @@ -21,7 +21,7 @@ fn create_rust_machine( let mut machine = DefaultMachineBuilder::>::new(core_machine).build(); machine - .load_program(&buffer, &vec![program.into()]) + .load_program(&buffer, [Ok(program.into())].into_iter()) .unwrap(); machine } @@ -33,7 +33,7 @@ fn create_asm_machine(program: String, version: u32) -> AsmMachine { let core = DefaultMachineBuilder::>::new(asm_core).build(); let mut machine = AsmMachine::new(core); machine - .load_program(&buffer, &vec![program.into()]) + .load_program(&buffer, [Ok(program.into())].into_iter()) .unwrap(); machine } @@ -239,7 +239,7 @@ pub fn test_rust_version0_unaligned64() { let core_machine = DefaultCoreMachine::::new(ISA_IMC, VERSION0, u64::max_value()); let mut machine = DefaultMachineBuilder::>::new(core_machine).build(); - let result = machine.load_program(&buffer, &vec![program.into()]); + let result = machine.load_program(&buffer, [Ok(program.into())].into_iter()); assert!(result.is_err()); assert_eq!(result.err(), Some(Error::MemWriteOnExecutablePage)); } @@ -261,7 +261,7 @@ pub fn test_asm_version0_unaligned64() { let asm_core = AsmCoreMachine::new(ISA_IMC, VERSION0, u64::max_value()); let core = DefaultMachineBuilder::>::new(asm_core).build(); let mut machine = AsmMachine::new(core); - let result = machine.load_program(&buffer, &vec![program.into()]); + let result = machine.load_program(&buffer, [Ok(program.into())].into_iter()); assert!(result.is_err()); assert_eq!(result.err(), Some(Error::MemWriteOnExecutablePage)); } @@ -344,7 +344,7 @@ pub fn test_asm_version1_asm_trace_bug() { .build(); AsmMachine::new(machine) }; - machine.load_program(&buffer, &[]).unwrap(); + machine.load_program(&buffer, [].into_iter()).unwrap(); let result = machine.run(); assert_eq!(result, Err(Error::CyclesExceeded)); @@ -361,7 +361,7 @@ pub fn test_asm_version2_asm_trace_bug() { .build(); AsmMachine::new(machine) }; - machine.load_program(&buffer, &[]).unwrap(); + machine.load_program(&buffer, [].into_iter()).unwrap(); let result = machine.run(); assert_eq!(result, Err(Error::MemOutOfBound)); @@ -383,7 +383,7 @@ pub fn test_trace_version1_asm_trace_bug() { .build(), ) }; - machine.load_program(&buffer, &[]).unwrap(); + machine.load_program(&buffer, [].into_iter()).unwrap(); let result = machine.run(); assert_eq!(result, Err(Error::CyclesExceeded)); @@ -405,7 +405,7 @@ pub fn test_trace_version2_asm_trace_bug() { .build(), ) }; - machine.load_program(&buffer, &[]).unwrap(); + machine.load_program(&buffer, [].into_iter()).unwrap(); let result = machine.run(); assert_eq!(result, Err(Error::MemOutOfBound)); From 489d97248c7510821839ab02d9c77d4a96cbee2d Mon Sep 17 00:00:00 2001 From: Mohanson Date: Wed, 27 Nov 2024 20:53:38 +0800 Subject: [PATCH 2/2] Fix the error given by deny (#446) * Fix the error given by deny * Allow Unicode-3.0 License --- Cargo.toml | 4 +- deny.toml | 233 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 225 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c507e8fc..2ffa0d96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,8 +37,8 @@ rand = "0.7.3" cc = "1.0" [dev-dependencies] -criterion = "0.4.0" -proptest = "0.9.1" +criterion = "0.5.1" +proptest = "1.5.0" lazy_static = "1.4.0" [target.'cfg(not(target_os = "windows"))'.dev-dependencies] diff --git a/deny.toml b/deny.toml index 2d331756..84cdf0ab 100644 --- a/deny.toml +++ b/deny.toml @@ -1,11 +1,93 @@ +# This template contains all of the possible sections and their default values + +# Note that all fields that take a lint level have these possible values: +# * deny - An error will be produced and the check will fail +# * warn - A warning will be produced, but the check will not fail +# * allow - No warning or error will be produced, though in some cases a note +# will be + +# The values provided in this template are the default values that will be used +# when any section or field is not specified in your own configuration + +# Root options + +# The graph table configures how the dependency graph is constructed and thus +# which crates the checks are performed against +[graph] +# If 1 or more target triples (and optionally, target_features) are specified, +# only the specified targets will be checked when running `cargo deny check`. +# This means, if a particular package is only ever used as a target specific +# dependency, such as, for example, the `nix` crate only being used via the +# `target_family = "unix"` configuration, that only having windows targets in +# this list would mean the nix crate, as well as any of its exclusive +# dependencies not shared by any other crates, would be ignored, as the target +# list here is effectively saying which targets you are building for. +targets = [ + # The triple can be any string, but only the target triples built in to + # rustc (as of 1.40) can be checked against actual config expressions + #"x86_64-unknown-linux-musl", + # You can also specify which target_features you promise are enabled for a + # particular target. target_features are currently not validated against + # the actual valid features supported by the target architecture. + #{ triple = "wasm32-unknown-unknown", features = ["atomics"] }, +] +# When creating the dependency graph used as the source of truth when checks are +# executed, this field can be used to prune crates from the graph, removing them +# from the view of cargo-deny. This is an extremely heavy hammer, as if a crate +# is pruned from the graph, all of its dependencies will also be pruned unless +# they are connected to another crate in the graph that hasn't been pruned, +# so it should be used with care. The identifiers are [Package ID Specifications] +# (https://doc.rust-lang.org/cargo/reference/pkgid-spec.html) +#exclude = [] +# If true, metadata will be collected with `--all-features`. Note that this can't +# be toggled off if true, if you want to conditionally enable `--all-features` it +# is recommended to pass `--all-features` on the cmd line instead +all-features = false +# If true, metadata will be collected with `--no-default-features`. The same +# caveat with `all-features` applies +no-default-features = false +# If set, these feature will be enabled when collecting metadata. If `--features` +# is specified on the cmd line they will take precedence over this option. +#features = [] + +# The output table provides options for how/if diagnostics are outputted +[output] +# When outputting inclusion graphs in diagnostics that include features, this +# option can be used to specify the depth at which feature edges will be added. +# This option is included since the graphs can be quite large and the addition +# of features from the crate(s) to all of the graph roots can be far too verbose. +# This option can be overridden via `--feature-depth` on the cmd line +feature-depth = 1 + +# This section is considered when running `cargo deny check advisories` +# More documentation for the advisories section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html [advisories] -vulnerability = "deny" -unmaintained = "warn" -yanked = "deny" -notice = "deny" +# The path where the advisory databases are cloned/fetched into +#db-path = "$CARGO_HOME/advisory-dbs" +# The url(s) of the advisory databases to use +#db-urls = ["https://github.com/rustsec/advisory-db"] +# A list of advisory IDs to ignore. Note that ignored advisories will still +# output a note when they are encountered. +ignore = [ + #"RUSTSEC-0000-0000", + #{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" }, + #"a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish + #{ crate = "a-crate-that-is-yanked@0.1.1", reason = "you can specify why you are ignoring the yanked crate" }, +] +# If this is true, then cargo deny will use the git executable to fetch advisory database. +# If this is false, then it uses a built-in git library. +# Setting this to true can be helpful if you have special authentication requirements that cargo-deny does not support. +# See Git Authentication for more information about setting up git authentication. +#git-fetch-with-cli = true +# This section is considered when running `cargo deny check licenses` +# More documentation for the licenses section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/licenses/cfg.html [licenses] -unlicensed = "deny" +# List of explicitly allowed licenses +# See https://spdx.org/licenses/ for list of possible licenses +# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. allow = [ "Apache-2.0", "BSD-2-Clause", @@ -13,14 +95,145 @@ allow = [ "ISC", "MIT", "Unicode-DFS-2016", + "Unicode-3.0", +] +# The confidence threshold for detecting a license from license text. +# The higher the value, the more closely the license text must be to the +# canonical license text of a valid SPDX license file. +# [possible values: any between 0.0 and 1.0]. +confidence-threshold = 0.8 +# Allow 1 or more licenses on a per-crate basis, so that particular licenses +# aren't accepted for every possible crate as with the normal allow list +exceptions = [ + # Each entry is the crate and version constraint, and its specific allow + # list + #{ allow = ["Zlib"], crate = "adler32" }, +] + +# Some crates don't have (easily) machine readable licensing information, +# adding a clarification entry for it allows you to manually specify the +# licensing information +#[[licenses.clarify]] +# The package spec the clarification applies to +#crate = "ring" +# The SPDX expression for the license requirements of the crate +#expression = "MIT AND ISC AND OpenSSL" +# One or more files in the crate's source used as the "source of truth" for +# the license expression. If the contents match, the clarification will be used +# when running the license check, otherwise the clarification will be ignored +# and the crate will be checked normally, which may produce warnings or errors +# depending on the rest of your configuration +#license-files = [ +# Each entry is a crate relative path, and the (opaque) hash of its contents +#{ path = "LICENSE", hash = 0xbd0eed23 } +#] + +[licenses.private] +# If true, ignores workspace crates that aren't published, or are only +# published to private registries. +# To see how to mark a crate as unpublished (to the official registry), +# visit https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field. +ignore = false +# One or more private registries that you might publish crates to, if a crate +# is only published to private registries, and ignore is true, the crate will +# not have its license(s) checked +registries = [ + #"https://sekretz.com/registry ] -copyleft = "deny" -default = "deny" +# This section is considered when running `cargo deny check bans`. +# More documentation about the 'bans' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/bans/cfg.html [bans] +# Lint level for when multiple versions of the same crate are detected multiple-versions = "warn" -wildcards = "deny" +# Lint level for when a crate version requirement is `*` +wildcards = "allow" +# The graph highlighting used when creating dotgraphs for crates +# with multiple versions +# * lowest-version - The path to the lowest versioned duplicate is highlighted +# * simplest-path - The path to the version with the fewest edges is highlighted +# * all - Both lowest-version and simplest-path are used +highlight = "all" +# The default lint level for `default` features for crates that are members of +# the workspace that is being checked. This can be overridden by allowing/denying +# `default` on a crate-by-crate basis if desired. +workspace-default-features = "allow" +# The default lint level for `default` features for external crates that are not +# members of the workspace. This can be overridden by allowing/denying `default` +# on a crate-by-crate basis if desired. +external-default-features = "allow" +# List of crates that are allowed. Use with care! +allow = [ + #"ansi_term@0.11.0", + #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason it is allowed" }, +] +# List of crates to deny +deny = [ + #"ansi_term@0.11.0", + #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason it is banned" }, + # Wrapper crates can optionally be specified to allow the crate when it + # is a direct dependency of the otherwise banned crate + #{ crate = "ansi_term@0.11.0", wrappers = ["this-crate-directly-depends-on-ansi_term"] }, +] +# List of features to allow/deny +# Each entry the name of a crate and a version range. If version is +# not specified, all versions will be matched. +#[[bans.features]] +#crate = "reqwest" +# Features to not allow +#deny = ["json"] +# Features to allow +#allow = [ +# "rustls", +# "__rustls", +# "__tls", +# "hyper-rustls", +# "rustls", +# "rustls-pemfile", +# "rustls-tls-webpki-roots", +# "tokio-rustls", +# "webpki-roots", +#] +# If true, the allowed features must exactly match the enabled feature set. If +# this is set there is no point setting `deny` +#exact = true + +# Certain crates/versions that will be skipped when doing duplicate detection. +skip = [ + #"ansi_term@0.11.0", + #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason why it can't be updated/removed" }, +] +# Similarly to `skip` allows you to skip certain crates during duplicate +# detection. Unlike skip, it also includes the entire tree of transitive +# dependencies starting at the specified crate, up to a certain depth, which is +# by default infinite. +skip-tree = [ + #"ansi_term@0.11.0", # will be skipped along with _all_ of its direct and transitive dependencies + #{ crate = "ansi_term@0.11.0", depth = 20 }, +] + +# This section is considered when running `cargo deny check sources`. +# More documentation about the 'sources' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/sources/cfg.html [sources] -unknown-registry = "deny" -unknown-git = "deny" +# Lint level for what to happen when a crate from a crate registry that is not +# in the allow list is encountered +unknown-registry = "warn" +# Lint level for what to happen when a crate from a git repository that is not +# in the allow list is encountered +unknown-git = "warn" +# List of URLs for allowed crate registries. Defaults to the crates.io index +# if not specified. If it is specified but empty, no registries are allowed. +allow-registry = ["https://github.com/rust-lang/crates.io-index"] +# List of URLs for allowed Git repositories +allow-git = [] + +[sources.allow-org] +# github.com organizations to allow git sources for +github = [] +# gitlab.com organizations to allow git sources for +gitlab = [] +# bitbucket.org organizations to allow git sources for +bitbucket = []