I’m developing a predicate to validate a signature using Solana network wallets. To accomplish this, I’m utilizing the ed_verify()
function. However, despite passing mocked values for the public key, signature, and message hash, the function consistently fails to return true.
Code of my POC
forc = “0.56.0”
fuel-core = “0.26.0”
sway = “0.59.0”
Predicate code:
predicate;
use std::{
b512::B512,
constants::ZERO_B256,
ecr::{
EcRecoverError,
ed_verify,
},
tx::{
tx_id,
tx_witness_data,
},
};
configurable {
SIGNER: b256 = ZERO_B256,
}
fn main() -> bool {
let signature: B512 = tx_witness_data(0);
let result = ed_verify(SIGNER, signature, tx_id());
return result.is_ok();
}
Error:
How to run the project:
run command pnpm chain:start
to start local network
you can run pnpm build:resources
to generate predicate and script
Run pnpm dev
to start the project
To get a project id you can access this link
1 Like
I changed my script to use the example and receipt true as expected
I’m thinking that the problem could be when I make the conversion of solana public key to b256 pattern.
1 Like
Here is a print of fuelup show
:
nick
June 19, 2024, 9:44am
6
Hi @pedropereiradev ,
Can you try using the example data for the ed_verify function first? The example code can be found here:
/// * `public_key`: [b256] - The public key that signed the message.
/// * `signature`: [B512] - The signature generated by signing a message hash.
/// * `msg_hash`: [b256] - The hashed signed data.
///
/// # Returns
///
/// * [Result<bool, EcRecoverError>] - A verified result or an error.
///
/// # Examples
///
/// ```sway
/// use std::{ecr::ed_verify, b512::B512};
///
/// fn foo() {
/// let pub_key = 0x314fa58689bbe1da2430517de2d772b384a1c1d2e9cb87e73c6afcf246045b10;
/// let msg = b256::zero();
/// let msg_hash = sha256(msg);
/// let hi = 0xf38cef9361894be6c6e0eddec28a663d099d7ddff17c8077a1447d7ecb4e6545;
/// let lo = 0xf5084560039486d3462dd65a40c80a74709b2f06d450ffc5dc00345c6b2cdd00;
/// let signature: B512 = B512::from((hi, lo));
Then, can you try recovering this Solana signature/public key/message with a Typescript or Rust ED25519-dalek library, such as:
Then if you get it recovering, post the code for that here. This will help us rule out any particular cryptography issues.
Fuel uses ED25519-DALEK not sure if that is what Solana uses for their keys:
nick
June 19, 2024, 9:58am
7
Hi @pedropereiradev ,
Can you try using the example data for the ed_verify module first?
let hi_2 = b256::zero();
let lo_2 = 0x44ac566bd156b4fc71a4a4cb2655d3dd360c695edb17dc3b64d611e122fea23d;
let msg_hash_2 = 0xee45573606c96c98ba970ff7cf9511f1b8b25e6bcd52ced30b89df1e4a9c4323;
let signature_2: B512 = B512::from((hi_2, lo_2));
let result_2 = ec_recover_address_r1(signature_2, msg_hash_2);
assert(result_2.is_err());
}
#[test]
fn ecr_ed_verify() {
let pub_key_1 = 0x314fa58689bbe1da2430517de2d772b384a1c1d2e9cb87e73c6afcf246045b10;
let msg_1 = b256::zero();
let msg_hash_1 = sha256(msg_1);
let hi_1 = 0xf38cef9361894be6c6e0eddec28a663d099d7ddff17c8077a1447d7ecb4e6545;
let lo_1 = 0xf5084560039486d3462dd65a40c80a74709b2f06d450ffc5dc00345c6b2cdd00;
let signature_1: B512 = B512::from((hi_1, lo_1));
// A verified public key with signature
let verified_1 = ed_verify(pub_key_1, signature_1, msg_hash_1);
assert(verified_1.is_ok());
Then, can you try recovering this Solana signature/public key/message with a Typescript or Rust ED25519-dalek library, such as:
Then if you get it recovering, post the code for that here. This will help us rule out any particular cryptography issues.
Fuel uses ED25519-DALEK not sure if that is what Solana uses for their keys: