Coder Social home page Coder Social logo

xdagj-native-randomx's Introduction

Welcome to xdagj-native-randomx

GitHub release (latest SemVer) GitHub GitHub issues

Donation address

XDAG:BkcVG4i1BfxUJLdNPdctaCReBoyn4j32d

Development is based on xdagj community-driven

RandomX

RandomX is a proof-of-work (PoW) algorithm that is optimized for general-purpose CPUs. RandomX uses random code execution (hence the name) together with several memory-hard techniques to minimize the efficiency advantage of specialized hardware.

RandomX

Xdagj

The java version of xdag

Xdagj

Xdagj-Native-RandomX

xdagj-native-randomx is an implements of RandomX use Java JNA.

Install

1. system

JDK   : v17
Maven : v3.9.1

2. compile

2.1 checkout

git clone https://github.com/XDagger/xdagj-native-randomx.git
cd xdagj-native-randomx
git submodule init
git submodule update

2.2 compile randomx lib

2.2.1 compile randomx share lib

cd randomx
mkdir build && cd build
cmake .. -DARCH=native -DBUILD_SHARED_LIBS=ON -DCMAKE_C_FLAGS="-fPIC"
make
cp -i librandomx.dylib ../../src/main/resources
overwrite ../../src/main/resources/librandomx.dylib? (y/n [n]) y

2.2.2 compile java lib

cd ../../
mvn package

3. maven system dependency

<dependency>
    <groupId>io.xdag</groupId>
    <artifactId>xdagj-native-randomx</artifactId>
    <version>0.1.7</version>
</dependency>

4. example

package io.xdag.crypto.randomx;

import java.nio.charset.StandardCharsets;
import java.util.HexFormat;
import java.util.List;

public class Example {

        String key = "hello xdagj-native-randomx";
        byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
    
        // 1. build randomx jna wrapper
        RandomXWrapper randomXWrapper = RandomXWrapper.builder()
                .flags(List.of(RandomXFlag.JIT, RandomXFlag.HARD_AES, RandomXFlag.ARGON2))
                .fastInit(false)
                .miningMode(false)
                .build();
    
        byte[] seed = new byte[]{(byte)1, (byte)2, (byte)3, (byte)4};
        // 2. init dataset or cache
            randomXWrapper.init(seed);
    
        // 3. create randomxVm
        RandomXVM randomxVm = randomXWrapper.createVM();
    
        // 4. calculate hash
        byte[] hash = randomxVm.getHash(keyBytes);
    
        // 5. print result
        HexFormat hex = HexFormat.of();
        System.out.println("message:" + key);
        System.out.println("hash:" + hex.formatHex(hash));
    }
}

5. benchmark

JMH is a Java harness for building, running, and analysing nano/micro/milli/macro benchmarks written in Java and other languages targetting the JVM

result of ubuntu:

system :macOS 13.3.1
CPU    :Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
RAM    :16 GB 2667 MHz DDR4
Benchmark Mode Cnt Score Error Units
RandomXJNAPerformance.testHash thrpt 25 75.130 ± 2.128 ops/s
RandomXJNAPerformance.testHash avgt 25 0.015 ± 0.001 s/op

xdagj-native-randomx's People

Contributors

cherry1603 avatar lucasmlk avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

xdagj-native-randomx's Issues

SIGILL during JNI call

hi @Holt666 , @cherry1603 , I am running into issue while running Example.java
Tried both to build project , and importing xdagj-native-randomx-0.1.7 as Maven dependency into another project, same issue

/home/user/.sdkman/candidates/java/17.0.8-amzn/bin/java -javaagent:/home/user/Downloads/idea-IU-232.10203.10/lib/idea_rt.jar=36503:/home/user/Downloads/idea-IU-232.10203.10/bin -Dfile.encoding=UTF-8 -classpath /home/user/TOOLS/drill/target/classes:/home/user/.m2/repository/commons-cli/commons-cli/1.4/commons-cli-1.4.jar:/home/user/.m2/repository/org/slf4j/slf4j-simple/1.7.21/slf4j-simple-1.7.21.jar:/home/user/.m2/repository/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar:/home/user/.m2/repository/com/eclipsesource/minimal-json/minimal-json/0.9.2/minimal-json-0.9.2.jar:/home/user/.m2/repository/io/xdag/xdagj-native-randomx/0.1.7/xdagj-native-randomx-0.1.7.jar:/home/user/.m2/repository/net/java/dev/jna/jna/5.13.0/jna-5.13.0.jar tk.netindev.drill.Drill

A fatal error has been detected by the Java Runtime Environment:

SIGILL (0x4) at pc=0x00007f3db00b5954, pid=1086159, tid=1086160

JRE version: OpenJDK Runtime Environment Corretto-17.0.8.7.1 (17.0.8+7) (build 17.0.8+7-LTS)

Java VM: OpenJDK 64-Bit Server VM Corretto-17.0.8.7.1 (17.0.8+7-LTS, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)

Problematic frame:

C [jna18207388093069493637.tmp+0x32954] randomx_blake2b_init_param+0x74

No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again

If you would like to submit a bug report, please visit:

https://github.com/corretto/corretto-17/issues/

The crash happened outside the Java Virtual Machine in native code.

See problematic frame for where to report the bug.

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

Ubuntu-20.04, latest Idea

Any help will be appreciated :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.