How to extract tx signatures in predicates?

There is an example of signatures recovery in predicates: Signatures example - The Fuel Rust SDK.

The problem is that the signed message in this example is always an array of zeroes (which means that the signatures could be reused). The more robust solution for multisigs would’ve been to sign the transaction itself instead of the predefined array.

Is there a way to extract a list of transaction signatures in predicates?

1 Like

I’m not sure I understand the question, predicates are stateless so what transaction are you referring to here?

As far as I understand if you want the predicate to use something else as the signed message, you’d have to pass that to it as an argument.

Yeah, predicates are stateless, but I thought that in the predicate code you can introspect the transaction which uses that predicate, isn’t that correct?

In my understanding, it would’ve been possible to implement multi-sig transactions on top of predicates if:

  1. N out of M accounts sign the transaction that aims to spend assets from a predicate;
  2. You can extract these signatures in the predicate’s sway code and verify them

I think that the proper way to do this it to sign the transaction (or transaction hash). If you sign an arbitrary message and pass it as a predicate argument, it’ll be possible to reproduce by anyone in the future.
Also, you cannot pass the signed transaction hash as a predicate argument, because this will change the transaction hash (and you won’t be able to verify the signature in sway). Therefore I have a questions if it’s possible to extract signatures from the transaction :slight_smile:

Oh ok, I see what you mean, I think.

You should be able to get info about the current transaction the regular way and sign on something like std::tx::tx_id().

Yeah, but how exactly can I extract current tx signatures in sway predicate code? All I found is some assembler code on public github which doesn’t work for me: multisig-predicate/src/main.sw at main · recizk/multisig-predicate · GitHub

Are you talking about the transaction witnesses?
There’s accessors for these and the rest of the transaction fields in std::tx

Oh, I see, thanks! Should I use std::tx::tx_witness_data<T>(index: u64)? What should be the T type parameter in that context?

One question. I know that this technology is gonna be a game changer. But how easy is gonna be to implement for new devs or projects with old technology?

Yes, it is possible to extract a list of transaction signatures within predicates. The exact method of extracting signatures may vary depending on the specific blockchain platform or programming language you are working with. However, I can provide you with a general approach.

When executing a transaction in a blockchain system, the transaction object typically contains a field where signatures can be included. In many cases, this field is an array or a list that can store multiple signatures.

To extract a list of transaction signatures within a predicate, you would typically follow these steps:

  1. Retrieve the transaction object: Obtain the transaction object that contains the signatures you want to extract. This could be done using appropriate blockchain libraries or APIs provided by the blockchain platform.

  2. Access the signature field: Once you have the transaction object, you need to access the field that stores the signatures. The exact field name and structure may vary depending on the blockchain platform and the programming language you are using. For example, in Ethereum, the signature field is usually named v, r, and s, which represent the ECDSA components of the signature.

  3. Extract the signatures: Iterate through the signature field and extract the individual signatures. Depending on the structure of the signature field, you may need to decode or parse each signature to obtain the necessary information.

4.Store the extracted signatures: As you extract each signature, you can store them in a list or an array data structure for further processing or analysis within your predicate.

1 Like