Skip to content

mint_content_token panics instead of returning an error for invalid content_hash length #485

Description

@RUKAYAT-CODER

Description

TeachLinkBridge::mint_content_token (contracts/teachlink/src/tokenization.rs) validates content_hash with:

crate::validation::BytesValidator::validate_length(&content_hash, 32, 32).unwrap();

If content_hash isn't exactly 32 bytes, this .unwrap() panics the whole contract invocation (HostError: Error(WasmVm, InvalidAction), "caught panic 'called Result::unwrap() on an Err value: InvalidBytesLength'") instead of returning a proper Result::Err with a contract error the caller can handle.

This was discovered because the test_cross_contract_interactions.rs test fixture (content_params()) was passing a 6-byte placeholder (b"QmHash") as content_hash, which panicked 6 different tests once CI was fixed to actually run them (see #484). The test fixture itself has been corrected to use a valid 32-byte hash, but the production .unwrap() should probably be replaced with proper error propagation (e.g. ? returning TokenizationError::InvalidContentHash or similar) so callers get a normal contract error instead of the invocation panicking.

Steps to reproduce

Call mint_content_token with a content_hash that isn't exactly 32 bytes.

Suggested fix

Replace the .unwrap() in mint_content_token with ? (or equivalent), propagating a proper TokenizationError variant instead of panicking.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions