2

This makes absolutely no sense, but maybe someone has a good suggestion.

We wrote our own client implementation to send extrinsics to a Substrate chain and it has been working fine, until just today, when I changed a string to be longer in the pallet call parameters.

The extrinsic started failing with error code 1010 BadProof (invalid signature) all of a sudden.

I managed to validate all the data again, against the Polkadot UI and the payload is fine. But, once the string gets long enough that it makes the signed payload longer than 256 bytes, the error shows up again.

Under the hood, we use the schnorrkel Rust package to sign, but looking at the code I saw nothing about size limits.

Any ideas?

1 Answer 1

4

When the payload is more than 256 bytes, you need to sign the Blake2-256 hash of the data to sign.

Ref: https://github.com/paritytech/substrate/blob/9a6d706/primitives/runtime/src/generic/unchecked_extrinsic.rs#L207L224

impl<Call, Extra> Encode for SignedPayload<Call, Extra>
where
    Call: Encode,
    Extra: SignedExtension,
{
    /// Get an encoded version of this payload.
    ///
    /// Payloads longer than 256 bytes are going to be `blake2_256`-hashed.
    fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
        self.0.using_encoded(|payload| {
            if payload.len() > 256 {
                f(&blake2_256(payload)[..])
            } else {
                f(payload)
            }
        })
    }
}
1
  • I guess I am not totally crazy after all! Thank you @joepetrowski.
    – georgiosd
    Commented Oct 22, 2022 at 5:58

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.