Skip to content

Commit

Permalink
some cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
pmerkleplant committed Dec 3, 2023
1 parent b6b842a commit fec2a9e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
2 changes: 2 additions & 0 deletions examples/stealth-addresses/StealthSecp256k1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ contract StealthSecp256k1Example is Script {
spendingPubKey: receiverSpendingPubKey,
viewingPubKey: receiverViewPubKey
});
console.log("Stealth Meta Address: ");
console.logBytes(receiverStealthMeta.toBytes("eth"));

// Sender creates stealth address from receiver's stealth meta address.
console.log(
Expand Down
5 changes: 2 additions & 3 deletions src/curves/Secp256k1Arithmetic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

// TODO: Represent point at infinity via zero point?
/**
* @notice Point is a secp256k1 point in Affine coordinates
*
Expand Down Expand Up @@ -168,7 +167,7 @@ library Secp256k1Arithmetic {
//----------------------------------
// Arithmetic

/// @dev Returns a new point being the sum of points `point` and `other`.
/// @dev Returns the sum of points `point` and `other` as new point.
///
/// @dev TODO Note about performance. intoPoint() conversion is expensive.
/// Also created new point struct in memory.
Expand Down Expand Up @@ -391,7 +390,7 @@ library Secp256k1Arithmetic {
// Private Functions

//----------------------------------
// Affine Point
// Jacobian Point
//
// Functionality stolen from Jordi Baylina's [ecsol](https://github.com/jbaylina/ecsol/blob/c2256afad126b7500e6f879a9369b100e47d435d/ec.sol).

Expand Down
2 changes: 0 additions & 2 deletions src/signatures/ECDSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ library ECDSA {
revert("PrivateKeyInvalid()");
}

// TODO: Should revert if digest is zero?

uint8 v;
bytes32 r;
bytes32 s;
Expand Down
18 changes: 9 additions & 9 deletions src/stealth-addresses/ERC5564Announcer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ pragma solidity ^0.8.16;
*
* Index | Description | Length in bytes
* -----------------------------------------------------------------------------
* [0x00] | View tag | 1
* [0x01:0x04] | `0xeeeeeeee` | 4
* [0x05:0x24] | `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE` | 20
* [0x18:0x38] | Amount in wei | 32
* [0x00] | View tag | 1
* [0x01:0x04] | `0xeeeeeeee` | 4
* [0x05:0x24] | `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE` | 20
* [0x18:0x38] | Amount in wei | 32
*
* - Tx involving a contract call with a single argument, eg ERC-20/ERC-721
* transfers:
*
* Index | Description | Length in bytes
* -----------------------------------------------------------------------------
* [0x00] | View tag | 1
* [0x01:0x04] | Solidity function selector | 4
* [0x05:0x24] | Contract address | 20
* [0x18:0x38] | One word argument, eg token amount | 32
* [0x00] | View tag | 1
* [0x01:0x04] | Solidity function selector | 4
* [0x05:0x24] | Contract address | 20
* [0x18:0x38] | One word argument, eg token amount | 32
*
* @custom:references
* - [EIP-5564]: https://eips.ethereum.org/EIPS/eip-5564
Expand All @@ -41,7 +41,7 @@ interface IERC5564Announcer {
///
/// @param schemeId Scheme id based on [EIP-5564 Scheme Registry] registry.
/// @param stealthAddress The stealth address.
/// @param caller The address who announced the tx.
/// @param caller The address announcing the tx.
/// @param ephemeralPubKey The ephemeral public key created during the
/// stealth address generation.
/// @param metadata Bytes blob providing the view tag and arbitrary
Expand Down
24 changes: 15 additions & 9 deletions src/stealth-addresses/StealthSecp256k1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,21 @@ library StealthSecp256k1 {
// Stealth Meta Addresses

// TODO: See https://eips.ethereum.org/EIPS/eip-5564#stealth-meta-address-format.
function toBytes(StealthAddress memory stealthMetaAddress)
internal
pure
returns (bytes memory)
{
return bytes("");
//
// st:eth:0x<spendingKey><viewingKey>
function toBytes(
StealthMetaAddress memory stealthMetaAddress,
string memory chainShortName
) internal pure returns (bytes memory) {
bytes memory prefix =
abi.encodePacked(bytes("st:"), bytes(chainShortName), bytes(":0x"));

bytes memory pubKeys = abi.encodePacked(
stealthMetaAddress.spendingPubKey.toBytes(),
stealthMetaAddress.viewingPubKey.toBytes()
);

return abi.encodePacked(prefix, pubKeys);
}

// Stealth Address
Expand All @@ -67,9 +76,6 @@ library StealthSecp256k1 {
internal
returns (StealthAddress memory)
{
// TODO: Functionality missing in Secp256k1(Arithmetic):
// - PublicKey + PublicKey

// Create ephemeral key pair.
PrivateKey ephemeralPrivKey = Secp256k1.newPrivateKey();
PublicKey memory ephemeralPubKey = ephemeralPrivKey.toPublicKey();
Expand Down

0 comments on commit fec2a9e

Please sign in to comment.