-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EIP-41 Stealth address standard #87
Open
ross-weir
wants to merge
5
commits into
ergoplatform:master
Choose a base branch
from
ross-weir:eip41/stealthaddresses
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# EIP-41 Stealth Address Standard | ||
|
||
* Author: ross-weir | ||
* Status: Proposed | ||
* Created: 16-Dec-2022 | ||
* Last edited: 17-Dec-2022 | ||
* License: CC0 | ||
* Forking: not needed | ||
|
||
## Motivation | ||
|
||
This specification defines a standardized way of implementing and interacting with stealth addresses on the Ergo blockchain. | ||
|
||
Stealth addresses enable recipients of a payment to remain anonymous when receiving funds thus providing financial privacy should an actor desire it. | ||
|
||
## Scenario | ||
|
||
An actor, `Receiver`, wishes to receive a stealth payment so they generate a public address and share it. | ||
|
||
An actor, `Sender`, wishes to make a stealth payment to `Receiver` so they create a box protected by a "one-time-secret" generated from the `Receiver`s public address. Due to the method of generation this box will be spendable by `Receiver` and cannot be linked to the `Receiver`s public address they shared. | ||
|
||
## Stealth address specification | ||
|
||
The implementation suggested in this EIP was posted by `scalahub` in a thread on `ergoforum.org` [[1]](#1) and is outlined below. | ||
|
||
**Script protecting stealth boxes:** | ||
|
||
```scala | ||
{ | ||
// ===== Contract Information ===== // | ||
// Name: EIP-0041 Stealth address contract | ||
// Version: 1.0.0 | ||
val gr = SELF.R4[GroupElement].get | ||
val gy = SELF.R5[GroupElement].get | ||
val ur = SELF.R6[GroupElement].get | ||
val uy = SELF.R7[GroupElement].get | ||
|
||
proveDHTuple(gr,gy,ur,uy) | ||
} | ||
``` | ||
|
||
**Script ErgoTree:** | ||
|
||
``` | ||
1000cee4c6a70407e4c6a70507e4c6a70607e4c6a70707 | ||
``` | ||
|
||
**Generation of stealth box registers [[5]](#5):** | ||
|
||
```typescript | ||
const g = new EC("secp256k1").g; // group element generator | ||
const u = receiverPublicKey; | ||
const r = BigInt(rand(32)); | ||
const y = BigInt(rand(32)); | ||
const gr = g.mul(r); // gr = g^r = R4 | ||
const gy = g.mul(y); // gy = g^y = R5 | ||
const ur = u.mul(r); // ur = u^r = R6 | ||
const uy = u.mul(y); // uy = u^y = R7 | ||
``` | ||
|
||
**Box register declarations:** | ||
|
||
- Register `R4` | ||
- Type: `SConstant[SGroupElement]` | ||
- Value: gr = g^r | ||
- Register `R5` | ||
- Type: `SConstant[SGroupElement]` | ||
- Value: gy = g^y | ||
- Register `R6` | ||
- Type: `SConstant[SGroupElement]` | ||
- Value: ur = u^r | ||
- Register `R7` | ||
- Type: `SConstant[SGroupElement]` | ||
- Value: uy = u^y | ||
|
||
> 📝 As discussed in the `ergoforum` discussion [[1]](#1) this register declaration is larger in size than that originally proposed by `kushti` but possesses the useful property that it could look like a legitimate use-case. | ||
|
||
## Public key generation | ||
|
||
Public keys used for `Receiver` stealth addresses should be generated following `EIP-3` [[6]](#6) so they are deterministic and payments made to `Receiver` can be retrieved after a fresh wallet restore. | ||
|
||
## Scanning for spendable stealth boxes | ||
|
||
All stealth boxes created following this standard will be located at the encoded address `2pxnLshTr2aL5t3QFd6ScSEHC5Jk6EpnMRzGb3`. In order to discover spendable stealth boxes a wallet would need to check the following for each box at this address: | ||
|
||
```ts | ||
const gr = stealthBox.R4; | ||
const gy = stealthBox.R5; | ||
const ur = stealthBox.R6; | ||
const uy = stealthBox.R7; | ||
const x = receiverSecretKey; // the secret key corresponding to the public key shared by `Receiver` | ||
const isSpendable = ur.eq(gr.mul(x)) && uy.eq(gy.mul(x)); | ||
``` | ||
|
||
> ⚠️ All stealth boxes being located at `2pxnLshTr2aL5t3QFd6ScSEHC5Jk6EpnMRzGb3` is a potential scalability issue related to this EIP. Wallets/indexing services will need to ensure stealth box scanning implementations are efficient. | ||
|
||
## Stealth address encoding | ||
|
||
To provide users of Ergo a seamless experience when interacting with stealth addresses there needs to be a way for wallets/applications to detect a `Receiver` is requesting a stealth payment. If a `Receiver` shares a standard `P2PK` address, for example, there is currently no way for a wallet to know that the user wants to receive a stealth payment. | ||
|
||
To address this issue we propose adding a new `AddressType`. | ||
|
||
Currently Ergo uses: | ||
|
||
```ts | ||
enum AddressType { | ||
P2PK = 1, | ||
P2SH = 2, | ||
P2S = 3 | ||
} | ||
``` | ||
|
||
We propose adding a new address type of `AddressType.P2SA`: | ||
|
||
```ts | ||
enum AddressType { | ||
P2PK = 1, | ||
P2SH = 2, | ||
P2S = 3, | ||
P2SA = 4 | ||
} | ||
``` | ||
|
||
This will allow `Sender`s wallet to detect that a `Receiver` is requesting a stealth payment like so: | ||
|
||
```ts | ||
const isStealthAddress = headByte & 0xf == AddressType.P2SA | ||
``` | ||
|
||
And the `Sender`s wallet can construct the stealth transaction accordingly. | ||
|
||
## References | ||
|
||
- <a id="1">[1]</a> [Stealth Address Contract (ergoforum)](https://www.ergoforum.org/t/stealth-address-contract/255) | ||
- <a id="2">[2]</a> [ErgoScript by example](https://github.com/ergoplatform/ergoscript-by-example/blob/main/stealthAddress.md) | ||
- <a id="3">[3]</a> [Stealth-doc (ERGOHACK III aragogi)](https://github.com/aragogi/Stealth-doc) | ||
- <a id="4">[4]</a> [Ethereum (EIP-5564)](https://eips.ethereum.org/EIPS/eip-5564#:~:text=A%20Stealth%20address%20is%20generated,compute%20the%20matching%20private%20key.) | ||
- <a id="5">[5]</a> [TypeScript stealth address example](https://github.com/ross-weir/ergo-stealth-address-example/blob/main/index.ts) | ||
- <a id="6">[6]</a> [Ergo (EIP-0003)](eip-0003.md) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to describe how to encode a P2SA and make clear that it's a special kind of address, as it's not ErgoTree-based like others.
You can take this comment as the basis for that: #87 (comment)