Skip to content

feat: implement encryption to an address point and decryption from an address secret#9272

Merged
sklppy88 merged 5 commits intomasterfrom
ek/feat/new-address-implementation/encrypt-and-decrypt-with-new-scheme
Oct 25, 2024
Merged

feat: implement encryption to an address point and decryption from an address secret#9272
sklppy88 merged 5 commits intomasterfrom
ek/feat/new-address-implementation/encrypt-and-decrypt-with-new-scheme

Conversation

@sklppy88
Copy link
Contributor

@sklppy88 sklppy88 commented Oct 17, 2024

Resolves #9326, #8966, #8969

This PR finally implements the new address scheme in encryption and decryption. We encrypt with the address's point, and decrypt with preaddress + ivsk (addressSecret).

Some nomenclature before we start:
The old address (h in Mike's presentation; hash(partialAddress, publicKeysHash)) -> preAddress
The secret corresponding to the address point -> addressSecret

The flow generally works by taking a secret, and deriving a valid point from it.

We then store the x-coordinate of this point as the address. We do this even though we know that this x-coordinate has two valid y-coordinates (a positive and negative one), but we do not store any information about the sign in the address.

Even still, we can support secrets that get computed into a positive and a negative y coordinate.

To do this, whenever we recompute the y-coordinate to recover the point from the x-coordinate, we make sure to encrypt to the positive point only. i.e. if we solve for y with x, and we get a negative coordinate, we subtract it from the Field modulus to get a positive one.

But if you think "hey, we can't do that, our secret corresponds to a negative y-coordinate", you would be right. In order to address this, we as the owner of the secret, can recompute our full point as we know all of the information that can derive this point. Thus we know what sign our "true" y-coordinate is. In this case, if our y-coordinate is negative, all we need to do is negate our secret (Field modulus minus secret) to derive the secret for point containing the negated negative (and now positive) y-coordinate.

You can see that this above process is being done, with the the encryption taking place in payload.nr, and that the decryption taking place in note_processor.ts.

Outstanding work:
The interface of getEvents in pxe_service should be investigated. With these changes it works... but it's unnecessarily disgusting I think.

The interface of the encryption api in payload.nr is extremely jank, but this pr is getting pretty big, so it will be handled imminently in #9390.

Look through the rest of the tests, think about replacing arbitrary addresses with "valid" ones.

Remove any excess code relating to needing the ivpk in both ts and nr

Docs and migration notes. As this change is pretty big I think it would be good to go through this also later / with someone on the devrel team to make sure the docs are comprehensively updated.

More of this stack doesn't show up on the graphite comment here:
image

@sklppy88 sklppy88 changed the title init feat: implement correct encryption and decryption Oct 17, 2024
@sklppy88 sklppy88 force-pushed the ek/feat/new-address-implementation/modify-contract-instance-to-include-public-keys branch from da9a81f to 2d638df Compare October 17, 2024 19:40
@sklppy88 sklppy88 force-pushed the ek/feat/new-address-implementation/encrypt-and-decrypt-with-new-scheme branch from 5404e50 to 6388e81 Compare October 17, 2024 19:40
Base automatically changed from ek/feat/new-address-implementation/modify-contract-instance-to-include-public-keys to master October 17, 2024 21:45
@sklppy88 sklppy88 force-pushed the ek/feat/new-address-implementation/encrypt-and-decrypt-with-new-scheme branch from 6388e81 to 9424c07 Compare October 18, 2024 10:19
@sklppy88 sklppy88 changed the base branch from master to ek/feat/new-address-implementation/modify-private-calldata-to-use-public-keys-instead-of-public-keys-hash October 18, 2024 10:19
@sklppy88 sklppy88 force-pushed the ek/feat/new-address-implementation/modify-private-calldata-to-use-public-keys-instead-of-public-keys-hash branch from 5b8d888 to dea191e Compare October 18, 2024 10:48
@sklppy88 sklppy88 force-pushed the ek/feat/new-address-implementation/encrypt-and-decrypt-with-new-scheme branch 2 times, most recently from 5721621 to 58d05a3 Compare October 18, 2024 12:05
@sklppy88 sklppy88 changed the base branch from ek/feat/new-address-implementation/modify-private-calldata-to-use-public-keys-instead-of-public-keys-hash to ek/feat/new-address-scheme-implementation/introduce-public-keys-default October 18, 2024 12:05
@sklppy88 sklppy88 marked this pull request as ready for review October 18, 2024 12:06
@sklppy88 sklppy88 force-pushed the ek/feat/new-address-implementation/encrypt-and-decrypt-with-new-scheme branch 3 times, most recently from db4767f to f3fd5d4 Compare October 19, 2024 11:01
@sklppy88 sklppy88 force-pushed the ek/feat/new-address-scheme-implementation/introduce-public-keys-default branch from bc6018f to 62b4c08 Compare October 19, 2024 12:33
@sklppy88 sklppy88 force-pushed the ek/feat/new-address-implementation/encrypt-and-decrypt-with-new-scheme branch 5 times, most recently from e1846a5 to 20c067b Compare October 21, 2024 05:33
@sklppy88 sklppy88 force-pushed the ek/feat/new-address-scheme-implementation/introduce-public-keys-default branch from 62b4c08 to be7b51a Compare October 22, 2024 05:49
@sklppy88 sklppy88 force-pushed the ek/feat/new-address-implementation/encrypt-and-decrypt-with-new-scheme branch from 20c067b to b561c82 Compare October 22, 2024 05:49
Base automatically changed from ek/feat/new-address-scheme-implementation/quick-account-manager-refactor to master October 24, 2024 13:22
@sklppy88 sklppy88 force-pushed the ek/feat/new-address-implementation/encrypt-and-decrypt-with-new-scheme branch from 9585935 to 9de53fd Compare October 24, 2024 13:29
const encryptedLogs = encryptedTxLogs.flatMap(encryptedTxLog => encryptedTxLog.unrollLogs());

const vsks = await Promise.all(vpks.map(vpk => this.keyStore.getMasterSecretKey(vpk)));
const vsks = await Promise.all(
Copy link
Contributor Author

@sklppy88 sklppy88 Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this file are a bit janky and should be fixed in a follow up PR, have noted it in the description.

@@ -75,7 +75,8 @@ mod test {
#[test]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file's changes was just due to the formatter not being run on master

Thunkar
Thunkar previously approved these changes Oct 24, 2024
Copy link
Contributor

@Thunkar Thunkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, awesome job!

Copy link
Contributor

@nventuro nventuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely to see this finally be implemented! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement the new address scheme across the stack Send notes using Addresses instead of keys Change the aztec-nr Address derivation

4 participants