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: Integration of keccak256 into Plutus. #1

Closed
wants to merge 3 commits into from
Closed
Changes from 2 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
72 changes: 72 additions & 0 deletions CIP-0382/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
CIP: 382
Title: Integration of `keccak256` into Plutus
Authors: Sergei Patrikeev <[email protected]>
Discussions-To: https://github.com/cardano-foundation/CIPs/pull/524
Comments-URI: https://github.com/cardano-foundation/CIPs/pull/524
Status: Draft
Category: Plutus
Type: Standards Track
Created: 2023-06-13
Post-History: None
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

The [integration](https://github.com/input-output-hk/cardano-base/pull/252) 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
`keccak256` function is already available in [cardano-base](https://github.com/input-output-hk/cardano-base/blob/master/cardano-crypto-class/src/Cardano/Crypto/Hash/Keccak256.hs).
The changes would require a single function to be added to Plutus.

## Rationale
While the `keccak256` function might be implemented in on-chain scripts, doing so would be computationally unfeasible.

## Path to Proposed
To move this Draft to Proposed, we need to cost the `keccak256` function.

### Trustworthiness of Implementations
The implementation of `keccak256` is based on the version found in the [cardano-base](https://github.com/input-output-hk/cardano-base/blob/master/cardano-crypto-class/src/Cardano/Crypto/Hash/Keccak256.hs) library.

### Costing of function
We performed some benchmarks (2,7 GHz Quad-Core Intel Core i7) on the `keccak256` that can be used to finalize the costing:
* Empty Input:
* `keccak256("")` -> N ms
* Short Fixed-Length Inputs (1, 2, 4, 8, 16, 32)
* `keccak256("a" ^ 1)` -> N ms
* `keccak256("a" ^ 2)` -> N ms
* `keccak256("a" ^ 4)` -> N ms
* `keccak256("a" ^ 8)` -> N ms
* `keccak256("a" ^ 16)` -> N ms
* `keccak256("a" ^ 32)` -> N ms
* Long Fixed-Length Inputs (256, 512, 1024)
* `keccak256("a" ^ 256)` -> N ms
* `keccak256("a" ^ 512)` -> N ms
* `keccak256("a" ^ 1024)` -> N ms
* Recursive hashing
* `keccak256(keccak256("a"))` -> N ms
* `keccak256(keccak256(keccak256("a")))` -> N ms

Choose a reason for hiding this comment

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

This can be removed. The costing will be handled in the future.


## Backward Compatibility
The addition of `keccak256` is backward compatible and will not interfere with existing functions within Plutus.

## Path to Active
Upon successful review and evaluation, the `keccak256` function is planned for release in an upcoming update.

## References
- keccak256: https://keccak.team/files/Keccak-submission-3.pdf
- Ethereum Yellow Paper: https://ethereum.github.io/yellowpaper/paper.pdf
- Ethereum standard on signing data: https://eips.ethereum.org/EIPS/eip-712