Skip to content

Commit

Permalink
Add eth_sign documentation (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed Jan 23, 2020
1 parent 1afb333 commit d1441b6
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions source/contracts/signatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ All the signatures are sorted by the signer address and concatenated.

---
### ECDSA Signature
`signature type > 26`
`31 > signature type > 26`

To be able to have the ECDSA signature without the need of additional data we use the signature type byte to encode `v`.

Expand All @@ -20,18 +20,33 @@ To be able to have the ECDSA signature without the need of additional data we us

`r`, `s` and `v` are the required parts of the ECDSA signature to recover the signer.

---------
### `eth_sign` signature
`signature type > 30`

To be able to use `eth_sign` we need to take the parameters `r`, `s` and `v` from calling `eth_sign` and set `v = v + 4`

#### Constant part:
`{32-bytes r}{32-bytes s}{1-byte v}`

`r`, `s` and `v` are the required parts of the ECDSA signature to recover the signer.
`v` will be substracted by `4` to calculate the signature.

---
### Contract Signature (EIP-1271)
`signature type == 0`

#### Constant part:
`{32-bytes signature verifier}{32-bytes data position}`
`{32-bytes signature verifier}{32-bytes data position}{1-byte signature type}`

**Signature verifier** - Padded address of the contract that implements the EIP 1271 interface to verify the signature

**Data position** - Position of the start of the signature data (offset relative to the beginning of the signature data)

#### Dynamic part:
`{bytes signature data}`
**Signature type** - 0

#### Dynamic part (solidity `bytes`):
`{32-bytes signature length}{bytes signature data}`

**Signature data** - Signature bytes that are verified by the signature verifier

Expand All @@ -42,10 +57,11 @@ The method `signMessage` can be used to mark a message as signed on-chain.
`signature type == 1`

#### Constant Part:
`{32-bytes hash validator}`
`{32-bytes hash validator}{32-bytes ignored}{1-byte signature type}`

**Hash validator** - Padded address of the account that pre-validated the hash that should be validated. The Safe keeps track of all hashes that have been pre validated. This is done with a **mapping address to mapping of bytes32 to boolean** where it is possible to set a hash as validated by a certain address (hash validator). To add an entry to this mapping use `approveHash`. Also if the validator is the sender of transaction that executed the Safe transaction it is **not** required to use `approveHash` to add an entry to the mapping. (This can be seen in the [Team Edition tests](https://github.com/gnosis/safe-contracts/blob/v1.0.0/test/gnosisSafeTeamEdition.js))

**Signature type** - 1


## Examples
Expand All @@ -68,3 +84,4 @@ The signatures bytes used for `execTransaction` would therefore be the following
"bde0b9f486b1960454e326375d0b1680243e031fd4fb3f070d9a3ef9871ccfd57d1a653cffb6321f889169f08e548684e005f2b0c3a6c06fba4c4a68f5e006241c" + // encoded ECDSA signature
"000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000deadbeef" // length of bytes + data of bytes
```

0 comments on commit d1441b6

Please sign in to comment.