Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Implement support for cryptographic primitives in the smart contract execution engine #52

Closed
1 task done
abizjak opened this issue May 4, 2022 · 0 comments · Fixed by #51
Closed
1 task done
Assignees
Labels
[Prio] High An urgent problem that blocks the system use until the issue is resolved. [Size] Medium

Comments

@abizjak
Copy link
Contributor

abizjak commented May 4, 2022

These primitives are

  • ed25519 signature checking
  • ecdsa over secp256k1 signature checking (bitcoin/ethereum scheme)
  • sha2-256 hashing
  • sha3-256 hashing
  • keccak-256 hashing (this is almost sha3, but with a padding difference, it is what Ethereum uses in their smart contracts, hence the motivation).

We have decided on the following API

    /// Verify an ed25519 signature. The public key is expected to be 32 bytes,
    /// the signature is expected to be 64 bytes, and the message may be
    /// variable length.
    ///
    /// The return value is 0 if verification fails, and 1 if it succeeds. No
    /// other return values are possible.
    pub fn verify_ed25519_signature(
        public_key: *const u8,
        signature: *const u8,
        message: *const u8,
        message_len: u32,
    ) -> i32;

    /// Verify an ed25519 signature. The public key is expected to be 33 bytes,
    /// the signature is expected to be 64 bytes (serialized in compressed
    /// format), and the message must be 32 bytes. 
    ///
    /// The return value is 0 if verification fails, and 1 if it succeeds. No
    /// other return values are possible.
    pub fn verify_ecdsa_secp256k1_signature(
        public_key: *const u8,
        signature: *const u8,
        message: *const u8,
    ) -> i32;

    /// Hash the data using the SHA2-256 algorithm. The resulting hash (32
    /// bytes) is written starting at the `output` pointer. The output
    /// segment *may* overlap with the data segment.
    pub fn hash_sha2_256(data: *const u8, data_len: u32, output: *mut u8);

    /// Hash the data using the SHA3-256 algorithm. The resulting hash (32
    /// bytes) is written starting at the `output` pointer. The output
    /// segment *may* overlap with the data segment.
    pub fn hash_sha3_256(data: *const u8, data_len: u32, output: *mut u8);

    /// Hash the data using Keccak-256 algorithm. The resulting hash (32 bytes)
    /// is written starting at the `output` pointer. The output segment
    /// *may* overlap with the data segment.
    pub fn hash_keccak_256(data: *const u8, data_len: u32, output: *mut u8);

We are to use the ZIP-215 specification of ed25519 signature schecking and the bitcoin-core implementation of ecdsa.

  • This also includes an update cargo-concordium.
@abizjak abizjak added [Prio] High An urgent problem that blocks the system use until the issue is resolved. [Size] Medium labels May 4, 2022
@abizjak abizjak self-assigned this May 4, 2022
@abizjak abizjak linked a pull request May 4, 2022 that will close this issue
5 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
[Prio] High An urgent problem that blocks the system use until the issue is resolved. [Size] Medium
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant