Skip to content

Commit

Permalink
Fix ed25519_verify signature
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Feb 12, 2021
1 parent 5028e89 commit 27d40e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
17 changes: 7 additions & 10 deletions packages/std/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extern "C" {
fn humanize_address(source_ptr: u32, destination_ptr: u32) -> u32;

fn secp256k1_verify(message_hash_ptr: u32, signature_ptr: u32, public_key_ptr: u32) -> u32;
fn verify_ed25519(message_ptr: u32, signature_ptr: u32, public_key_ptr: u32) -> u32;
fn ed25519_verify(message_ptr: u32, signature_ptr: u32, public_key_ptr: u32) -> u32;

fn debug(source_ptr: u32);

Expand Down Expand Up @@ -199,23 +199,20 @@ impl Api for ExternalApi {
}
}

fn ed25519_verify(&self, message: &[u8], signature: &[u8], public_key: &[u8]) -> StdResult<()> {
fn ed25519_verify(&self, message: &[u8], signature: &[u8], public_key: &[u8]) -> bool {
let msg_send = build_region(message);
let msg_send_ptr = &*msg_send as *const Region as u32;
let sig_send = build_region(signature);
let sig_send_ptr = &*sig_send as *const Region as u32;
let pubkey_send = build_region(public_key);
let pubkey_send_ptr = &*pubkey_send as *const Region as u32;

let result = unsafe { verify_ed25519(msg_send_ptr, sig_send_ptr, pubkey_send_ptr) };
if result != 0 {
let error = unsafe { consume_string_region_written_by_vm(result as *mut Region) };
return Err(StdError::generic_err(format!(
"verify_ed25519 error: {}",
error
)));
let result = unsafe { ed25519_verify(msg_send_ptr, sig_send_ptr, pubkey_send_ptr) };
match result {
0 => false,
1 => true,
_ => unreachable!(),
}
Ok(())
}

fn debug(&self, message: &str) {
Expand Down
9 changes: 2 additions & 7 deletions packages/std/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,8 @@ impl Api for MockApi {
}
}

fn ed25519_verify(
&self,
_message: &[u8],
_signature: &[u8],
_public_key: &[u8],
) -> StdResult<()> {
Ok(())
fn ed25519_verify(&self, _message: &[u8], _signature: &[u8], _public_key: &[u8]) -> bool {
true
}

fn debug(&self, message: &str) {
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub trait Api {

fn secp256k1_verify(&self, message_hash: &[u8], signature: &[u8], public_key: &[u8]) -> bool;

fn ed25519_verify(&self, message: &[u8], signature: &[u8], public_key: &[u8]) -> StdResult<()>;
fn ed25519_verify(&self, message: &[u8], signature: &[u8], public_key: &[u8]) -> bool;

/// Emits a debugging message that is handled depending on the environment (typically printed to console or ignored).
/// Those messages are not persisted to chain.
Expand Down

0 comments on commit 27d40e3

Please sign in to comment.