Skip to content

Commit

Permalink
Changed ecrecover recId to uint32
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel.soloviev committed May 17, 2022
1 parent 636699e commit cb62e66
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
9 changes: 7 additions & 2 deletions examples/sign.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract Sign {
// Divide the signature in r, s and v variables
bytes32 r;
bytes32 s;
uint8 v;
uint32 v;

bytes memory rA = new bytes(32);
bytes memory sA = new bytes(32);
Expand All @@ -20,7 +20,12 @@ contract Sign {

r = bytes32(rA);
s = bytes32(sA);
v = uint8(signature[64]);

if (signature.length == 65) {
v = uint8(signature[65]);
} else {
v = uint8(signature[64]) * 256 + uint8(signature[65]);
}

// If the signature is valid (and not malleable), return the signer address
return ecrecover(hash, v, r, s);
Expand Down
3 changes: 1 addition & 2 deletions src/emit/lachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ impl LachainTarget {
fn declare_externals(&self, binary: &mut Binary) {
let u8_ptr_ty = binary.context.i8_type().ptr_type(AddressSpace::Generic);
let u32_ty = binary.context.i32_type();
let u8_ty = binary.context.i8_type();
let void_ty = binary.context.void_type();

let ftype = void_ty.fn_type(&[u8_ptr_ty.into(), u8_ptr_ty.into()], false);
Expand Down Expand Up @@ -716,7 +715,7 @@ impl LachainTarget {
void_ty.fn_type(
&[
u8_ptr_ty.into(), // hashOffset
u8_ty.into(), // vOffset
u32_ty.into(), // v
u8_ptr_ty.into(), // rOffset
u8_ptr_ty.into(), // sOffset
u8_ptr_ty.into(), // resultOffset
Expand Down
2 changes: 1 addition & 1 deletion src/sema/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ static BUILTIN_FUNCTIONS: [Prototype; 27] = [
builtin: Builtin::Ecrecover,
namespace: None,
name: "ecrecover",
args: &[Type::Bytes(32), Type::Uint(8), Type::Bytes(32), Type::Bytes(32)],
args: &[Type::Bytes(32), Type::Uint(32), Type::Bytes(32), Type::Bytes(32)],
ret: &[Type::Address(true)],
target: &[],
doc: "Recover the address associated with the public key from elliptic curve signature or return zero on error",
Expand Down

0 comments on commit cb62e66

Please sign in to comment.