Restructure and generalize
This commit is contained in:
parent
1ddde97548
commit
a99bd4d91d
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target/
|
26
pom.xml
26
pom.xml
|
@ -3,7 +3,7 @@
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>jmaa</groupId>
|
<groupId>jmaa.pbc</groupId>
|
||||||
<artifactId>pbc-vanity-address</artifactId>
|
<artifactId>pbc-vanity-address</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>4.0.0</version>
|
<version>4.0.0</version>
|
||||||
|
@ -36,8 +36,8 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.partisiablockchain.core</groupId>
|
<groupId>com.partisiablockchain.core</groupId>
|
||||||
<artifactId>blockchain</artifactId>
|
<artifactId>contract</artifactId>
|
||||||
<version>4.74.0</version>
|
<version>4.55.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
@ -46,6 +46,26 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>execute</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals><goal>exec</goal></goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<executable>java</executable>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
|
3
run.sh
Executable file
3
run.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
echo $*
|
||||||
|
mvn compile exec:java -Dexec.mainClass="jmaa.pbc.PbcVanityAddressSearcher" -Dexec.args="$*"
|
77
src/main/java/jmaa/pbc/PbcVanityAddressSearcher.java
Normal file
77
src/main/java/jmaa/pbc/PbcVanityAddressSearcher.java
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
package jmaa.pbc;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import com.partisiablockchain.BlockchainAddress;
|
||||||
|
import com.partisiablockchain.crypto.BlockchainPublicKey;
|
||||||
|
import com.partisiablockchain.crypto.KeyPair;
|
||||||
|
|
||||||
|
/** Search for PBC vanity addresses.
|
||||||
|
*
|
||||||
|
* <p>Based on Jesper Balman Gravgaard's original version.
|
||||||
|
*/
|
||||||
|
public final class PbcVanityAddressSearcher {
|
||||||
|
|
||||||
|
private static final int NUM_THREADS = 8;
|
||||||
|
private static final long MAX_ITERATIONS_PER_THREAD = 100_000_000;
|
||||||
|
private static final long INITIAL_PING_INTERVAL = 10_000;
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
System.out.println("Args: " + List.of(args));
|
||||||
|
searchForPrivateKeyWithVanityAddress(args[0], args[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param vanityPrefix Desired address prefix
|
||||||
|
*/
|
||||||
|
private static void searchForPrivateKeyWithVanityAddress(String vanityPrefix, String vanitySuffix) throws InterruptedException {
|
||||||
|
if (!vanityPrefix.startsWith("00")) {
|
||||||
|
throw new IllegalArgumentException("Vanity prefix must start with 00.");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Searching for private key for address prefix \"%s\" and suffix \"%s\" ".formatted(vanityPrefix, vanitySuffix));
|
||||||
|
|
||||||
|
List<Thread> searchers = new ArrayList<>();
|
||||||
|
for(int threadIdx=0;threadIdx<NUM_THREADS ;threadIdx++) {
|
||||||
|
final Thread searcher = new Thread(new KeySearcher(threadIdx, vanityPrefix, vanitySuffix));
|
||||||
|
searcher.start();
|
||||||
|
searchers.add(searcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Thread searcher : searchers) {
|
||||||
|
searcher.join();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private record KeySearcher(int threadIdx, String vanityPrefix, String vanitySuffix) implements Runnable {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
long start = System.nanoTime();
|
||||||
|
long pingInterval = INITIAL_PING_INTERVAL;
|
||||||
|
for(int iterationIdx=1;iterationIdx<MAX_ITERATIONS_PER_THREAD;iterationIdx++) {
|
||||||
|
// Generate random keypair
|
||||||
|
final KeyPair keyPair = new KeyPair();
|
||||||
|
final BlockchainAddress address = keyPair.getPublic().createAddress();
|
||||||
|
|
||||||
|
// Check vanity
|
||||||
|
final String addressAsString = address.writeAsString();
|
||||||
|
final boolean satisfiesVanity = addressAsString.startsWith(vanityPrefix) && addressAsString.endsWith(vanitySuffix);
|
||||||
|
|
||||||
|
// Output if vain enough
|
||||||
|
if(satisfiesVanity) {
|
||||||
|
System.out.println("[%2d:%10d] match: addr=%s - pk=%s".formatted(threadIdx, iterationIdx, addressAsString, keyPair.getPrivateKey().toString(16)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ping
|
||||||
|
if (iterationIdx % pingInterval == 0) {
|
||||||
|
final long now = System.nanoTime();
|
||||||
|
final long duration = (now - start) / 1_000_000_000;
|
||||||
|
System.out.println("[%2d:%10d] ping at %d sec".formatted(threadIdx, iterationIdx, duration));
|
||||||
|
pingInterval = pingInterval * 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,52 +0,0 @@
|
||||||
package jmaa.pbc;
|
|
||||||
|
|
||||||
/** Search for PBC vanity addresses.
|
|
||||||
*
|
|
||||||
* <p>Based on Jesper Balman Gravgaard's original version.
|
|
||||||
*/
|
|
||||||
public final class PbcVanityAddressSearcher {
|
|
||||||
|
|
||||||
/** The vanity prefix to hunt for. */
|
|
||||||
public static final String VANITY_PREFIX = "00badc0de";
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void randomKeys() throws InterruptedException {
|
|
||||||
List<Thread> searchers = new ArrayList<>();
|
|
||||||
for(int i=0;i<8;i++) {
|
|
||||||
final Thread searcher = new Thread(new KeySearcher(i));
|
|
||||||
searcher.start();
|
|
||||||
searchers.add(searcher);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Thread searcher : searchers) {
|
|
||||||
searcher.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
record KeySearcher(int id) implements Runnable {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
long start = System.nanoTime();
|
|
||||||
for(int i=0;i<100_000_000;i++) {
|
|
||||||
final KeyPair keyPair = new KeyPair();
|
|
||||||
final BlockchainPublicKey publicKey = keyPair.getPublic();
|
|
||||||
final BlockchainAddress address = publicKey.createAddress();
|
|
||||||
if(address.writeAsString().startsWith(VANITY_PREFIX)) {
|
|
||||||
System.out.println("["+id+"] match: "+address.writeAsString()+ " - "+keyPair.getPrivateKey().toString(16));
|
|
||||||
}
|
|
||||||
if (i % 1_000_000 == 0) {
|
|
||||||
final long now = System.nanoTime();
|
|
||||||
final long duration = (now - start) / 1_000_000;
|
|
||||||
System.out.print("["+id+":"+i+"] "+duration+" ");
|
|
||||||
start = now;
|
|
||||||
}
|
|
||||||
if ((id==0) && (i % 1_000_000 == 10_000)) {
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user