Skip to content
Draft
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 constantine/constantine
Submodule constantine updated 385 files
5 changes: 5 additions & 0 deletions constantine/jna_ethereum_evm_precompiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ int bls12381_mapFpToG1(byte* r, int r_len, const byte* inputs, int inputs_len) {

int bls12381_mapFp2ToG2(byte* r, int r_len, const byte* inputs, int inputs_len) {
return (int) ctt_eth_evm_bls12381_map_fp2_to_g2(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len);
}


void keccak256(byte* result, byte* message, int message_len) {
ctt_keccak256_hash(result, message, (ptrdiff_t)message_len,0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.hyperledger.besu.nativelib.constantine;

import com.sun.jna.Native;

public class LibConstantineKeccak256 {
public static final boolean ENABLED;

static {
boolean enabled;
try {
Native.register(LibConstantineKeccak256.class, "constantinebindings");
enabled = true;
} catch (final Throwable t) {
t.printStackTrace();
enabled = false;
}
ENABLED = enabled;
}

public static native int keccak256(byte[] output, byte[] input, int input_len);

public static byte[] keccak256(byte[] input) {
byte[] output = new byte[32];
keccak256(output, input, input.length);
return output;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.hyperledger.besu.nativelib.constantine;

import org.apache.tuweni.bytes.Bytes;
import org.junit.Test;

import java.nio.charset.StandardCharsets;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;

public class LibConstantineKeccak256Test {

@Test
public void testKeccakNonimalCase() {
final byte[] inputs = "testKeccak256".getBytes(StandardCharsets.UTF_8);
final byte[] result = LibConstantineKeccak256.keccak256(inputs);
assertEquals(Bytes.wrap(result), Bytes.fromHexString("0xfe8baa653979909c621153b53c973bab3832768b5e77896a5b5944d20d48c7a6"));
}


}
Loading