Idea for making solidity contracts more secure. 1. Sprinkle your code with asserts 2. Stripe it away with the compiler for production build Example (not tested) Failing asserts crash the program in unit and fuzz tests. When PROD = true, compiler + optimizer removes Dev.check
This is not good advice. It's generally considered insecure and bad practice to mix testing concerns within production contracts. One of the top causes of bugs are copying/pasting/adding/removing code. If you have code or macros that are toggled depending on environment, youâĶ
Thanks. It's definitely not an advice. It's an idea maybe worth exploring? I don't see the disadvantage. Testing can still be execised properly. Test with PROD = false and then test with PROD = true
if we add asserts while writing the actual code, will there be any need to test it? or are you saying that by doing this we code and test at once? genuinely trying to understand your point of view here
Yes, tests are needed. The purpose is to check parts of code (during testing) that are difficult to check. For example, tests can check the initial and final states after function calls but it's difficult to test the intermediate steps.
Finally, regular practices from C++/Rust are making their way to web3. It is a bit of re-inventing a wheel, but it is a solid practice which is proven by time in web2, I vote for it.
Assert should only be used to test for internal errors, and to check invariants.
This is interesting, but also I can see it biting back. Example: in Rust in debug mode underflows/overflows panic, in prod mode they don't. I've had it before that someone didn't know this and wrote code that would underflow but they thought it'd panic and they were safe.
thanks for innovating a new security standard
Programmer Smart ðĪ
United States āđāļāļĢāļāļāđ
- 1. Good Thursday 27.3K posts
- 2. Happy Friday Eve N/A
- 3. #thursdaymotivation 1,653 posts
- 4. #thursdayvibes 2,279 posts
- 5. #ThursdayThoughts 1,583 posts
- 6. #āļŦāļĨāļīāļāļāļāļĄāļāļāļīāļāļīāļāļāđāļāļ3āļāļĩ2569 742K posts
- 7. LINGORM CH3 CALENDAR SIGN 733K posts
- 8. Nnamdi Kanu 63.2K posts
- 9. #ProofOfFortification N/A
- 10. FEMA 80.3K posts
- 11. Crockett 59.3K posts
- 12. But Jesus 22K posts
- 13. The 2024 88.4K posts
- 14. NO CAP 14.5K posts
- 15. Knicks 14.2K posts
- 16. Shamet 3,201 posts
- 17. FREE HAT 1,902 posts
- 18. Hire American 5,463 posts
- 19. Sam Harris 3,925 posts
- 20. Paint 32.7K posts
Something went wrong.
Something went wrong.