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

Fix potential unsafe casting of transaction count #198

Open
fkrause98 opened this issue Aug 15, 2024 · 0 comments
Open

Fix potential unsafe casting of transaction count #198

fkrause98 opened this issue Aug 15, 2024 · 0 comments

Comments

@fkrause98
Copy link
Contributor

We're casting from u64 to u16 here:

pub fn add_l2_to_l1_message(
    vm_state: &mut VMState,
    opcode: &Opcode,
    state_storage: &mut StateStorage,
) -> Result<(), EraVmError> {
    let key = vm_state.get_register(opcode.src0_index).value;
    let value = vm_state.get_register(opcode.src1_index).value;
    let is_service = opcode.imm0 == 1;
    state_storage.record_l2_to_l1_log(L2ToL1Log {
        key,
        value,
        is_service,
        address: vm_state.current_context()?.contract_address,
        shard_id: 0,
        tx_number: vm_state.tx_number as u16,  // <-------- THIS ONE
    })?;
    Ok(())
}

But the vm's field is actually a u64, so we should check if this is safe or simply change it to avoid bugs/panics.

@fkrause98 fkrause98 changed the title Fix probably unsafe casting of transaction count Fix potential unsafe casting of transaction count Aug 15, 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

1 participant