1

thread 'main' panicked at 'called Result::unwrap()on anErr value: ParseIntError { kind: InvalidDigit }', lang/syn/src/idl/mod.rs:214:76

I'm new to anchor and using it for past two weeks. I wanted to use a helper function eth_addr() for a signature verification. So I implemented it in a enum, when I try to use it in the lib.rs it throws me the above error. I have implemented eth_addr() returning a const value of usize.

type.rs

  pub const PUB_KEY_SIZE: usize = 20;

   pub fn eth_addr(&self) -> [u8; PUB_KEY_SIZE] {
       match self {
           Self::MintSignature {
               eth_addr,
               sig_r: _,
               sig_s: _,
               sig_v: _,
               msg: _,
           } => *eth_addr,
       }

lib.rs

 if state.authority != secp256k1_instruction_data.eth_addr() {
            msg!("Error: Invalid signer for the mint signature");
            return err!(Error::InvalidSigner);
        }

secp256k1_instruction_data is the unpacked instruction data of enum Secp256k1InstructionData where eth_addr() has been implemented.

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseIntError { kind: InvalidDigit }', lang/syn/src/idl/mod.rs:214:76
stack backtrace:
   0:        0x10466c0dc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h188b7ef1c7993e78
   1:        0x1043dfd44 - core::fmt::write::he84a3004e7af3f34
   2:        0x104647a58 - std::io::Write::write_fmt::h9370b50affaab0be
   3:        0x104670f98 - std::panicking::default_hook::{{closure}}::hc074f8023cce83ca
   4:        0x104671e10 - std::panicking::rust_panic_with_hook::h1e59e224d558a492
   5:        0x1046719dc - std::panicking::begin_panic_handler::{{closure}}::he1a9d6ab32bfd8c6
   6:        0x104671954 - std::sys_common::backtrace::__rust_end_short_backtrace::he9b94791b02f48cd
   7:        0x104671920 - _rust_begin_unwind
   8:        0x1047f5950 - core::panicking::panic_fmt::h9fec86f6a9c4146e
   9:        0x1047f5b08 - core::result::unwrap_failed::h04f08301b97a771c
  10:        0x104395958 - <anchor_syn::idl::IdlType as core::str::traits::FromStr>::from_str::array_from_str::h2ff42bfe7bf35b61
  11:        0x104394dfc - <anchor_syn::idl::IdlType as core::str::traits::FromStr>::from_str::hf718c6ba731d402a
  12:        0x104357c4c - anchor_syn::idl::file::to_idl_type::h1ea386dfbceee694
  13:        0x104358094 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once::haa47edb8ccd6241e
  14:        0x1043585bc - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once::hd89ac91d85975486
  15:        0x10439b68c - <core::iter::adapters::filter_map::FilterMap<I,F> as core::iter::traits::iterator::Iterator>::try_fold::heed2912c2746a817
  16:        0x10437afac - <core::iter::adapters::GenericShunt<I,R> as core::iter::traits::iterator::Iterator>::next::h6c24577be838490d
  17:        0x10435a23c - anchor_syn::idl::file::parse_ty_defs::h11873edcbd63c65c
  18:        0x10430d950 - anchor_syn::idl::file::parse::hfbb2577322f5f915
  19:        0x104288dc0 - anchor_cli::extract_idl::h47360cc7ebe268b6
  20:        0x104311dd8 - anchor_cli::build_cwd::h62d1ef82604fd1c5
  21:        0x1043115d4 - anchor_cli::build_all::h1cfceec859897162
  22:        0x104287048 - anchor_cli::build::h564fd188568c0bb6
  23:        0x104275a70 - anchor_cli::entry::h0256f27efce20e7b
  24:        0x1041b4f38 - anchor::main::h3ca4f6d7a3d2f4cf
  25:        0x1041b34cc - std::sys_common::backtrace::__rust_begin_short_backtrace::h16950677100173d7
  26:        0x1041b34f0 - std::rt::lang_start::{{closure}}::ha35d8116774c78f5
  27:        0x1041b55a0 - _main

Please let me know if any further info is needed.

1
  • You may need to add more information about your full state and instruction info, since ParseIntError makes it look like there's some invalid data passed in from the outside
    – Jon C
    Oct 17, 2022 at 22:06

1 Answer 1

1

The ParseIntError is because an InvalidDigit is passed somewhere. In your example, this error is generated in the line:

pub fn eth_addr(&self) -> [u8; PUB_KEY_SIZE] {

Try to use a number instead a varible, something like this:

pub fn eth_addr(&self) -> [u8; 20] {

It is possible that variables are not accepted there, check it.

1
  • Yes that's exactly the issue. I found out and fixed it. Thanks for the help.
    – Elliot
    Dec 26, 2022 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.