Suggest Using Safe Addition and Subtraction Functions for Enhanced Security #597
Replies: 2 comments
-
Hello, can I pick this one up? |
Beta Was this translation helpful? Give feedback.
-
I remember during the early stages of the project, we had an internal discussion about safe operations, such as 1- Check and execute. In the first approach (Check and execute), when we want to execute a transaction, we need to ensure that the input data is also valid. In Pactus, we followed the second approach: check, then execute. If you examine the Pactus code, you can find some basic checks in the Another issue with safe operations comes down to the preference or taste of developers. Imagine we have a At the moment, it is very unlikely that we want to add safe operation methods, even in the |
Beta Was this translation helpful? Give feedback.
-
Description
I have noticed that the current implementation of addition and subtraction functions uses the + and - operators to perform arithmetic operations. While this approach is common, it may lead to potential integer overflow or underflow issues, especially when dealing with large numbers. To enhance the security and robustness of the code, I suggest using the safe addition and subtraction functions provided below(just for example):
These safe addition and subtraction functions include checks for potential overflow and underflow scenarios, which help prevent unintended behavior and keep the calculations within the safe bounds of the int64 data type.
By adopting these safe functions in the codebase, we can minimize the risk of unexpected behavior caused by integer overflow or underflow, making the system more reliable and secure, especially in scenarios involving large numeric values.
Thank you for considering this suggestion.
Beta Was this translation helpful? Give feedback.
All reactions