-
Notifications
You must be signed in to change notification settings - Fork 60
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 account balance overflow #377
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why do we need a new dependency for all this (
primitive_types::U256
)? Can't we use the existingBigUint
? - I don't know if we want to introduce the breaking semantic change of requiring a string instead of a number in the /mint endpoint. Can't we deserialize a big numeric JSON literal into the desired numeric Rust type (be it U256 or BigUint), without it needing to be a string?
cc: @marioiordanov
It'd require creating a custom
Rust's built-in numeric types only go up to u128, so there's no built-in way to deserialize a u256 directly. I've you have any idea on how to do this, I'm down to change it. |
It's possible for deserialising directly from some number. Just deserialize to serde_json::Value::Number. Then convert to string and then convert to U256 |
I ran an experiment and it seems that precision is lost that way: experiment link |
The experiment doesn't emulate starknet-devnet-rs, because it uses arbitrary precision in the crate that the file is |
Wow, didn't know that. I ran the code as a devnet test and indeed the precision is preserved. |
Thanks for the great tip @marioiordanov! Didn't know that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we now lose the U256 dependency?
Could |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we now lose the U256 dependency?
Could
ethers
be used instead or do you insist on a separate own struct for U256?starknet-devnet-core
already uses it (it usesprimitive-types
itself too)
I meant losing the primitive-types
dependency. But I guess an extra dependency is not such a big issue; your PR is good, so let's merge it. Thank you for the contribution and the patience.
Closes #110
Usage related changes
amount must be a string instead of plain integer in/mint
Development related changes
Checklist:
./scripts/format.sh
./scripts/clippy_check.sh
./scripts/check_unused_deps.sh
cargo test
These 2 tests are failing locally for me: