Skip to content

Commit

Permalink
adds fixture and test inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
yash25198 committed Dec 7, 2024
1 parent bcfa957 commit e2dbdaf
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 44 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 20 additions & 11 deletions contracts/src/Fibonacci.sol → contracts/src/BitMix.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ pragma solidity ^0.8.20;
import {ISP1Verifier} from "@sp1-contracts/ISP1Verifier.sol";

struct PublicValuesStruct {
uint32 n;
uint32 a;
uint32 b;
bytes32[1] block_hashes;
bytes32 pub_a_x;
bytes32 pub_a_y;
bytes32 pub_c_x;
bytes32 pub_c_y;
bytes cipher;
}

/// @title Fibonacci.
/// @author Succinct Labs
/// @notice This contract implements a simple example of verifying the proof of a computing a
/// fibonacci number.
contract Fibonacci {
contract BitMix {
/// @notice The address of the SP1 verifier contract.
/// @dev This can either be a specific SP1Verifier for a specific version, or the
/// SP1VerifierGateway which can be used to verify proofs for any version of SP1.
Expand All @@ -32,13 +35,19 @@ contract Fibonacci {
/// @notice The entrypoint for verifying the proof of a fibonacci number.
/// @param _proofBytes The encoded proof.
/// @param _publicValues The encoded public values.
function verifyFibonacciProof(bytes calldata _publicValues, bytes calldata _proofBytes)
public
view
returns (uint32, uint32, uint32)
{
ISP1Verifier(verifier).verifyProof(fibonacciProgramVKey, _publicValues, _proofBytes);
PublicValuesStruct memory publicValues = abi.decode(_publicValues, (PublicValuesStruct));
function verifyBitMixProof(
bytes calldata _publicValues,
bytes calldata _proofBytes
) public view returns (uint32, uint32, uint32) {
ISP1Verifier(verifier).verifyProof(
fibonacciProgramVKey,
_publicValues,
_proofBytes
);
PublicValuesStruct memory publicValues = abi.decode(
_publicValues,
(PublicValuesStruct)
);
return (publicValues.n, publicValues.a, publicValues.b);
}
}
10 changes: 4 additions & 6 deletions contracts/src/fixtures/groth16-fixture.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"a": 6765,
"b": 10946,
"n": 20,
"vkey": "0x00467584e2e560847e9e96b5102c082f5e07155429c6622988799df9d95dbb47",
"publicValues": "0x00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000001a6d0000000000000000000000000000000000000000000000000000000000002ac2",
"proof": "0x090690900091bc3f08015e1ed96bee4e8c7a3ab074bfaa54129b1c63a9c6e478ec63255d3028cceaeed53e04bf0ee42f58ff0980ff00212e52a2a1d85b69b1268f5030820bc4589b0566e8a3f0738fa64405c10ee7347e58afbf4f1f431b327e5ba522c32f83c0c6e9e5bc37dfe2b31ae2bead89e0c7d8a0df1226b005d75f2e252b104a030d532c73f896df2328ce3322c055bda3b979dda22568ef85761b1d82bdcbec230f2838693d3663a0bd00006fa0f0dd4ea0e14b8b44273b0e8575e5478fa8d92a910cc26e0cdff4869f3fac686f91d245839368dbeadc9daaa4062ad1b3772523b284a3c41d60328f30461e03a465f4d6ec8d0fdfeeba176b8d0c7c82167c18"
"cipherText": "0x04ab56bc879ce0f13b8a33b5046e8d99c4e0e2347af8f94064e75247e837c10c25b2980660f82cee60f4059890a366df5d8dff39ef40500be899ca3e969631efe0b615a2a4a32a15b2a3409ecc60d0216b4b3d37ef55a8638c9bea73f47a93d077c262fc21761dc5af278957c59e69ff5aa7794dba44ede16607e9c3b57d57462d",
"vkey": "0x00e35dd2e44ea70566507a46e650fda297f45149524b5eac6c2665ee0690face",
"publicValues": "0x0000000000000000000000000000000000000000000000000000000000000020ccbbcf2c854ac69d4d337a862cdf921daabe8896d3c990d02f21a3c900000000dbff552efd5921eb3cb0c9e8ef7297b6e186fc8ecfee7c4bf67a405a3fadca8cd90c2ed0346e85e3fc03a88ed8f205ed6d8ffdad65da84191b6b5936e1869762218da385c94e85331a105861767f3cbc05485e9bec742720c309123bbb45ac0225f128ada179ff10d05da8192f0faa2f0654e9748c94629194b30558fd5d2a6000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000008104ab56bc879ce0f13b8a33b5046e8d99c4e0e2347af8f94064e75247e837c10c25b2980660f82cee60f4059890a366df5d8dff39ef40500be899ca3e969631efe0b615a2a4a32a15b2a3409ecc60d0216b4b3d37ef55a8638c9bea73f47a93d077c262fc21761dc5af278957c59e69ff5aa7794dba44ede16607e9c3b57d57462d00000000000000000000000000000000000000000000000000000000000000",
"proof": "0x090690902aadad2e32e868aea2085b49cf4ea41fa5c251f597cea09cbf69fa610f2821b51c3df4b1cfbad15f5c8454e52feda0189cec79973c396eebf982b8a7f11648661a889792fc606709599ca2b7fdd1c175bdfeca02d7bfbb05e5812903591cf82c1113fffb3de041b8602d96a620680149ea5377da94d6e413aff81e16588a1fb11c92dcc60c55234c6b7633a152a5ab7b3da00a973c0024d8cc07fa2d366747ce0652d2b454505c17506d375c2150815a7d4dd1282fa0b289ad66b970af43e2be1a6cee6ebcec77a0eabdf081defd66afee3f1803afd8397d0f874d2f52fd525d28dbea71f52ed5b1307971eef4e83bc7c6737ec5846bce3eac05ac9f7dd4d76a"
}
10 changes: 4 additions & 6 deletions contracts/src/fixtures/plonk-fixture.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"a": 6765,
"b": 10946,
"n": 20,
"vkey": "0x00467584e2e560847e9e96b5102c082f5e07155429c6622988799df9d95dbb47",
"publicValues": "0x00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000001a6d0000000000000000000000000000000000000000000000000000000000002ac2",
"proof": "0x54bdcae32122ba5d63ecb7d08cf7e217531928202417f27aa006e67ab53721eb386323bd1548e7a98de06f907d6067c9069866a6e8ca4a81a8553566abee9c2903efec8d0d3a52e9e717313d6fb5076bf3865cd8705a40b2613563b1d10f13adbeced54b179c997b00339169940341b4bb6ea21cd43992779b03e9a17fe6925f6273774e1b37fe45304344f3c66efee0b283cc6f8bb5d50e1f711d869080191284b5b93d10eafd8c57fab7d77ff15918e5e7fd93ed7ae6edc8629464aee148934e719c761e932ac3e956d05c70f9f2d2145c0b72f5e96127311b0b5ff805683091ec1f391beaffe65cf81e0613902331c700fcb0659c0c57e2f5d48d7e4eec04309060221f29322fc530473f367d34f38b47747afd4397acf8f75219ed6d393a468822b5152de3687df40b6ffebe49fbf0ceda8b54042283e454586875bb602b26a1175e165bdd7b6f29206896396e864904bb3cf5d375c84f311e5c557918dedccf27c30f43b11922ac6c9c0901634269de7d8ec9543ff834167149db30cd87b5c00c8d28cabf65079b6be84e5d013f514775e16d078215751f30547561ded0d2af784c0cbefb1fbd6149c09ed6eb0844265b1b0d038acd6b389cba9b3d6335e31567c706acf8cb896be0b70ce13eeb65990e69e29a48b85de56e2cda40d154034633f321f266a6af27e1adebe64e89a451bbeabb5fc0d9cf22c66c76710f599f39434b12f8ce865dda948710bed1755df69588eb5b0c21fb0f929b1bff7b7358c4cb1c271a65be960be28f2af49f3be51ddd6a4e552a3c1bb57204cd020d1057ae15602a43eb67628c5697ef5b181ded7e76a1f26997bca92ba31ef7337b63326a31cb1a13ec5b1d81605d83dbbf17f9699ebe3f2a2afa211dd09cf5de084d29ab28c212d9017f24ce6697e36d8c84b82970e1dedf5c74a821b73fce661c2a0bf1408f2c557c0e8962ad59cca1931cb276d3566e6f4a9411102cbf486c83aced09563d22a891e9abd3b6cee11963269c1f32f6131e97852584736ca8dbf7c6f9e34f660f79c2b9cd21515608ccc90af5e5689df83f623c08bc49284d93d4cfbf4ca60c2e2d8c1cb71195ac41b0788267d5af7092b421963519a1bb2e23774e7648344b19334175fa8031c8562bfb5209242b0a35282cbc7d05f96f4bf24318b6c37f0727f359fd9cf136abc923abbffc906a32cfb0e6d16ce61cc2d20748c2460f6844"
"cipherText": "0x04ab56bc879ce0f13b8a33b5046e8d99c4e0e2347af8f94064e75247e837c10c25b2980660f82cee60f4059890a366df5d8dff39ef40500be899ca3e969631efe0b615a2a4a32a15b2a3409ecc60d0216b4b3d37ef55a8638c9bea73f47a93d077c262fc21761dc5af278957c59e69ff5aa7794dba44ede16607e9c3b57d57462d",
"vkey": "0x00e35dd2e44ea70566507a46e650fda297f45149524b5eac6c2665ee0690face",
"publicValues": "0x0000000000000000000000000000000000000000000000000000000000000020ccbbcf2c854ac69d4d337a862cdf921daabe8896d3c990d02f21a3c900000000dbff552efd5921eb3cb0c9e8ef7297b6e186fc8ecfee7c4bf67a405a3fadca8cd90c2ed0346e85e3fc03a88ed8f205ed6d8ffdad65da84191b6b5936e1869762218da385c94e85331a105861767f3cbc05485e9bec742720c309123bbb45ac0225f128ada179ff10d05da8192f0faa2f0654e9748c94629194b30558fd5d2a6000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000008104ab56bc879ce0f13b8a33b5046e8d99c4e0e2347af8f94064e75247e837c10c25b2980660f82cee60f4059890a366df5d8dff39ef40500be899ca3e969631efe0b615a2a4a32a15b2a3409ecc60d0216b4b3d37ef55a8638c9bea73f47a93d077c262fc21761dc5af278957c59e69ff5aa7794dba44ede16607e9c3b57d57462d00000000000000000000000000000000000000000000000000000000000000",
"proof": "0x54bdcae316d0ee5d2c1eb72f265810a2864d69bdd7d68ada51b0db28b010614f5998c7fa0604d62b5220967b30d0e3c39e4205f53f195a655d5556d850b07b8259a4947f067d6780ba538d9fd0a0ef6814596dd5fb399f628439e42bd28f57d0ab26f10521628cfeb67cc0a2308d4f4f1b8e9586f77a46ff6c9bc606960ae99d1323624f21acae0a6d00651679af53a067be30868a58e84ab1a9d049784a8870659ba8640176167a6a44388fa0ba0d0e2e5530aedd1f66fd2afda099e470cb01a43c110a06daa5c9690236e19dcec2f0d12376d0fbd6aaa9765d8b07ffb2fe697af4edbf16d4178ba767a2f0a5dc3899c5cc931d3f3c1322921215323035ba183fa2815b093e2dd9787383dd51372fa9e4f7ff2d2be041b4cc89dbfe766388043e97bb3c09bbc768b68d023e0758299f816e1df8cc859f4595c96e867177cdaf0105a7d200a2270b95ade76c19d067b25d80c511366f562af675b0ab6ac53adda8493757134efab0fea37325f140a080f85effdc5032525a4bf8a9eaa250529f673d52380e3dce8871409ac460d225dd214b5f456e309937ffa1eb9e16e7bcddee5325d60e106a0998be4b450b7b50954b1a2b8809e551e2600042e1020037a7f353db1d01e75fb64534f44db3dd3dd22c218bc359e430485db1f9f3602f498dbb52b7f32ed250ffc600f47239f84c72ce9d99c72ef981eb27ad2b6d7d410ea4fff42d7b058587164f8630e2c018e6f45b3208ce71465cd3932f325857620a53a773a72a125ab32e384eba990444a18e39cc4d64b55edbaaf6248e58e74a09966ea858521995d3a515afeed2bb31e23a8b57cc645569aa9e584e356ad0a0cd6c744c9e301e20a347032e8d01a629c07e4605f5cde7e72877b11cea5b6ea57395fed8848906a0b6b6baea435d928552776ea81dc68c48bcd5b8374b62e7d770395ba9c734107a4e5898ce256d3c286e7ea2aae6f35a34f67007de32a34d0e3578652b952b2ea6a20f0c89450c4127a5c6fb8b36e7b97f38ac04c86010fe42d7c32ade73561ae6388f8156faae69229d26434f0a9c564e1906a10154bcbcd825688838de9a1c1b73a888faef6b5be6b5290507caf44a4e21e05050c9b3d367aa647ddb95aa1d15eb4767ed2e6028fa2f41f8dc7dbd5c89a716d2b7f34f1e4c9270c7d6dab52ed878c8ada6b053d622cb8244dfa205f376d11e8c82c0327596c99652f256cc"
}
Binary file modified elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
109 changes: 109 additions & 0 deletions inputs/test_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"pub_a_x": [
219, 255, 85, 46, 253, 89, 33, 235, 60, 176, 201, 232, 239, 114, 151,
182, 225, 134, 252, 142, 207, 238, 124, 75, 246, 122, 64, 90, 63, 173,
202, 140
],
"pub_a_y": [
217, 12, 46, 208, 52, 110, 133, 227, 252, 3, 168, 142, 216, 242, 5, 237,
109, 143, 253, 173, 101, 218, 132, 25, 27, 107, 89, 54, 225, 134, 151,
98
],
"pub_b_x": [
152, 138, 173, 223, 97, 145, 80, 132, 28, 26, 70, 22, 0, 145, 60, 209,
49, 229, 191, 108, 67, 120, 137, 118, 131, 227, 136, 40, 103, 121, 202,
211
],
"pub_b_y": [
93, 81, 17, 199, 142, 170, 65, 237, 116, 176, 67, 141, 203, 108, 178,
21, 186, 222, 230, 56, 163, 194, 153, 135, 210, 3, 138, 26, 235, 239,
221, 162
],
"pub_c_y": [
37, 241, 40, 173, 161, 121, 255, 16, 208, 93, 168, 25, 47, 15, 170, 47,
6, 84, 233, 116, 140, 148, 98, 145, 148, 179, 5, 88, 253, 93, 42, 96
],
"pub_c_x": [
33, 141, 163, 133, 201, 78, 133, 51, 26, 16, 88, 97, 118, 127, 60, 188,
5, 72, 94, 155, 236, 116, 39, 32, 195, 9, 18, 59, 187, 69, 172, 2
],
"priv_b": [
106, 96, 27, 238, 26, 219, 156, 72, 60, 153, 234, 89, 166, 191, 81, 28,
183, 212, 166, 136, 40, 123, 176, 254, 119, 83, 209, 137, 13, 43, 63,
130
],
"block_params": {
"version": [0, 0, 0, 32],
"previous_block_hash": [
207, 126, 77, 13, 158, 233, 240, 241, 47, 120, 39, 196, 81, 137, 5,
210, 172, 155, 203, 126, 3, 56, 34, 104, 153, 64, 231, 99, 0, 0, 0,
0
],
"timestamp": [16, 64, 84, 103],
"n_bits": [255, 255, 0, 29],
"nonce": [7, 220, 146, 143]
},
"block_hashes": [
[
204, 187, 207, 44, 133, 74, 198, 157, 77, 51, 122, 134, 44, 223,
146, 29, 170, 190, 136, 150, 211, 201, 144, 208, 47, 33, 163, 201,
0, 0, 0, 0
]
],
"outpoint_index": 0,
"tx_index": 4,
"tx_hex": [
2, 0, 0, 0, 0, 1, 1, 241, 211, 179, 200, 255, 168, 189, 41, 205, 42,
229, 255, 114, 30, 213, 49, 124, 111, 130, 17, 184, 182, 233, 35, 187,
160, 250, 54, 151, 114, 97, 253, 1, 0, 0, 0, 0, 255, 255, 255, 255, 2,
160, 134, 1, 0, 0, 0, 0, 0, 34, 0, 32, 138, 200, 41, 242, 147, 123, 31,
130, 119, 195, 244, 31, 94, 29, 31, 96, 69, 237, 96, 105, 235, 103, 160,
112, 5, 25, 79, 108, 80, 207, 237, 236, 174, 184, 17, 8, 0, 0, 0, 0, 22,
0, 20, 78, 239, 53, 181, 40, 32, 209, 128, 224, 144, 165, 90, 107, 246,
226, 149, 26, 109, 211, 61, 2, 71, 48, 68, 2, 32, 121, 114, 76, 209,
182, 129, 95, 27, 69, 146, 19, 6, 31, 23, 227, 66, 18, 20, 46, 95, 149,
7, 211, 151, 80, 33, 74, 49, 145, 68, 111, 78, 2, 32, 92, 120, 121, 89,
149, 189, 178, 222, 233, 241, 210, 236, 252, 11, 166, 103, 132, 160,
111, 108, 30, 29, 116, 159, 237, 55, 246, 105, 43, 13, 158, 144, 1, 33,
3, 221, 185, 40, 127, 121, 95, 66, 138, 218, 141, 125, 215, 190, 9, 78,
51, 137, 62, 132, 202, 72, 62, 128, 209, 207, 228, 17, 156, 151, 11,
187, 124, 0, 0, 0, 0
],
"proof": [
[
200, 107, 52, 234, 226, 196, 211, 79, 80, 229, 244, 88, 74, 3, 182,
57, 185, 2, 233, 6, 183, 158, 11, 115, 18, 181, 34, 117, 134, 208,
1, 147
],
[
96, 7, 26, 70, 233, 21, 55, 109, 49, 9, 14, 0, 132, 68, 155, 241,
101, 212, 63, 22, 28, 21, 215, 137, 52, 20, 73, 237, 185, 139, 63,
168
],
[
30, 58, 50, 139, 28, 79, 33, 18, 86, 67, 39, 32, 167, 77, 97, 20,
230, 133, 241, 153, 198, 132, 201, 105, 101, 131, 74, 13, 126, 20,
198, 27
],
[
89, 135, 141, 24, 24, 22, 115, 80, 219, 5, 160, 40, 46, 119, 249,
93, 6, 226, 175, 124, 27, 234, 231, 169, 162, 59, 58, 32, 161, 30,
129, 253
],
[
148, 50, 32, 193, 0, 53, 4, 249, 192, 93, 254, 97, 203, 220, 39,
103, 101, 238, 14, 197, 134, 116, 1, 78, 136, 177, 77, 190, 230,
122, 212, 160
],
[
6, 8, 196, 179, 201, 223, 112, 123, 45, 88, 195, 10, 195, 166, 68,
75, 47, 106, 146, 14, 64, 75, 195, 181, 51, 151, 216, 141, 121, 191,
206, 241
],
[
112, 25, 219, 238, 245, 54, 178, 151, 164, 218, 112, 4, 65, 250, 65,
167, 150, 125, 76, 36, 241, 88, 167, 28, 103, 239, 233, 110, 37, 41,
207, 17
]
]
}
1 change: 1 addition & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ hex = "0.4.3"
serde = { version = "1.0", features = ["derive"] }
ecies = { version = "0.2.3", default-features = false, features = ["pure"] }
libsecp256k1 = { version = "0.7.1" }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }

