ink-examples icon indicating copy to clipboard operation
ink-examples copied to clipboard

Errors when using "cargo-contract" v 5.0.3.

Open CasiniNift opened this issue 10 months ago • 5 comments

I was doing this ink! example . When I did "cargo contract build" , I would always get this error: Image

If I use cargo contract v 4.1.1, I don't get any issues.

I think there are several ink! examples in the repo that do not work if you use v5 for cargo contracts.

CasiniNift avatar Feb 25 '25 08:02 CasiniNift

I got same errors. But this project is compiled by using cargo-contract "4.1.1". So I think this project might not be compatible with latest version of ink!.

Image Image

realtakahashi avatar Feb 25 '25 08:02 realtakahashi

@CasiniNift @realtakahashi Thanks for reporting.

This is likely caused by "unsafe" usize to u8 conversions originating from code generated by the derived implementations of the SCALE Encode and Decode traits.

cargo-contract v5.0.3 (https://github.com/use-ink/cargo-contract/releases/tag/v5.0.3) introduced these checks against such "unsafe" conversions.

You can read more about it in this PR (https://github.com/use-ink/cargo-contract/pull/1895).

For now, if this is blocking you, you can use cargo-contract v5.0.2, as we figure out the best way to handle this case.

davidsemakula avatar Feb 25 '25 12:02 davidsemakula

@davidsemakula thank you for the clarification. I have the same error when I use v5.0.2. I am using the same code in the example.

CasiniNift avatar Feb 25 '25 14:02 CasiniNift

@CasiniNift be sure to run cargo clean before running cargo contract build after installing v5.0.2

If that sill fails for some reason, you can try adding #[allow(clippy::cast_possible_truncation)] just above this line. That should disable the check for the offending Enum in this example.

davidsemakula avatar Feb 25 '25 14:02 davidsemakula

@davidsemakula adding #[allow(clippy::cast_possible_truncation)] fixes the problem, thank you!

CasiniNift avatar Feb 25 '25 15:02 CasiniNift

Closing as root cause was solved upstream in parity-scale-code, see links below for details

  • https://github.com/paritytech/parity-scale-codec/issues/713
  • https://github.com/paritytech/parity-scale-codec/pull/715

davidsemakula avatar Sep 24 '25 20:09 davidsemakula