Skip to content

Commit

Permalink
ec-recover (FuelLabs#5)
Browse files Browse the repository at this point in the history
* Add ecr lib

* Add todo comment

* Add recover_pubkey and refactor ecr

* Fixup

* Update comments

* Add comments to ec-recover asm block

* Modify asm

* Clean up asm

* Fix B512 field assignment

* Fix ordering of lib deps

* Remove ec_recover, to be added in separate PR

* Clean up comments
  • Loading branch information
nfurfaro authored Jan 11, 2022
1 parent 267ae8a commit 57205cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/ecr.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
library ecr;

use ::b512::B512;
use ::address::Address;

/// Recover the address derived from the private key used to sign a message
pub fn ec_recover_address(signature: B512, msg_hash: b256) -> Address {
let address = asm(pub_key_buffer, sig_ptr: signature.hi, hash: msg_hash, addr_buffer, sixty_four: 64) {
move pub_key_buffer sp; // mv sp to pub_key result buffer.
cfei i64;
ecr pub_key_buffer sig_ptr hash; // recover public_key from sig & hash
move addr_buffer sp; // mv sp to addr result buffer.
cfei i32;
s256 addr_buffer pub_key_buffer sixty_four; // hash 64 bytes to the addr_buffer
addr_buffer: b256
};

~Address::from(address)
}
1 change: 1 addition & 0 deletions src/lib.sw
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ dep context;
dep address;
dep block;
dep result;
dep ecr;

use core::*;

0 comments on commit 57205cb

Please sign in to comment.