[patch.crates-io]
sha2-v0-10-8 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", branch = "patch-v0.10.8" }
Expand Down
51 changes: 44 additions & 7 deletions lib/src/btc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,40 @@ pub struct BitMix {
pub pub_a_y: [u8; 32],
pub pub_b_x: [u8; 32],
pub pub_b_y: [u8; 32],
pub priv_c: [u8; 32],
pub pub_c_x: [u8; 32],
pub pub_c_y: [u8; 32],
pub priv_b: [u8; 32],
}

impl BitMix {
pub fn verify(&self) -> (bool, Vec<[u8; 32]>, [u8; 32], [u8; 32], Vec<u8>) {
pub fn verify(
&self,
) -> (
bool,
Vec<[u8; 32]>,
[u8; 32],
[u8; 32],
[u8; 32],
[u8; 32],
Vec<u8>,
) {
let (tx_hash, _prevouts, outpoints) = parse_tx(&self.tx_hex);
let merkle_root = calculate_merkle_root(&tx_hash, self.tx_index, &self.proof);

let block_hash = calculate_block_hash(&self.block_params, merkle_root);

let sec_key = SecretKey::parse_slice(&self.priv_c).unwrap();
let pub_c = PublicKey::from_secret_key(&sec_key);
let pub_c_bytes = pub_c.serialize_compressed();
let mut pub_c_slice = Vec::new();
pub_c_slice.extend_from_slice(&self.pub_c_x);
pub_c_slice.extend_from_slice(&self.pub_c_y);

let pub_c_bytes =
PublicKey::parse_slice(&pub_c_slice, Some(libsecp256k1::PublicKeyFormat::Raw)).unwrap();
let compress_pub_c = pub_c_bytes.serialize_compressed();

let combined_pub_key =
point_addition(&self.pub_a_x, &self.pub_a_y, &self.pub_b_x, &self.pub_b_y);

let script_pub_key = construct_witness_script(combined_pub_key, pub_c_bytes);
let script_pub_key = calculate_witness_script_address(combined_pub_key, compress_pub_c);

assert!(compare_bytes(
outpoints[self.outpoint_index as usize].spk.clone(),
Expand All @@ -40,14 +56,35 @@ impl BitMix {

assert!(find_block_hash(&block_hash, &self.block_hashes));

let cipher_text = encrypt_ecies(&self.pub_a_x, &self.pub_a_y, &self.priv_c[0..32]);
let cipher_text = encrypt_ecies(&self.pub_a_x, &self.pub_a_y, &self.priv_b);

(
true,
self.block_hashes.clone(),
self.pub_a_x,
self.pub_a_y,
self.pub_c_x,
self.pub_c_y,
cipher_text,
)
}
}

mod tests {
use super::*;
use libsecp256k1::SecretKey;
use serde::{Deserialize, Serialize};
use std::fs;

#[test]
fn test_bitmix() {
let input_file = "/Users/yash/Desktop/crema/bitmix/inputs/test_1.json";

let file_content = fs::read_to_string(input_file).unwrap();
let bitmix_input: BitMix = serde_json::from_str(&file_content).unwrap();

let (verified, _, _, _, _, _, _) = bitmix_input.verify();

assert!(verified);
}
}
21 changes: 14 additions & 7 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ sol! {
bytes32[1] memory block_hashes;
bytes32 pub_a_x;
bytes32 pub_a_y;
bytes32 pub_c_x;
bytes32 pub_c_y;
bytes memory cipher;
}
}
Expand Down Expand Up @@ -254,13 +256,13 @@ fn point_addition(pub_a_x: &[u8], pub_a_y: &[u8], pub_b_x: &[u8], pub_b_y: &[u8]
pub_a_slice.extend_from_slice(pub_a_x);
pub_a_slice.extend_from_slice(pub_a_y);
let pub_a =
PublicKey::parse_slice(&pub_a_slice, Some(libsecp256k1::PublicKeyFormat::Full)).unwrap();
PublicKey::parse_slice(&pub_a_slice, Some(libsecp256k1::PublicKeyFormat::Raw)).unwrap();

let mut pub_b_slice = Vec::new();
pub_b_slice.extend_from_slice(pub_b_x);
pub_b_slice.extend_from_slice(pub_b_y);
let pub_b =
PublicKey::parse_slice(&pub_b_slice, Some(libsecp256k1::PublicKeyFormat::Full)).unwrap();
PublicKey::parse_slice(&pub_b_slice, Some(libsecp256k1::PublicKeyFormat::Raw)).unwrap();
let pub_c = PublicKey::combine(&[pub_a, pub_b]).unwrap();
let pub_c_bytes = pub_c.serialize_compressed();

Expand Down Expand Up @@ -317,6 +319,7 @@ mod tests {
.unwrap();
let data = b"Hello, world!";
let encrypted_data = encrypt_ecies(&x, &y, data);
println!("{:?}", hex::encode(encrypted_data));
}

#[test]
Expand Down Expand Up @@ -356,13 +359,17 @@ mod tests {
let pub_b = PublicKey::from_secret_key(&sec_key_b);

let sec_key_c = SecretKey::parse_slice(&priv_key_c).unwrap();
let pub_c = PublicKey::from_secret_key(&sec_key_c).serialize_compressed();
let pub_c = PublicKey::from_secret_key(&sec_key_c);

let pub_ab = PublicKey::combine(&[pub_a, pub_b])
.unwrap()
.serialize_compressed();

let script_pubkey = calculate_witness_script_address(pub_ab, pub_c);
println!("pub_a: {:?} pub_b: {:?} pub_c: {:?} {}", pub_a.serialize()[32], pub_b.serialize()[32], pub_c.serialize(), pub_c.serialize()[32]);

let pub_ab = PublicKey::combine(&[pub_a, pub_b]).unwrap();

let script_pubkey = calculate_witness_script_address(
pub_ab.serialize_compressed(),
pub_c.serialize_compressed(),
);

assert_eq!(
script_pubkey,
Expand Down
Loading

0 comments on commit e2dbdaf

Please sign in to comment.