{"id":19720480,"url":"https://github.com/xdagger/xdagj-native-randomx","last_synced_at":"2025-04-29T21:30:52.632Z","repository":{"id":92608920,"uuid":"566116214","full_name":"XDagger/xdagj-native-randomx","owner":"XDagger","description":"Java Native Randomx Implement","archived":false,"fork":false,"pushed_at":"2025-02-25T09:01:36.000Z","size":2672,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T19:34:22.090Z","etag":null,"topics":["java","jna","jni","randomx","xdag","xdagj"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/XDagger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-15T01:55:01.000Z","updated_at":"2025-03-04T06:22:57.000Z","dependencies_parsed_at":"2024-11-11T23:21:42.336Z","dependency_job_id":null,"html_url":"https://github.com/XDagger/xdagj-native-randomx","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XDagger%2Fxdagj-native-randomx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XDagger%2Fxdagj-native-randomx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XDagger%2Fxdagj-native-randomx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XDagger%2Fxdagj-native-randomx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/XDagger","download_url":"https://codeload.github.com/XDagger/xdagj-native-randomx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251585757,"owners_count":21613274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jna","jni","randomx","xdag","xdagj"],"created_at":"2024-11-11T23:11:36.579Z","updated_at":"2025-04-29T21:30:52.626Z","avatar_url":"https://github.com/XDagger.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Welcome to xdagj-native-randomx\n\n![Build Status](https://github.com/XDagger/xdagj-native-randomx/actions/workflows/maven.yml/badge.svg)\n![Latest Release](https://img.shields.io/github/v/release/XDagger/xdagj-native-randomx)\n![License](https://img.shields.io/github/license/XDagger/xdagj-native-randomx)\n![Issues](https://img.shields.io/github/issues/XDagger/xdagj-native-randomx)\n\n---\n\n## Introduction\n\n`xdagj-native-randomx` is a Java implementation of the RandomX proof-of-work algorithm using JNA (Java Native Access). This library is a community-driven project based on the [xdagj](https://github.com/XDagger/xdagj) ecosystem.\n\n### **What is RandomX?**\n\nRandomX is a proof-of-work (PoW) algorithm optimized for general-purpose CPUs. It uses random code execution and memory-hard techniques to minimize the efficiency advantage of specialized hardware like ASICs.\n\nFor more details, visit the [RandomX GitHub repository](https://github.com/tevador/RandomX).\n\n---\n\n## Features\n\n- **Native Integration**: Leverages RandomX's native C++ library via JNA.\n- **Cross-Platform Support**: Works on Linux, macOS (x86_64 and aarch64), and Windows.\n- **Easy Integration**: Available as a Maven dependency for seamless use in Java projects.\n\n---\n\n## Donation Address\n\nSupport the project with XDAG donations:  \n**XDAG Address**: `BkcVG4i1BfxUJLdNPdctaCReBoyn4j32d`\n\n---\n\n## Installation\n\n### **1. Requirements**\n\n- **JDK**: v17 or later\n- **Maven**: v3.9.9 or later\n\n### **2. Build Steps**\n\n#### **2.1 Clone the Repository**\n```bash\ngit clone https://github.com/XDagger/xdagj-native-randomx.git\ncd xdagj-native-randomx\ngit submodule init\ngit submodule update\n```\n\n#### **2.2 Compile RandomX Native Library**\n\nCompile and copy the appropriate shared library for your platform:\n\n##### **Linux x86_64**\n```bash\ncd randomx\nmkdir build \u0026\u0026 cd build\ncmake .. -DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON -DCMAKE_C_FLAGS=\"-fPIC\"\nmake -j4\ncp -i librandomx.so ../../src/main/resources/native/librandomx_linux_x86_64.so\n```\n\n##### **macOS x86_64**\n```bash\ncd randomx\nmkdir build \u0026\u0026 cd build\ncmake .. -DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON\nmake -j4\ncp -i librandomx.dylib ../../src/main/resources/native/librandomx_macos_x86_64.dylib\n```\n\n##### **macOS aarch64**\n```bash\ncd randomx\nmkdir build \u0026\u0026 cd build\ncmake .. -DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON\nmake -j4\ncp -i librandomx.dylib ../../src/main/resources/native/librandomx_macos_aarch64.dylib\n```\n\n##### **Windows x86_64**\n```bash\ncd randomx\nmkdir build \u0026\u0026 cd build\ncmake .. -G \"MinGW Makefiles\" -DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON\nmake -j4\ncp -i randomx.dll ../../src/main/resources/native/librandomx_windows_x86_64.dll\n```\n\n#### **2.3 Compile Java Library**\n```bash\ncd ../../\nmvn clean package\n```\n\n### **3. Add Maven Dependency**\n\nTo include `xdagj-native-randomx` in your project, add the following dependency to your `pom.xml`:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.xdag\u003c/groupId\u003e\n    \u003cartifactId\u003exdagj-native-randomx\u003c/artifactId\u003e\n    \u003cversion\u003e0.2.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n---\n\n## Usage Example\n\n```java\npackage io.xdag.crypto.randomx;\n\nimport java.nio.charset.StandardCharsets;\nimport java.util.HexFormat;\nimport java.util.Set;\n\npublic class Example {\n    \n    public static void main(String[] args) {\n        // Key to be hashed\n        String key = \"hello xdagj-native-randomx\";\n        byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);\n\n        // Get supported RandomX flags for the current CPU\n        Set\u003cRandomXFlag\u003e flags = RandomXUtils.getFlagsSet();\n        System.out.println(\"Supported flags: \" + flags);\n        int combinedFlags = RandomXFlag.toValue(flags);\n        System.out.println(\"Combined flags value: \" + combinedFlags);\n\n        // Initialize RandomX cache with the supported flags\n        RandomXCache cache = new RandomXCache(flags);\n        cache.init(keyBytes);\n\n        // Create and configure RandomXTemplate using builder pattern\n        byte[] hash;\n        try (RandomXTemplate template = RandomXTemplate.builder()\n                .cache(cache)\n                .miningMode(false)  // Set to false for normal hashing mode\n                .flags(flags)\n                .build()) {\n\n            // Initialize the template with the configured settings\n            template.init();\n\n            // Calculate hash of the input key\n            hash = template.calculateHash(keyBytes);\n        }\n\n        // Format and display the results\n        HexFormat hex = HexFormat.of();\n        System.out.printf(\"Message: %s%n\", key);\n        System.out.printf(\"Hash: %s%n\", hex.formatHex(hash));\n    }\n}\n```\n\n---\n\n## Benchmark Results\n\n### Linux System Configuration\n- **OS**: Linux 5.4.119\n- **CPU**: AMD EPYC 9754 (16 cores)\n- **RAM**: 32 GB\n- **thread**: 8\n- **RandomX Flags**: [DEFAULT, HARD_AES, JIT, ARGON2_SSSE3, ARGON2_AVX2, ARGON2]\n\n### Linux Performance Results\n|           Benchmark            | Mode  | Cnt | Score   | Error  | Units |\n|:------------------------------:|:-----:|:---:|:-------:|:------:|:-----:|\n| RandomXBenchmark.lightBatch | thrpt |   | 328.736  |  | ops/s |\n| RandomXBenchmark.lightNoBatch | thrpt  |   | 325.383   |  | ops/s  |\n| RandomXBenchmark.miningBatch | thrpt  |   | 2777.939   |  | ops/s  |\n| RandomXBenchmark.miningNoBatch | thrpt  |   | 2817.811   |  | ops/s  |\n\n---\n\n### MacOS System Configuration\n- **OS**: macOS 15.1.1\n- **CPU**: Apple M3 Pro\n- **RAM**: 36 GB\n- **thread**: 8\n- **RandomX Flags**: [DEFAULT, HARD_AES, SECURE]\n\nJIT flag will cause jvm to crash in MacOS\n\n### MacOS Performance Results\n|           Benchmark            | Mode  | Cnt | Score   | Error  | Units |\n|:------------------------------:|:-----:|:---:|:-------:|:------:|:-----:|\n| RandomXBenchmark.lightBatch | thrpt |   | 32.864  |  | ops/s |\n| RandomXBenchmark.lightNoBatch | thrpt  |   | 33.683   |  | ops/s  |\n| RandomXBenchmark.miningBatch | thrpt  |   | 554.966   |  | ops/s  |\n| RandomXBenchmark.miningNoBatch | thrpt  |   | 570.060   |  | ops/s  |\n\n---\n\n## Contribution\n\nWe welcome contributions to improve the project! Please feel free to submit issues or pull requests.\n\nFor discussions or questions, contact the [xdagj community](https://github.com/XDagger/xdagj).\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxdagger%2Fxdagj-native-randomx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxdagger%2Fxdagj-native-randomx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxdagger%2Fxdagj-native-randomx/lists"}