Skip to content
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

Support Poseidon2 #40

Open
1 of 4 tasks
redshiftzero opened this issue Apr 12, 2023 · 3 comments
Open
1 of 4 tasks

Support Poseidon2 #40

redshiftzero opened this issue Apr 12, 2023 · 3 comments
Assignees

Comments

@redshiftzero
Copy link
Member

redshiftzero commented Apr 12, 2023

There's another version of Poseidon, called Poseidon2:
https://eprint.iacr.org/2023/323

Most relevant for us is section 7.3 which discusses mitigating the attacks found here where the researchers are able to skip 2 rounds of Poseidon 1. Note that the current additional security margin in Poseidon 1 (added in case new attacks are found) is 2 full rounds and 7.5% additional partial rounds.

This ticket is to evaluate whether we should migrate to Poseidon2 prior to mainnet launch, given that we do not want to change hash functions after launch.

Sub tasks:

@plaidfinch
Copy link

If we change poseidon implementations in the SCT post-mainnet, then we'll have to maintain two separate shielded pools forever, which makes me think this is not actually a place where things are particularly agile. Compared to in the key hierarchy, though, I suppose it is.

@hdevalence
Copy link
Member

I'm not sure that's true — in a hypothetical V2 where we changed the hash function, we could recreate a new SCT with the same leaves but the new hash function, and use that instead. Clients would have to upgrade and re-sync, and the leaf commitment hashes would still be poseidon 1, but that's the less important part of the inclusion proofs.

@redshiftzero
Copy link
Member Author

Here are the places we currently use Poseidon1 in the protocol categorized by how easy it is to change the hash function:

Least agility: Impacts all published addresses

We use rate-2 Poseidon1 to hash the spend authorization key $ak$ and the nullifier deriving key $nk$. The hash output in turn is used to compute the IVK, which is used to derive the transmission key $pk_d$. Since the transmission key is part of the address, changing the derivation of the IVK changes the address, which is the most disruptive change since it impacts all published addresses. It also is a circuit-breaking change since we derive the IVK in-circuit.

Low-medium agility: Circuit-breaking changes

The next category of places we use Poseidon1 are:

  • Deriving nullifiers based on position, state commitment, and nullifier deriving key (rate 3 Poseidon1)
  • Deriving swap and note commitments (rate 6 Poseidon1)
  • Deriving asset-specific value generators (rate 1 Poseidon1)
  • Hashing state commitments into the state commitment tree (SCT) - (rate 1 and 4 Poseidon1)

For the SCT, while we can transparently change the hash function used in the tree, since Merkle path verification in the circuits would also need to use the new hash, unless I'm missing something I think this is still a circuit-breaking change, as are the other uses of Poseidon1 in this category.

High agility: No major implications

The final place we're currently using Poseidon1 which we can easily change is:

  • Deriving two Rseeds for the outputs of a swap (rate 1 Poseidon1)

We derive two Rseed values in SwapPlaintext::output_rseeds() which are then used to derive blinding factors for the swap output notes. While this is currently done inside the verification method of the current transparent swap claim, we can derive the blinding factors out of circuit based on each Rseed, and witness the resulting blinding factors in the circuit, which is what we do for the other circuits involving note commitments. This is the approach taken for the ZK swap claim in penumbra-zone/penumbra#2151. It's also reasonable to in a future change just use Blake2 in SwapPlaintext::output_rseeds() instead of Poseidon1.

@redshiftzero redshiftzero self-assigned this Apr 24, 2023
@redshiftzero redshiftzero moved this from Next to Testnet 52: Amalthe in Testnets Apr 24, 2023
redshiftzero added a commit that referenced this issue Apr 25, 2023
This is the `r1cs` branch from our git fork of `ark-sponge`:

https://github.com/penumbra-zone/sponge

It is unmodified in this commit, changes will be made in the
subsequent commits for clarity of the git history.

The upstream `ark-sponge` repository is archived because they moved
the poseidon implementation to a different repository. In addition,
we need to make a lot of changes to get on the upstream impl. This
was attempted back in November and at that time we decided to continue
using our fork only for the R1CS feature.

However, in light of the upcoming migration to Poseidon2, any work
resolving the divergence between our fork and the upstream repo would
be wasted, as we'll be soon removing Poseidon 1 from `poseidon377`.

As such, for stability, we are vendoring our fork of `ark-sponge`
on a temporary basis such that we can release `poseidon377` unchanged
to crates, then pin all penumbra repositories to that release.

Afterwards, we will proceed with migrating to Arkworks 0.4.x release
series [0] and migrating to Poseidon2 [1].

[0] penumbra-zone/penumbra#2004
[1] #40
@redshiftzero redshiftzero changed the title Evaluate Poseidon2 Support Poseidon2 Apr 26, 2023
redshiftzero added a commit that referenced this issue Apr 26, 2023
This is the `r1cs` branch from our git fork of `ark-sponge`:

https://github.com/penumbra-zone/sponge

It is unmodified in this commit, changes will be made in the
subsequent commits for clarity of the git history.

The upstream `ark-sponge` repository is archived because they moved
the poseidon implementation to a different repository. In addition,
we need to make a lot of changes to get on the upstream impl. This
was attempted back in November and at that time we decided to continue
using our fork only for the R1CS feature.

However, in light of the upcoming migration to Poseidon2, any work
resolving the divergence between our fork and the upstream repo would
be wasted, as we'll be soon removing Poseidon 1 from `poseidon377`.

As such, for stability, we are vendoring our fork of `ark-sponge`
on a temporary basis such that we can release `poseidon377` unchanged
to crates, then pin all penumbra repositories to that release.

Afterwards, we will proceed with migrating to Arkworks 0.4.x release
series [0] and migrating to Poseidon2 [1].

[0] penumbra-zone/penumbra#2004
[1] #40
@redshiftzero redshiftzero moved this from Testnet 52: Amalthe to In Progress in Testnets Apr 27, 2023
@redshiftzero redshiftzero moved this from In Progress to Next in Testnets May 4, 2023
@redshiftzero redshiftzero moved this from Next to Future in Testnets May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Future
Development

No branches or pull requests

3 participants