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

Casting errors in client-cli #187

Open
3 tasks done
mszulcz-mitre opened this issue Sep 28, 2022 · 0 comments · May be fixed by #188
Open
3 tasks done

Casting errors in client-cli #187

mszulcz-mitre opened this issue Sep 28, 2022 · 0 comments · May be fixed by #188
Labels
fix/bug Fixes errant behavior

Comments

@mszulcz-mitre
Copy link
Contributor

Affected Branch

trunk

Basic Diagnostics

  • I've pulled the latest changes on the affected branch and the issue is still present.

  • The issue is reproducible in docker

Description

The executable compiled from client-cli.cpp is used to interact with the transaction processor. In the "Launch System" section in README.md, it's called to mint new coins, print the balance of a wallet, make a new wallet, and send coins between wallets. For example, to mint new coins, the command is:

# ./build/src/uhs/client/client-cli 2pc-compose.cfg mempool0.dat wallet0.dat mint 10 5

When calling client-cli with the commands "mint", "send", or "fan", the code may exhibit a casting error. For example, if the mint command is accidentally called with a negative number, such as in

# ./build/src/uhs/client/client-cli 2pc-compose.cfg mempool0.dat wallet0.dat mint -1 5

the code would cast -1 to 18446744073709551615 and would create 18446744073709551615 new utxos without warning. If the mint command is invoked with -18446744073709551615 outputs, it actually only makes one:

root@102611d59e8f:/opt/tx-processor# ./build/src/uhs/client/client-cli 2pc-compose.cfg mempool0.dat wallet0.dat mint -18446744073709551615 5
[2022-09-28 05:18:56.541] [WARN ] Existing wallet file not found
[2022-09-28 05:18:56.541] [WARN ] Existing client file not found
34162c6120b9ddb3d1dd6f69b4898ba2af4e4e6868e3b099d39316c133ab54ae
root@102611d59e8f:/opt/tx-processor# ./build/src/uhs/client/client-cli 2pc-compose.cfg mempool0.dat wallet0.dat info
Balance: $0.05, UTXOs: 1, pending TXs: 0

This is caused by the use of std::stoull and std::stoul, which are used to convert strings to unsigned integers. For example, here's the function mint_command:

auto mint_command(cbdc::client& client, const std::vector<std::string>& args)
    -> bool {
    static constexpr auto min_mint_arg_count = 7;
    if(args.size() < min_mint_arg_count) {
        std::cerr << "Mint requires args <n outputs> <output value>"
                  << std::endl;
        return false;
    }

    const auto n_outputs = std::stoull(args[5]);
    const auto output_val = std::stoul(args[6]);

Code of Conduct

  • I agree to follow this project's Code of Conduct
@mszulcz-mitre mszulcz-mitre added the fix/bug Fixes errant behavior label Sep 28, 2022
@HalosGhost HalosGhost linked a pull request Sep 28, 2022 that will close this issue
@HalosGhost HalosGhost removed their assignment Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix/bug Fixes errant behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants