Skip to content

Commit

Permalink
draft kzg_to_versioned_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
anvacaru committed Nov 13, 2024
1 parent d22a3f2 commit 9d9a443
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Building
These instructions are for Ubuntu, assuming that Clang12 is installed.

- Update submodules: `git submodule update --init --recursive`
- Build dependencies: `make CXX=clang++-12 -j3 libff libcryptopp libsecp256k1`
- Build: `make CXX=clang++-12 build -j3`
- Build dependencies: `make CC=clang-14 CXX=clang++-14 -j4 libff libcryptopp libsecp256k1 c-kzg-eip4844`
- Build: `make CC=clang-14 CXX=clang++-14 build -j4`

Testing
-------
Expand Down
14 changes: 14 additions & 0 deletions plugin-c/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,18 @@ bool hook_KRYPTO_bn128ate(list *g1, list *g2) {
}
return alt_bn128_final_exponentiation(accum) == alt_bn128_GT::one();
}

uint8_t const VERSIONED_HASH_VERSION_KZG = 0x01;

struct string *kzg_to_versioned_hash(struct string *commitment) {
if(len(commitment) != 48) {
throw std::runtime_error("kzg commitment: invalid length");
}
struct string* commitment_sha256 = hook_KRYPTO_sha256raw(struct string *str);
struct string *result = allocString(64);
memcpy(result->data, VERSIONED_HASH_VERSION_KZG,1);
memcpy(result->data + 2, commitment_sha256 -> data + 2, 31);
return result;
}

}
7 changes: 7 additions & 0 deletions plugin/krypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,12 @@ The BN128 elliptic curve is defined over 2-dimensional points over the fields of
syntax Bool ::= isValidPoint(G1Point) [function, hook(KRYPTO.bn128valid)]
| isValidPoint(G2Point) [function, symbol(isValidG2Point), hook(KRYPTO.bn128g2valid)]
// ---------------------------------------------------------------------------------------------------
```

Point Evaluation Precompile
---------------------------
```k
syntax Bytes ::= pointEvaluation ( Bytes ) [function, hook(KRYPTO.pointEvaluation)]
// -----------------------------------------------------------------------------------
endmodule
```

0 comments on commit 9d9a443

Please sign in to comment.