├── .cargo └── config.toml ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md └── src └── main.rs /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | rustflags = "-C target-cpu=native" 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | # Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "ansi_term" 7 | version = "0.11.0" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" 10 | dependencies = [ 11 | "winapi", 12 | ] 13 | 14 | [[package]] 15 | name = "atty" 16 | version = "0.2.14" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" 19 | dependencies = [ 20 | "hermit-abi", 21 | "libc", 22 | "winapi", 23 | ] 24 | 25 | [[package]] 26 | name = "bitflags" 27 | version = "1.2.1" 28 | source = "registry+https://github.com/rust-lang/crates.io-index" 29 | checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" 30 | 31 | [[package]] 32 | name = "cfg-if" 33 | version = "0.1.10" 34 | source = "registry+https://github.com/rust-lang/crates.io-index" 35 | checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" 36 | 37 | [[package]] 38 | name = "clap" 39 | version = "2.33.3" 40 | source = "registry+https://github.com/rust-lang/crates.io-index" 41 | checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" 42 | dependencies = [ 43 | "ansi_term", 44 | "atty", 45 | "bitflags", 46 | "strsim", 47 | "textwrap", 48 | "unicode-width", 49 | "vec_map", 50 | ] 51 | 52 | [[package]] 53 | name = "crunchy" 54 | version = "0.2.2" 55 | source = "registry+https://github.com/rust-lang/crates.io-index" 56 | checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" 57 | 58 | [[package]] 59 | name = "getrandom" 60 | version = "0.1.15" 61 | source = "registry+https://github.com/rust-lang/crates.io-index" 62 | checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" 63 | dependencies = [ 64 | "cfg-if", 65 | "libc", 66 | "wasi", 67 | ] 68 | 69 | [[package]] 70 | name = "heck" 71 | version = "0.3.1" 72 | source = "registry+https://github.com/rust-lang/crates.io-index" 73 | checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" 74 | dependencies = [ 75 | "unicode-segmentation", 76 | ] 77 | 78 | [[package]] 79 | name = "hermit-abi" 80 | version = "0.1.17" 81 | source = "registry+https://github.com/rust-lang/crates.io-index" 82 | checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" 83 | dependencies = [ 84 | "libc", 85 | ] 86 | 87 | [[package]] 88 | name = "hex" 89 | version = "0.4.2" 90 | source = "registry+https://github.com/rust-lang/crates.io-index" 91 | checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" 92 | 93 | [[package]] 94 | name = "lazy_static" 95 | version = "1.4.0" 96 | source = "registry+https://github.com/rust-lang/crates.io-index" 97 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 98 | 99 | [[package]] 100 | name = "libc" 101 | version = "0.2.81" 102 | source = "registry+https://github.com/rust-lang/crates.io-index" 103 | checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" 104 | 105 | [[package]] 106 | name = "ppv-lite86" 107 | version = "0.2.10" 108 | source = "registry+https://github.com/rust-lang/crates.io-index" 109 | checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" 110 | 111 | [[package]] 112 | name = "proc-macro-error" 113 | version = "1.0.4" 114 | source = "registry+https://github.com/rust-lang/crates.io-index" 115 | checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" 116 | dependencies = [ 117 | "proc-macro-error-attr", 118 | "proc-macro2", 119 | "quote", 120 | "syn", 121 | "version_check", 122 | ] 123 | 124 | [[package]] 125 | name = "proc-macro-error-attr" 126 | version = "1.0.4" 127 | source = "registry+https://github.com/rust-lang/crates.io-index" 128 | checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" 129 | dependencies = [ 130 | "proc-macro2", 131 | "quote", 132 | "version_check", 133 | ] 134 | 135 | [[package]] 136 | name = "proc-macro2" 137 | version = "1.0.24" 138 | source = "registry+https://github.com/rust-lang/crates.io-index" 139 | checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" 140 | dependencies = [ 141 | "unicode-xid", 142 | ] 143 | 144 | [[package]] 145 | name = "quote" 146 | version = "1.0.7" 147 | source = "registry+https://github.com/rust-lang/crates.io-index" 148 | checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" 149 | dependencies = [ 150 | "proc-macro2", 151 | ] 152 | 153 | [[package]] 154 | name = "rand" 155 | version = "0.7.3" 156 | source = "registry+https://github.com/rust-lang/crates.io-index" 157 | checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" 158 | dependencies = [ 159 | "getrandom", 160 | "libc", 161 | "rand_chacha", 162 | "rand_core", 163 | "rand_hc", 164 | ] 165 | 166 | [[package]] 167 | name = "rand_chacha" 168 | version = "0.2.2" 169 | source = "registry+https://github.com/rust-lang/crates.io-index" 170 | checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" 171 | dependencies = [ 172 | "ppv-lite86", 173 | "rand_core", 174 | ] 175 | 176 | [[package]] 177 | name = "rand_core" 178 | version = "0.5.1" 179 | source = "registry+https://github.com/rust-lang/crates.io-index" 180 | checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" 181 | dependencies = [ 182 | "getrandom", 183 | ] 184 | 185 | [[package]] 186 | name = "rand_hc" 187 | version = "0.2.0" 188 | source = "registry+https://github.com/rust-lang/crates.io-index" 189 | checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" 190 | dependencies = [ 191 | "rand_core", 192 | ] 193 | 194 | [[package]] 195 | name = "solidity-selector-miner" 196 | version = "0.1.0" 197 | dependencies = [ 198 | "hex", 199 | "rand", 200 | "structopt", 201 | "tiny-keccak", 202 | ] 203 | 204 | [[package]] 205 | name = "strsim" 206 | version = "0.8.0" 207 | source = "registry+https://github.com/rust-lang/crates.io-index" 208 | checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" 209 | 210 | [[package]] 211 | name = "structopt" 212 | version = "0.3.21" 213 | source = "registry+https://github.com/rust-lang/crates.io-index" 214 | checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c" 215 | dependencies = [ 216 | "clap", 217 | "lazy_static", 218 | "structopt-derive", 219 | ] 220 | 221 | [[package]] 222 | name = "structopt-derive" 223 | version = "0.4.14" 224 | source = "registry+https://github.com/rust-lang/crates.io-index" 225 | checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90" 226 | dependencies = [ 227 | "heck", 228 | "proc-macro-error", 229 | "proc-macro2", 230 | "quote", 231 | "syn", 232 | ] 233 | 234 | [[package]] 235 | name = "syn" 236 | version = "1.0.54" 237 | source = "registry+https://github.com/rust-lang/crates.io-index" 238 | checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44" 239 | dependencies = [ 240 | "proc-macro2", 241 | "quote", 242 | "unicode-xid", 243 | ] 244 | 245 | [[package]] 246 | name = "textwrap" 247 | version = "0.11.0" 248 | source = "registry+https://github.com/rust-lang/crates.io-index" 249 | checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" 250 | dependencies = [ 251 | "unicode-width", 252 | ] 253 | 254 | [[package]] 255 | name = "tiny-keccak" 256 | version = "2.0.2" 257 | source = "registry+https://github.com/rust-lang/crates.io-index" 258 | checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" 259 | dependencies = [ 260 | "crunchy", 261 | ] 262 | 263 | [[package]] 264 | name = "unicode-segmentation" 265 | version = "1.7.1" 266 | source = "registry+https://github.com/rust-lang/crates.io-index" 267 | checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" 268 | 269 | [[package]] 270 | name = "unicode-width" 271 | version = "0.1.8" 272 | source = "registry+https://github.com/rust-lang/crates.io-index" 273 | checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" 274 | 275 | [[package]] 276 | name = "unicode-xid" 277 | version = "0.2.1" 278 | source = "registry+https://github.com/rust-lang/crates.io-index" 279 | checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" 280 | 281 | [[package]] 282 | name = "vec_map" 283 | version = "0.8.2" 284 | source = "registry+https://github.com/rust-lang/crates.io-index" 285 | checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" 286 | 287 | [[package]] 288 | name = "version_check" 289 | version = "0.9.2" 290 | source = "registry+https://github.com/rust-lang/crates.io-index" 291 | checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" 292 | 293 | [[package]] 294 | name = "wasi" 295 | version = "0.9.0+wasi-snapshot-preview1" 296 | source = "registry+https://github.com/rust-lang/crates.io-index" 297 | checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" 298 | 299 | [[package]] 300 | name = "winapi" 301 | version = "0.3.9" 302 | source = "registry+https://github.com/rust-lang/crates.io-index" 303 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 304 | dependencies = [ 305 | "winapi-i686-pc-windows-gnu", 306 | "winapi-x86_64-pc-windows-gnu", 307 | ] 308 | 309 | [[package]] 310 | name = "winapi-i686-pc-windows-gnu" 311 | version = "0.4.0" 312 | source = "registry+https://github.com/rust-lang/crates.io-index" 313 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 314 | 315 | [[package]] 316 | name = "winapi-x86_64-pc-windows-gnu" 317 | version = "0.4.0" 318 | source = "registry+https://github.com/rust-lang/crates.io-index" 319 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 320 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solidity-selector-miner" 3 | version = "0.1.0" 4 | authors = ["Anton Bukov "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | rand = "0.7.3" 11 | tiny-keccak = { version = "2.0.0", features = ["keccak"] } 12 | structopt = "0.3.21" 13 | hex = "0.4.2" 14 | 15 | [profile.release] 16 | lto = true 17 | codegen-units = 1 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 1inch.exchange 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # solidity-selector-miner 2 | 3 | ### Usage 4 | 5 | ```bash 6 | cargo run --release aabbccdd "(address,uint256)" 8 7 | ``` 8 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use tiny_keccak::{Keccak, Hasher}; 2 | use std::thread; 3 | use std::time::Instant; 4 | use structopt::StructOpt; 5 | 6 | extern crate hex; 7 | 8 | #[derive(StructOpt)] 9 | struct Args { 10 | selector: String, 11 | params: String, 12 | #[structopt(default_value = "1")] 13 | threads: usize, 14 | } 15 | 16 | fn main() { 17 | let args = Args::from_args(); 18 | 19 | let alphabet: [u8; 62] = [ 20 | '0' as u8, '1' as u8, '2' as u8, '3' as u8, '4' as u8, '5' as u8, '6' as u8, '7' as u8, 21 | '8' as u8, '9' as u8, 'a' as u8, 'b' as u8, 'c' as u8, 'd' as u8, 'e' as u8, 'f' as u8, 22 | 'g' as u8, 'h' as u8, 'i' as u8, 'j' as u8, 'k' as u8, 'l' as u8, 'm' as u8, 'n' as u8, 23 | 'o' as u8, 'p' as u8, 'q' as u8, 'r' as u8, 's' as u8, 't' as u8, 'u' as u8, 'v' as u8, 24 | 'w' as u8, 'x' as u8, 'y' as u8, 'z' as u8, 'A' as u8, 'B' as u8, 'C' as u8, 'D' as u8, 25 | 'E' as u8, 'F' as u8, 'G' as u8, 'H' as u8, 'I' as u8, 'J' as u8, 'K' as u8, 'L' as u8, 26 | 'M' as u8, 'N' as u8, 'O' as u8, 'P' as u8, 'Q' as u8, 'R' as u8, 'S' as u8, 'T' as u8, 27 | 'U' as u8, 'V' as u8, 'W' as u8, 'X' as u8, 'Y' as u8, 'Z' as u8, 28 | ]; 29 | 30 | let mut target = [0u8; 4]; 31 | target.copy_from_slice( 32 | &hex::decode(args.selector) 33 | .unwrap() 34 | .drain(0..4) 35 | .collect::>(), 36 | ); 37 | 38 | let params_length = args.params.len(); 39 | let mut params = [[0u8; 32]; 100]; 40 | for i in 0..params_length/32 { 41 | params[i].copy_from_slice(&args.params.as_bytes()[i*32..(i+1)*32]); 42 | } 43 | if params_length % 32 > 0 { 44 | params[params_length/32][0..params_length%32].copy_from_slice( 45 | &args.params.as_bytes()[params_length/32*32..params_length] 46 | ); 47 | } 48 | 49 | let args_threads = args.threads; 50 | let mut handles = vec![]; 51 | for ti in 0..args.threads { 52 | handles.push(Some(thread::spawn(move || { 53 | let mut index = 0; 54 | let mut reported_index = 0; 55 | let mut last = Instant::now(); 56 | let first = last; 57 | 58 | for i1 in 0..alphabet.len() { 59 | for i2 in 0..alphabet.len() { 60 | for i3 in 0..alphabet.len() { 61 | for i4 in 0..alphabet.len() { 62 | for i5 in 0..alphabet.len() { 63 | for i6 in 0..alphabet.len() { 64 | index += 1; 65 | let ms = last.elapsed().as_millis() as u64; 66 | if ms > 3000 { 67 | println!( 68 | "Thread #{:x}: iteration {}M ({} MH/s)\r", 69 | ti, 70 | (index / 1000) as f64 / 1000.0, 71 | ((index - reported_index) / (1 + ms)) as f64 / 1000.0 72 | ); 73 | last = Instant::now(); 74 | reported_index = index 75 | } 76 | 77 | let mut hasher = Keccak::v256(); 78 | hasher.update(&[ 79 | 'f' as u8, 80 | 'u' as u8, 81 | 'n' as u8, 82 | 'c' as u8, 83 | '_' as u8, 84 | alphabet[ti], 85 | alphabet[i1], 86 | alphabet[i2], 87 | alphabet[i3], 88 | alphabet[i4], 89 | alphabet[i5], 90 | alphabet[i6], 91 | ]); 92 | for i in 0..params_length/32 { 93 | hasher.update(¶ms[i]); 94 | } 95 | for i in 0..params_length%32 { 96 | hasher.update(&[params[params_length/32][i]]); 97 | } 98 | 99 | let mut res = [0u8; 4]; 100 | hasher.finalize(&mut res); 101 | if &res[0..4] == &target[0..4] { 102 | println!( 103 | "Found signature func_{} in {} seconds after {}M iterations", 104 | String::from_utf8(vec![ 105 | alphabet[ti], 106 | alphabet[i1], 107 | alphabet[i2], 108 | alphabet[i3], 109 | alphabet[i4], 110 | alphabet[i5], 111 | alphabet[i6], 112 | ]) 113 | .unwrap(), 114 | first.elapsed().as_secs(), 115 | (index * args_threads as u64 / 1000) as f64 / 1000.0 116 | ); 117 | std::process::exit(0); 118 | } 119 | } 120 | } 121 | } 122 | } 123 | } 124 | } 125 | }))); 126 | } 127 | 128 | for i in 0..handles.len() { 129 | handles[i].take().map(std::thread::JoinHandle::join); 130 | } 131 | } 132 | --------------------------------------------------------------------------------