Skip to content

write fuzz tests for cosmwasm #655

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

Draft
wants to merge 93 commits into
base: main
Choose a base branch
from
Draft

Conversation

faddat
Copy link
Contributor

@faddat faddat commented Apr 22, 2025

This adds some amateurish fuzz tests to cosmwasm. Especially in need of review because I haven't done this befofre and I want to make sure we get meaningful output.

faddat added 21 commits April 22, 2025 14:32
…king

- Introduced a new example in `debug_vectors.go` to demonstrate vector debugging capabilities.
- Enhanced `SafeUnmanagedVector` to track consumption state and provide detailed debug information, including stack traces for consumption attempts.
- Added functions to enable vector debugging and retrieve vector creation/consumption statistics.
- Updated error handling in `StoreCode` and `StoreCodeUnchecked` to ensure proper validation and error messaging.
… for safer memory management

- Updated comments to clarify the purpose of contract functions.
- Replaced instances of copyAndDestroyUnmanagedVector with the safer CopyAndDestroyToSafeVector pattern across multiple contract functions, enhancing memory safety.
- Introduced a new receiveVectorSafe function to handle UnmanagedVector safely, preventing potential double-free issues.
…or improved memory safety

- Replaced all instances of copyAndDestroyUnmanagedVector with CopyAndDestroyToSafeVector in contract functions to enhance memory management.
- Updated comments to reflect the safer pattern being implemented across the codebase.
- Updated test cases to replace instances of copyAndDestroyUnmanagedVector with CopyAndDestroyToSafeVector, ensuring consistent use of safer memory management practices.
- Enhanced comments to clarify the safer approach being implemented in the tests.
- Updated the `Instantiate`, `Execute`, and `Query` methods to use a default `deserCost` value of 1/10000 gas per byte as defined in the VMConfig.
- Replaced direct JSON unmarshalling with `DeserializeResponse` to account for gas costs in the contract function implementations.
- Improved comments to clarify the changes made for gas cost management.
…d unmanaged vector functions

- Introduced `is_available` method in `SafeByteSlice` to check if the byte slice is not consumed and not nil, enhancing defensive programming.
- Added early return in `destroy_unmanaged_vector` to avoid unnecessary consumption of a nil vector.
- Implemented early checks in `safe_unmanaged_vector_to_bytes` to prevent consuming already consumed vectors.
- Updated test assertions for clarity and conciseness in error handling for consumed vectors.
- Introduced #[allow(non_camel_case_types)] attribute to the cache_t struct to suppress warnings related to naming conventions, improving code clarity and compliance with Go's conventions.
- Updated address formats in `ibc_test.go` to use Bech32-compliant addresses for consistency.
- Added comprehensive address validation tests in `internal/api/address_validation_test.go` covering valid and invalid Bech32, Ethereum, and Solana addresses, as well as legacy formats.
- Improved error messages in `api_test.go` for clarity on address validation failures.
- Refactored `mocks.go` to support various address formats and added validation logic for empty and oversized addresses.
- Introduced new tests in `libwasmvm/src/api_test.rs` to validate address formats, ensuring robust testing for address validation logic.
Copy link

mergify bot commented Apr 22, 2025

⚠️ The sha of the head commit of this PR conflicts with #654. Mergify cannot evaluate rules on this PR. ⚠️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant