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

CIP-0101 | Integration of keccak256 into Plutus #524

Merged
merged 21 commits into from
Sep 7, 2023
Merged
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions CIP-????/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
CIP: ?
Title: Integration of `keccak256` into Plutus
Status: Proposed
Category: Plutus
Authors:
- Sergei Patrikeev <[email protected]>
- Iñigo Querejeta-Azurmendi <[email protected]>
Implementors: []
serejke marked this conversation as resolved.
Show resolved Hide resolved
Discussions:
- https://github.com/cardano-foundation/CIPs/pull/524
Created: 2023-06-13
License: Apache-2.0
---

## Abstract
This CIP proposes an extension of the current Plutus functions to provide support for the [`keccak256`](https://keccak.team/files/Keccak-submission-3.pdf) hashing algorithm,
primarily to ensure compatibility with Ethereum's cryptographic infrastructure.

## Motivation: why is this CIP necessary?
rphair marked this conversation as resolved.
Show resolved Hide resolved

The [integration](https://github.com/cardano-foundation/CIPs/blob/master/CIP-0049/README.md) of the ECDSA and Schnorr signatures over the secp256k1 curve into Plutus was a significant
step towards interoperability with Ethereum and Bitcoin ecosystems. However, full compatibility is still impossible
due to the absence of the `keccak256` hashing algorithm in Plutus interpreter,
which is a fundamental component of Ethereum's cryptographic framework:
- data signing standard [EIP-712](https://eips.ethereum.org/EIPS/eip-712),
- `keccak256` is the hashing algorithm underlying Ethereum's ECDSA signatures.
- EVM heavily [depends](https://ethereum.github.io/yellowpaper/paper.pdf) on `keccak256` for internal state management

Adding `keccak256` to Plutus would enhance the potential for cross-chain solutions between Cardano and EVM-based blockchains.

## Specification
This proposal aims to introduce a new built-in hash function `keccak_256`.

This function will be developed following the [`keccak256`](https://keccak.team/files/Keccak-submission-3.pdf) specification
and will utilize the [cryptonite](https://github.com/haskell-crypto/cryptonite/blob/master/Crypto/Hash/Keccak.hs) implementation.
rphair marked this conversation as resolved.
Show resolved Hide resolved
Since `cryptonite` is already a part of the [`cardano-base`](https://github.com/input-output-hk/cardano-base/blob/master/cardano-crypto-class/src/Cardano/Crypto/Hash/Keccak256.hs),
rphair marked this conversation as resolved.
Show resolved Hide resolved
this simplifies its integration into Plutus. The cost of the `keccak_256` operation will scale linearly with the length of the message.

More specifically, Plutus will gain the following primitive operation:

* `keccak_256` :: ByteString -> ByteString

The input to this function can be a `ByteString` of arbitrary size, and the output will be a `ByteString` of 32 bytes.
Note that this function aligns with the format of existing hash functions in Plutus, such as [blake2b_256](https://github.com/input-output-hk/plutus/blob/75267027f157f1312964e7126280920d1245c52d/plutus-core/plutus-core/src/Data/ByteString/Hash.hs#L25)

## Rationale: how does this CIP achieve its goals?
While the `keccak256` function might be implemented in on-chain scripts, doing so would be computationally unfeasible.

rphair marked this conversation as resolved.
Show resolved Hide resolved
## Path to Active
This CIP may transition to active status once the Plutus version containing the `keccak_256` function is introduced
in a node release and becomes available on Mainnet.

### Acceptance Criteria
* A Plutus binding is created for the `keccak256` function and included in a new version of Plutus.
* Integration tests, similar to those of the existing Plutus hash functions, are added to the testing infrastructure.
* The function is benchmarked to assess its cost.
rphair marked this conversation as resolved.
Show resolved Hide resolved
* E2E tests with real use cases are incorporated into the testing infrastructure.
rphair marked this conversation as resolved.
Show resolved Hide resolved

### Implementation Plan
The Plutus team will develop the binding, integration tests, and benchmarks. The E2E tests will be designed and implemented
collaboratively by the testing team, the Plutus team, and community members planning to use this primitive.

## Copyright
This CIP is licensed under [Apache-2.0][https://www.apache.org/licenses/LICENSE-2.0].