Skip to content

Underflow In Transaction In Debug Mode #17

@necrashter

Description

@necrashter

When you run the program in debug mode, create transactions and commit them into a block, you will get the following error:

thread 'main' panicked at 'attempt to subtract with overflow', src/handlers.rs:592:37

The faulty code at src/handlers.rs:592:37 is:

                if let Some(from) = users_store.get_mut(source) {
                    from.balance -= transaction.amount - db.config.tx_traffic_reward;
                }

As @yigitsever suspected, this works correctly in release mode because these u32 values act like i32.
However, this is actually an undefined behavior. Hence it causes the error above in debug mode.

Although this requires some proficiency in Rust, I think it's a good first issue for beginners.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions