Skip to content

Commit

Permalink
Merge pull request #269 from AleoHQ/feat/signature-verify
Browse files Browse the repository at this point in the history
  • Loading branch information
a h authored Sep 1, 2023
2 parents dd2fd48 + 49d990f commit ae54004
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
9 changes: 9 additions & 0 deletions documentation/aleo/03_language.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ function main:
input r0: address.private;
```

### Signatures

Aleo uses a Schnorr signatures scheme to sign messages with an Aleo private key.
Signatures can be verified in Aleo instructions using the [`sign.verify`](./04_opcodes.md#signverify) instruction.

```aleo
sign.verify sign069ju4e8s66unu25celqycvsv3k9chdyz4n4sy62tx6wxj0u25vqp58hgu9hwyqc63qzxvjwesf2wz0krcvvw9kd9x0rsk4lwqn2acqhp9v0pdkhx6gvkanuuwratqmxa3du7l43c05253hhed9eg6ppzzfnjt06fpzp6msekdjxd36smjltndmxjndvv9x2uecsgngcwsc2qkns4afd r1 r2 into r3;
```

## Layout of an Aleo Program

An Aleo program contains declarations of a [Program ID](#programid), [Imports](#import), [Functions](#function), [Closures](#closure), [Structs](#struct), [Records](#record),
Expand Down
23 changes: 23 additions & 0 deletions documentation/aleo/04_opcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ The following lists show the standard and cryptographic opcodes supported by Ale
| [hash.psd2](#hashpsd2) | Poseidon hash with input rate 2 |
| [hash.psd4](#hashpsd4) | Poseidon hash with input rate 4 |
| [hash.psd8](#hashpsd8) | Poseidon hash with input rate 8 |
| [sign.verify](#signverify) | Verify a Schnorr signature |

## Specification

Expand Down Expand Up @@ -1471,6 +1472,28 @@ Computes the truncated remainder of `first` divided by `second`, wrapping around

***

### `sign.verify`

[Back to Top](#table-of-standard-opcodes)

#### Description

Verifies the signature `first` against the address public key `second` and the message `third`, storing the outcome in `destination`.

#### Example Usage

```aleo
sign.verify r0 r1 r2 into r3;
```

#### Supported Types

| First | Second | Third | Destination |
|-------------|-----------|-----------|-------------|
| `Signature` | `Address` | `Message` | `Boolean` |

***

### `shl`

[Back to Top](#table-of-standard-opcodes)
Expand Down
28 changes: 28 additions & 0 deletions documentation/leo/03_language.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,34 @@ These semantics will be accompanied by a standard library in a future sprint.
let receiver: address = aleo1ezamst4pjgj9zfxqq0fwfj8a4cjuqndmasgata3hggzqygggnyfq6kmyd4;
```

### Signatures

Aleo uses a Schnorr signatures scheme to sign messages with an Aleo private key.
Signatures in Leo have their own type `signature` and can be declared as literals `sign069ju4e8s66unu25celqycvsv3k9chdyz4n4sy62tx6wxj0u25vqp58hgu9hwyqc63qzxvjwesf2wz0krcvvw9kd9x0rsk4lwqn2acqhp9v0pdkhx6gvkanuuwratqmxa3du7l43c05253hhed9eg6ppzzfnjt06fpzp6msekdjxd36smjltndmxjndvv9x2uecsgngcwsc2qkns4afd`.
Signatures can be verified in Leo using the [`signature::verify` or `s.verify`](./04_operators.md#signatureverify) operators.

```leo
program test.aleo {
struct foo {
a: u8,
b: scalar
}
transition verify_field(s: signature, a: address, v: field) {
let first: bool = signature::verify(s, a, v);
let second: bool = s.verify(a, v);
assert_eq(first, second);
}
transition verify_foo(s: signature, a: address, v: foo) {
let first: bool = signature::verify(s, a, v);
let second: bool = s.verify(a, v);
assert_eq(first, second);
}
}
```

## Layout of a Leo Program

A Leo program contains declarations of a [Program Scope](#program-scope), [Imports](#import)
Expand Down
24 changes: 24 additions & 0 deletions documentation/leo/04_operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The Leo operators compile down to [Aleo instructions opcodes](../aleo/04_opcodes
| [Poseidon2::hash_to_destination](#poseidon2hash_to_destination) | Poseidon hash with input rate 2 |
| [Poseidon4::hash_to_destination](#poseidon4hash_to_destination) | Poseidon hash with input rate 4 |
| [Poseidon8::hash_to_destination](#poseidon8hash_to_destination) | Poseidon hash with input rate 8 |
| [signature::verify](#signatureverify) | Verify a signature |

## Specification

Expand Down Expand Up @@ -994,6 +995,29 @@ Computes the truncated remainder of `first` divided by `second`, wrapping around
[Back to Top](#table-of-standard-operators)
***

### `signature::verify`

```leo
transition verify_field(s: signature, a: address, v: field) {
let first: bool = signature::verify(s, a, v);
let second: bool = s.verify(a, v);
assert_eq(first, second);
}
```

#### Description

Verifies that the signature `first` was signed by the address `second` with respect to the field `third`, storing the outcome in `destination`.

#### Supported Types

| First | Second | Third | Destination |
|-------------|-----------|-----------|-------------|
| `Signature` | `Address` | `Message` | `Boolean` |

[Back to Top](#table-of-standard-operators)
***

### `shl`

```leo
Expand Down

0 comments on commit ae54004

Please sign in to comment.