{"id":18031470,"url":"https://github.com/mcdouglas-x/kangaroo-256-custom","last_synced_at":"2025-10-30T13:47:42.175Z","repository":{"id":259047177,"uuid":"874875402","full_name":"Mcdouglas-X/KANGAROO-256-CUSTOM","owner":"Mcdouglas-X","description":"Kangaroo with the goal of improving efficiency without losing the success rate.","archived":false,"fork":false,"pushed_at":"2024-12-13T16:16:58.000Z","size":1871,"stargazers_count":14,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-23T04:23:09.087Z","etag":null,"topics":["256-bit","algorithm","bitcoin","kangaroo","publickey","puzzle"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mcdouglas-X.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":"2024-10-18T16:10:39.000Z","updated_at":"2025-02-23T11:06:33.000Z","dependencies_parsed_at":"2024-10-22T19:20:10.731Z","dependency_job_id":null,"html_url":"https://github.com/Mcdouglas-X/KANGAROO-256-CUSTOM","commit_stats":null,"previous_names":["mcdouglas-x/kangaroo-256-custom"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mcdouglas-X%2FKANGAROO-256-CUSTOM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mcdouglas-X%2FKANGAROO-256-CUSTOM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mcdouglas-X%2FKANGAROO-256-CUSTOM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mcdouglas-X%2FKANGAROO-256-CUSTOM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mcdouglas-X","download_url":"https://codeload.github.com/Mcdouglas-X/KANGAROO-256-CUSTOM/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245791269,"owners_count":20672664,"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":["256-bit","algorithm","bitcoin","kangaroo","publickey","puzzle"],"created_at":"2024-10-30T10:09:16.540Z","updated_at":"2025-10-30T13:47:37.124Z","avatar_url":"https://github.com/Mcdouglas-X.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pollard's kangaroo for SECPK1\n\nThis 256bit version is based on:\n\nhttps://github.com/JeanLucPons/Kangaroo        125bit version\n\nWith ideas from:\n\nhttps://github.com/ZenulAbidin/Kangaroo-256    \n\nhttps://github.com/Totulik/Kangaroo-254-bit\n\nhttps://github.com/AlberTajuelo/kangaroo\n\nhttps://github.com/mikorist/Kangaroo-256-bit\n\n\nA Pollard's kangaroo interval ECDLP solver for SECP256K1 (based on VanitySearch engine).\n\n# Feature\n\n\u003cul\u003e\n  \u003cli\u003eFixed size arithmetic.\u003c/li\u003e\n  \u003cli\u003eFast Modular Inversion (Delayed Right Shift 62 bits).\u003c/li\u003e\n  \u003cli\u003eSecpK1 Fast modular multiplication (2 steps folding 512bits to 256bits reduction using 64 bits digits).\u003c/li\u003e\n  \u003cli\u003eMulti-GPU support.\u003c/li\u003e\n  \u003cli\u003eCUDA optimisation via inline PTX assembly.\u003c/li\u003e\n  \u003cli\u003eFull 256-bit interval search.\u003c/li\u003e\n  \u003cli\u003eImproved automatic dp selection based on range.\u003c/li\u003e\n  \u003cli\u003eImproved jump section for a more controlled success rate.\u003c/li\u003e\n\u003c/ul\u003e\n\n# Discussion Thread\n\nDiscusion thread: https://bitcointalk.org/index.php?topic=5513657\n\n# Usage\n\n```\n./kangaroo-256 55.txt\n```\n\n```\nKangaroo v2.3\nKangaroo [-v] [-t nbThread] [-d dpBit] [gpu] [-check]\n         [-gpuId gpuId1[,gpuId2,...]] [-g g1x,g1y[,g2x,g2y,...]]\n         inFile\n -v: Print version\n -gpu: Enable gpu calculation\n -gpuId gpuId1,gpuId2,...: List of GPU(s) to use, default is 0\n -g g1x,g1y,g2x,g2y,...: Specify GPU(s) kernel gridsize, default is 2*(MP),2*(Core/MP)\n -d: Specify number of leading zeros for the DP method (default is auto)\n -t nbThread: Secify number of thread\n -w workfile: Specify file to save work into (current processed key only)\n -i workfile: Specify file to load work from (current processed key only)\n -wi workInterval: Periodic interval (in seconds) for saving work\n -ws: Save kangaroos in the work file\n -wsplit: Split work file of server and reset hashtable\n -wm file1 file2 destfile: Merge work file\n -wmdir dir destfile: Merge directory of work files\n -wt timeout: Save work timeout in millisec (default is 3000ms)\n -winfo file1: Work file info file\n -wpartcreate name: Create empty partitioned work file (name is a directory)\n -wcheck worfile: Check workfile integrity\n -m maxStep: number of operations before give up the search (maxStep*expected operation)\n -o fileName: output result to fileName\n -l: List cuda enabled devices\n -check: Check GPU kernel vs CPU\n inFile: intput configuration file\n```\n\nStructure of the input file:\n* All values are in hex format\n* Public keys can be given either in compressed or uncompressed format\n\n```\nStart range\nEnd range\nKey #1\n```\n\nex\n\n```\n200000000000000000000000000000000\n3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n03633CBE3EC02B9401C5EFFA144C5B4D22F87940259634858FC7E59B1C09937852\n```\n\n# Note on Time/Memory tradeoff of the DP method\n\nThe distinguished point (DP) method is an efficient method for storing random walks and detect collision between them. Instead of storing all points of all kangagroo's random walks, we store only points that have an x value starting with dpBit zero bits. When 2 kangaroos collide, they will then follow the same path because their jumps are a function of their x values. The collision will be then detected when the 2 kangaroos reach a distinguished point.\\\nThis has a drawback when you have a lot of kangaroos and looking for collision in a small range as the overhead is in the order of nbKangaroo.2\u003csup\u003edpBit\u003c/sup\u003e until a collision is detected. If dpBit is too small a large number of point will enter in the central table, will decrease performance and quickly fill the RAM.\n**Powerfull GPUs with large number of cores won't be very efficient on small range, you can try to decrease the grid size in order to have less kangaroos but the GPU performance may not be optimal.**\nYau can change manualy the DP mask size using the -d option, take in consideration that it will require more operations to complete. See table below:\n\n| nbKangaroo.2\u003csup\u003edpBit\u003c/sup\u003e/sqrt(N) |  DP Overhead | Avg | \n|--------------------------------------|:------------:|:---:|\n| 4.000 | cubicroot(1+4.000) = ~71.0% | 3.55 sqrt(N) |\n| 2.000 | cubicroot(1+2.000) = ~44.2% | 2.99 sqrt(N) |\n| 1.000 | cubicroot(1+1.000) = ~26.0% | 2.62 sqrt(N) |\n| 0.500 | cubicroot(1+0.500) = ~14.5% | 2.38 sqrt(N) |\n| 0.250 | cubicroot(1+0.250) = ~7.7% | 2.24 sqrt(N) |\n| 0.125 | cubicroot(1+0.125) = ~4.0% | 2.16 sqrt(N) |\n\nDP overhead according to the range size (N), DP mask size (dpBit) and number of kangaroos running in paralell (nbKangaroo).\n\n# Probability of success\n\nThe picture below show the probability of success after a certain number of group operations. N is range size.\nThis plot does not take into consideration the DP overhead.\n\n![Probability of success](DOC/successprob.jpg)\n\n\n# How it works\n\nThe program uses 2 herds of kangaroos, a tame herd and a wild herd. When 2 kangoroos (a wild one and a tame one) collide, the \nkey can be solved. Due to the birthday paradox, a collision happens (in average) after 2.08*sqrt(k2-k1) [1] group operations, the 2 herds have the same size. To detect collision, the distinguished points method is used with a hashtable.\n\nHere is a brief description of the algorithm:\n\nWe have to solve P = k.G, P is the public key, we know that k lies in the range [k1,k2], G is the SecpK1 generator point.\\\nGroup operations are additions on the elliptic curve, scalar operations are done modulo the order of the curve.\n\nn = floor(log2(sqrt(k2-k1)))+1\n\n* Create a jump point table jP = [G,2G,4G,8G,...,2\u003csup\u003en-1\u003c/sup\u003e.G]\n* Create a jump distance table jD = [1,2,4,8,....,2\u003csup\u003en-1\u003c/sup\u003e]\n \nfor all i in herdSize\u003c/br\u003e\n\u0026nbsp;\u0026nbsp;tame\u003csub\u003ei\u003c/sub\u003e = rand(0..(k2-k1)) \u003cem\u003e# Scalar operation\u003c/em\u003e\u003c/br\u003e\n\u0026nbsp;\u0026nbsp;tamePos\u003csub\u003ei\u003c/sub\u003e = (k1+tame\u003csub\u003ei\u003c/sub\u003e).G \u003cem\u003e# Group operation\u003c/em\u003e\u003c/br\u003e\n\u0026nbsp;\u0026nbsp;wild\u003csub\u003ei\u003c/sub\u003e = rand(0..(k2-k1)) - (k2-k1)/2 \u003cem\u003e# Scalar operation\u003c/em\u003e\u003c/br\u003e\n\u0026nbsp;\u0026nbsp;wildPos\u003csub\u003ei\u003c/sub\u003e = P + wild\u003csub\u003ei\u003c/sub\u003e.G \u003cem\u003e# Group operation\u003c/em\u003e\u003c/br\u003e\n\nfound = false\u003c/br\u003e\n\nwhile not found\u003c/br\u003e\n\u0026nbsp;\u0026nbsp;for all i in herdSize\u003c/br\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;  tamePos\u003csub\u003ei\u003c/sub\u003e = tamePos\u003csub\u003ei\u003c/sub\u003e + jP[tamePos\u003csub\u003ei\u003c/sub\u003e.x % n] \u003cem\u003e# Group operation\u003c/em\u003e\u003c/br\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;  tame\u003csub\u003ei\u003c/sub\u003e += jD[tamePos\u003csub\u003ei\u003c/sub\u003e.x % n] \u003cem\u003e# Scalar operation\u003c/em\u003e\u003c/br\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;  wildPos\u003csub\u003ei\u003c/sub\u003e = wildPos\u003csub\u003ei\u003c/sub\u003e + jP[wildPos\u003csub\u003ei\u003c/sub\u003e.x % n] \u003cem\u003e# Group operation\u003c/em\u003e\u003c/br\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;  wild\u003csub\u003ei\u003c/sub\u003e += jD[wildPos\u003csub\u003ei\u003c/sub\u003e.x % n] \u003cem\u003e# Scalar operation\u003c/em\u003e\u003c/br\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;  if tamePos\u003csub\u003ei\u003c/sub\u003e is distinguished\u003c/br\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;  add (TAME,tamePos\u003csub\u003ei\u003c/sub\u003e,tame\u003csub\u003ei\u003c/sub\u003e) to hashTable\u003c/br\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;  if wildPos\u003csub\u003ei\u003c/sub\u003e is distinguished\u003c/br\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;  add (WILD,wildPos\u003csub\u003ei\u003c/sub\u003e,wild\u003csub\u003ei\u003c/sub\u003e) to hashTable\u003c/br\u003e\n\u0026nbsp;\u0026nbsp;found = is there a collision in hashTable between a tame and a wild kangaroo ?\u003c/br\u003e\n\u003c/br\u003e\n\n(Tame,Wild) = Collision\u003c/br\u003e\nk = k1 + Tame.dist - Wild.dist\u003c/br\u003e\n\n\nHere is an illustration of what's happening. When 2 paths collide they form a shape similar to the lambda letter. This is why this method is also called lambda method.\n\n![Paths](DOC/paths.jpg)\n\n# Compilation\n\n**compile using WSL on Windows**\n\nCompilation Commands:\n```\nmake gpu=1    Compile with GPU support.\n\nmake cpu=1    Compile optimized for CPUs.\n\nmake debug=1  Compile with debug symbols for debugging.\n```\n\nMain Target: Compiles the final executable kangaroo-256.\n\nDependency Management: Ensures that necessary directories ($(OBJDIR), $(OBJDIR)/SECPK1, $(OBJDIR)/GPU) are created before compiling.\n\nCleaning: Removes all object files and other generated files (cuda_version.txt, deviceQuery/cuda_build_log.txt) when make clean is invoked.\n\nThis Makefile structure allows you to easily switch between different compilation configurations (amd, gpu, default) by setting appropriate flags when invoking make, or by modifying the Makefile directly. Adjust paths (CUDA, CXXCUDA), compiler flags (CXXFLAGS, LFLAGS), and dependencies (SRC, OBJET) as per your project's requirements.\n\n## Windows\n\nInstall CUDA SDK 10.2 and open VC_CUDA102\\Kangaroo.sln in Visual C++ 2019.\\\nYou may need to reset your *Windows SDK version* in project properties.\\\nIn Build-\u003eConfiguration Manager, select the *Release* configuration.\\\nBuild and enjoy.\\\n\\\nNote: The current release has been compiled with Visual studio 2019 and CUDA SDK 10.2, if you have a different release of the CUDA SDK, you may need to update CUDA SDK paths in Kangaroo.vcxproj using a text editor. The current nvcc option are set up to architecture starting at 3.0 capability, for older hardware, add the desired compute capabilities to the list in GPUEngine.cu properties, CUDA C/C++, Device, Code Generation.\n\nVisual Sutido 2017 + Cuda 10 =\u003e Take project files in VC_CUDA10 (project files might be out of date)\\\nVisual Studio 2019 + Cuda10.2 =\u003e Take project files in VC_CUDA102\\\n\n## Linux\n\nInstall CUDA SDK.\\\nDepending on the CUDA SDK version and on your Linux distribution you may need to install an older g++ (just for the CUDA SDK).\\\nEdit the makefile and set up the good CUDA SDK path and appropriate compiler for nvcc. \n\n```\nCUDA       = /usr/local/cuda-8.0\nCXXCUDA    = /usr/bin/g++-4.8\n```\n\nYou can enter a list of architecture (refer to nvcc documentation) if you have several GPU with different architecture. Compute capability 2.0 (Fermi) is deprecated for recent CUDA SDK.\nKangaroo need to be compiled and linked with a recent gcc (\u003e=7). The current release has been compiled with gcc 7.3.0.\\\nGo to the Kangaroo directory. ccap is the desired compute capability.\n\n```\n$ g++ -v\ngcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04)\n$ make all (for build without CUDA support)\nor\n$ make gpu=1 ccap=20 all\n```\n\nExample with a 65bit key:\n```\n./kangaroo-256 65.txt\n```\n\n```\n[+] Kangaroo v2.3 [256 CUSTOM edition]\n[+] Start:10000000000000000\n[+] Stop :1FFFFFFFFFFFFFFFF\n[+] Keys :1\n[+] Number of CPU thread: 12\n[+] Range width: 2^64\n[+] Jump Avg distance: 2^31.99\n[+] Number of kangaroos: 2^13.58\n[+] Suggested DP: 15\n[+] Expected operations: 2^33.10\n[+] Expected RAM: 33.4MB\n[+] DP size: 15 [0x0007fff]\n[+] SolveKeyCPU Thread 06: 1024 kangaroos\n[+] SolveKeyCPU Thread 01: 1024 kangaroos\n[+] SolveKeyCPU Thread 04: 1024 kangaroos\n[+] SolveKeyCPU Thread 02: 1024 kangaroos\n[+] SolveKeyCPU Thread 00: 1024 kangaroos\n[+] SolveKeyCPU Thread 09: 1024 kangaroos\n[+] SolveKeyCPU Thread 10: 1024 kangaroos\n[+] SolveKeyCPU Thread 11: 1024 kangaroos\n[+] SolveKeyCPU Thread 03: 1024 kangaroos\n[+] SolveKeyCPU Thread 08: 1024 kangaroos\n[+] SolveKeyCPU Thread 07: 1024 kangaroos\n[+] SolveKeyCPU Thread 05: 1024 kangaroos\n[+] [55.52 MK/s][GPU 0.00 MK/s][Count 2^31.71][Dead 1][01:12 (Avg 02:45)][9.4/22.2MB] \n[+] Done: Total time 01:13 \n\n```\nAll the public address and privatekeys will be saved in the file PrivateKeyFOUND.txt of your current directory.\n\n**Donate to:**\n\n\n**btc: bc1qxs47ttydl8tmdv8vtygp7dy76lvayz3r6rdahu**\n\n\n# Articles\n\n - [1] Using Equivalence Classes to Accelerate Solvingthe Discrete Logarithm Problem in a Short Interval\\\n       https://www.iacr.org/archive/pkc2010/60560372/60560372.pdf\n - [2] Kangaroo Methods for Solving theInterval Discrete Logarithm Problem\\\n       https://arxiv.org/pdf/1501.07019.pdf\n - [3] Factoring and Discrete Logarithms using Pseudorandom Walks\\\n       https://www.math.auckland.ac.nz/~sgal018/crypto-book/ch14.pdf\n - [4] Kangaroos, Monopoly and Discrete Logarithms\\\n       https://web.northeastern.edu/seigen/11Magic/KruskalsCount/PollardKangarooMonopoly.pdf\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcdouglas-x%2Fkangaroo-256-custom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcdouglas-x%2Fkangaroo-256-custom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcdouglas-x%2Fkangaroo-256-custom/lists"}