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

Linking error potential fix #131

Merged
merged 5 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion ipa-multipoint/ipa_multipoint_jni/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub extern "system" fn Java_org_hyperledger_besu_nativelib_ipamultipoint_LibIpaM
/// Commit_root receives a list of 32 byte scalars and returns a 32 byte commitment.to_bytes()
/// This is ported from rust-verkle.
#[no_mangle]
pub extern "system" fn Java_org_hyperledger_besu_nativelib_ipamultipoint_LibIpaMultipoint_commit_root(env: JNIEnv,
pub extern "system" fn Java_org_hyperledger_besu_nativelib_ipamultipoint_LibIpaMultipoint_commitRoot(env: JNIEnv,
_class: JClass<'_>,
input: jbyteArray)
-> jbyteArray {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class LibIpaMultipoint {
* @param input [Fr,Fr,Fr...]
* @return commitment.to_bytes()
*/
public static native byte[] commit_root(byte[] input);
public static native byte[] commitRoot(byte[] input);

/**
* Pedersen hash as specified in https://notes.ethereum.org/@vbuterin/verkle_tree_eip
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright Besu Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
package org.hyperledger.besu.nativelib.ipa_multipoint;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.assertj.core.api.Assertions.*;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.hyperledger.besu.nativelib.ipamultipoint.LibIpaMultipoint;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class CommitRootTest {
private static final ObjectMapper objectMapper = new ObjectMapper();

public static List<TestData> JsonData() throws IOException {
InputStream inputStream = PedersenCommitmentTest.class.getResourceAsStream("/genesis_lvl1_commits.json");
return objectMapper.readValue(inputStream, new TypeReference<List<TestData>>() {
});
}

static class TestData {
public ArrayList<String> frs;
public String expected;
}

@ParameterizedTest
@MethodSource("JsonData")
public void TestPolynomialCommitments(TestData testData) {
List<Bytes> FrBytes = new ArrayList<>();
for (int i = 0; i < 256; i++) {
Bytes32 value = Bytes32.fromHexString(testData.frs.get(i));
FrBytes.add(value);
}
byte[] input = Bytes.concatenate(FrBytes).toArray();
Bytes32 result = Bytes32.wrap(LibIpaMultipoint.commitRoot(input));
Bytes32 expected = Bytes32.fromHexString(testData.expected);
assertThat(result).isEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public void testCallLibrary() {
assertThat(result).isEqualTo(expected);
}

@Test
public void testCallLibraryCommitRoot() {
Bytes32 input = Bytes32.fromHexString("0xf6e31f7a565a390b48fdd24569ac10d43562d19de37ea951c7f9f250a339d059");
Bytes32 result = Bytes32.wrap(LibIpaMultipoint.commitRoot(input.toArray()));
Bytes32 expected = Bytes32.fromHexString("0x588f93e52b41d8d3abade94bf44a2ccd5d6ef9090a63164fba8d02c909168c53");
assertThat(result).isEqualTo(expected);
}

@Test
public void testCallLibraryWithManyElements() {
Bytes32 element = Bytes32.fromHexString("0x0cfe3041fb6512c87922e2146c8308b372f3bf967f889e69ad116ce7c7ec00");
Expand Down
Loading
Loading