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

Passing unit value as argument to function RS-E1015 major bugrisk #2690

Closed
philipjonsen opened this issue Sep 22, 2024 · 1 comment
Closed

Comments

@philipjonsen
Copy link

Description
This issue is raised when a unit value is passed to a function call without using the unit literal: (). If this is intentional, extract the argument into a separate expression and replace it with (). Otherwise, consider revisiting this function call.

Bad practice

`fn foo<T: Debug>(t: T) {}

let v = vec![1].extend(&[2, 3]);
foo(v); // v is () here, and not [1, 2, 3]

Recommened:

`fn foo<T: Debug>(t: T) {}

let v = vec![1].extend(&[2, 3]);
foo(v); // v is () here, and not `[1, 2, 3]``

The argument(s) to Ok contain the unit-type
arbitrator/wasm-libraries/user-test/src/program.rs

fn write_slice(&self, ptr: GuestPtr, src: &[u8]) -> Result<(), MemoryBoundsError> {
    self.check_memory_access(ptr, src.len() as u32)?;
    unsafe { Ok(STATIC_MEM.write_slice(ptr, src)) }
}

fn say<D: Display>(&self, text: D) {

The argument(s) to Ok contain the unit-type
arbitrator/wasm-libraries/user-test/src/program.rs

fn write_u32(&mut self, ptr: GuestPtr, x: u32) -> Result<(), MemoryBoundsError> {
    self.check_memory_access(ptr, 4)?;
    unsafe { Ok(STATIC_MEM.write_u32(ptr, x)) }
}

fn write_slice(&self, ptr: GuestPtr, src: &[u8]) -> Result<(), MemoryBoundsError> {

The argument(s) to Ok contain the unit-type
arbitrator/wasm-libraries/user-host/src/program.rs

fn write_slice(&self, ptr: GuestPtr, src: &[u8]) -> Result<(), MemoryBoundsError> {
    self.check_memory_access(ptr, src.len() as u32)?;
    unsafe { Ok(STATIC_MEM.write_slice(ptr, src)) }
}

fn say<D: Display>(&self, text: D) {

The argument(s) to Ok contain the unit-type
arbitrator/wasm-libraries/user-host/src/program.rs

fn write_u32(&mut self, ptr: GuestPtr, x: u32) -> Result<(), MemoryBoundsError> {
    self.check_memory_access(ptr, 4)?;
    unsafe { Ok(STATIC_MEM.write_u32(ptr, x)) }
}

fn write_slice(&self, ptr: GuestPtr, src: &[u8]) -> Result<(), MemoryBoundsError> {

The argument(s) to update contain the unit-type
arbitrator/prover/src/machine.rs

let mut h = Keccak256::new();
h.update("Call indirect:");
h.update((table as u64).to_be_bytes());
h.update(ty.hash());
h.finalize().into()

}

The argument(s) to evm_stack::StackExecutor::new_with_precompiles contain the unit-type
arbitrator/prover/fuzz/fuzz_targets/osp.rs

    StackSubstateMetadata::new(MAX_OSP_GAS, &EVM_CONFIG),
    &*EVM_BACKEND,
);
evm_stack::StackExecutor::new_with_precompiles(stack, &EVM_CONFIG, &())

}

fn test_proof(

@joshuacolvin0
Copy link
Member

Linters typically produce a lot of false positive hits, none of this is useful information.

@joshuacolvin0 joshuacolvin0 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants