├── .gitignore ├── .vscode └── settings.json ├── Cargo.lock ├── Cargo.toml ├── darkforest ├── Cargo.toml ├── build.rs ├── examples │ └── standalone.rs └── src │ ├── explorers.rs │ └── lib.rs ├── mimc-fast ├── Cargo.toml ├── readme.md └── src │ └── main.rs ├── mimc ├── Cargo.toml ├── README.md └── src │ └── lib.rs └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | cache -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.watcherExclude": { 3 | "**/.git/objects/**": true, 4 | "**/.git/subtree-cache/**": true, 5 | "**/target/**": true 6 | } 7 | } -------------------------------------------------------------------------------- /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 = "aho-corasick" 7 | version = "0.7.15" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" 10 | dependencies = [ 11 | "memchr", 12 | ] 13 | 14 | [[package]] 15 | name = "arrayvec" 16 | version = "0.7.0" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "5a2f58b0bb10c380af2b26e57212856b8c9a59e0925b4c20f4a174a49734eaf7" 19 | 20 | [[package]] 21 | name = "atty" 22 | version = "0.2.14" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" 25 | dependencies = [ 26 | "hermit-abi", 27 | "libc", 28 | "winapi", 29 | ] 30 | 31 | [[package]] 32 | name = "autocfg" 33 | version = "1.0.1" 34 | source = "registry+https://github.com/rust-lang/crates.io-index" 35 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" 36 | 37 | [[package]] 38 | name = "base64" 39 | version = "0.13.0" 40 | source = "registry+https://github.com/rust-lang/crates.io-index" 41 | checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" 42 | 43 | [[package]] 44 | name = "bitflags" 45 | version = "1.2.1" 46 | source = "registry+https://github.com/rust-lang/crates.io-index" 47 | checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" 48 | 49 | [[package]] 50 | name = "bitvec" 51 | version = "0.20.2" 52 | source = "registry+https://github.com/rust-lang/crates.io-index" 53 | checksum = "1f682656975d3a682daff957be4ddeb65d6ad656737cd821f2d00685ae466af1" 54 | dependencies = [ 55 | "funty", 56 | "radium", 57 | "tap", 58 | "wyz", 59 | ] 60 | 61 | [[package]] 62 | name = "block-buffer" 63 | version = "0.9.0" 64 | source = "registry+https://github.com/rust-lang/crates.io-index" 65 | checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" 66 | dependencies = [ 67 | "generic-array", 68 | ] 69 | 70 | [[package]] 71 | name = "byte-slice-cast" 72 | version = "1.0.0" 73 | source = "registry+https://github.com/rust-lang/crates.io-index" 74 | checksum = "65c1bf4a04a88c54f589125563643d773f3254b5c38571395e2b591c693bbc81" 75 | 76 | [[package]] 77 | name = "byteorder" 78 | version = "1.4.3" 79 | source = "registry+https://github.com/rust-lang/crates.io-index" 80 | checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" 81 | 82 | [[package]] 83 | name = "bytes" 84 | version = "1.0.1" 85 | source = "registry+https://github.com/rust-lang/crates.io-index" 86 | checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" 87 | 88 | [[package]] 89 | name = "cfg-if" 90 | version = "1.0.0" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 93 | 94 | [[package]] 95 | name = "cpufeatures" 96 | version = "0.1.1" 97 | source = "registry+https://github.com/rust-lang/crates.io-index" 98 | checksum = "dec1028182c380cc45a2e2c5ec841134f2dfd0f8f5f0a5bcd68004f81b5efdf4" 99 | dependencies = [ 100 | "libc", 101 | ] 102 | 103 | [[package]] 104 | name = "crossbeam-channel" 105 | version = "0.5.0" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" 108 | dependencies = [ 109 | "cfg-if", 110 | "crossbeam-utils", 111 | ] 112 | 113 | [[package]] 114 | name = "crossbeam-deque" 115 | version = "0.8.0" 116 | source = "registry+https://github.com/rust-lang/crates.io-index" 117 | checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9" 118 | dependencies = [ 119 | "cfg-if", 120 | "crossbeam-epoch", 121 | "crossbeam-utils", 122 | ] 123 | 124 | [[package]] 125 | name = "crossbeam-epoch" 126 | version = "0.9.3" 127 | source = "registry+https://github.com/rust-lang/crates.io-index" 128 | checksum = "2584f639eb95fea8c798496315b297cf81b9b58b6d30ab066a75455333cf4b12" 129 | dependencies = [ 130 | "cfg-if", 131 | "crossbeam-utils", 132 | "lazy_static", 133 | "memoffset", 134 | "scopeguard", 135 | ] 136 | 137 | [[package]] 138 | name = "crossbeam-utils" 139 | version = "0.8.3" 140 | source = "registry+https://github.com/rust-lang/crates.io-index" 141 | checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49" 142 | dependencies = [ 143 | "autocfg", 144 | "cfg-if", 145 | "lazy_static", 146 | ] 147 | 148 | [[package]] 149 | name = "crunchy" 150 | version = "0.2.2" 151 | source = "registry+https://github.com/rust-lang/crates.io-index" 152 | checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" 153 | 154 | [[package]] 155 | name = "darkforest" 156 | version = "0.1.0" 157 | dependencies = [ 158 | "itertools", 159 | "lazy_static", 160 | "mimc", 161 | "rayon", 162 | "serde", 163 | ] 164 | 165 | [[package]] 166 | name = "digest" 167 | version = "0.9.0" 168 | source = "registry+https://github.com/rust-lang/crates.io-index" 169 | checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" 170 | dependencies = [ 171 | "generic-array", 172 | ] 173 | 174 | [[package]] 175 | name = "either" 176 | version = "1.6.1" 177 | source = "registry+https://github.com/rust-lang/crates.io-index" 178 | checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" 179 | 180 | [[package]] 181 | name = "env_logger" 182 | version = "0.7.1" 183 | source = "registry+https://github.com/rust-lang/crates.io-index" 184 | checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" 185 | dependencies = [ 186 | "atty", 187 | "humantime", 188 | "log", 189 | "regex", 190 | "termcolor", 191 | ] 192 | 193 | [[package]] 194 | name = "fixed-hash" 195 | version = "0.7.0" 196 | source = "registry+https://github.com/rust-lang/crates.io-index" 197 | checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" 198 | dependencies = [ 199 | "byteorder", 200 | "rand", 201 | "rustc-hex", 202 | "static_assertions", 203 | ] 204 | 205 | [[package]] 206 | name = "fnv" 207 | version = "1.0.7" 208 | source = "registry+https://github.com/rust-lang/crates.io-index" 209 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 210 | 211 | [[package]] 212 | name = "form_urlencoded" 213 | version = "1.0.1" 214 | source = "registry+https://github.com/rust-lang/crates.io-index" 215 | checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" 216 | dependencies = [ 217 | "matches", 218 | "percent-encoding", 219 | ] 220 | 221 | [[package]] 222 | name = "funty" 223 | version = "1.1.0" 224 | source = "registry+https://github.com/rust-lang/crates.io-index" 225 | checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" 226 | 227 | [[package]] 228 | name = "futures" 229 | version = "0.3.13" 230 | source = "registry+https://github.com/rust-lang/crates.io-index" 231 | checksum = "7f55667319111d593ba876406af7c409c0ebb44dc4be6132a783ccf163ea14c1" 232 | dependencies = [ 233 | "futures-channel", 234 | "futures-core", 235 | "futures-io", 236 | "futures-sink", 237 | "futures-task", 238 | "futures-util", 239 | ] 240 | 241 | [[package]] 242 | name = "futures-channel" 243 | version = "0.3.13" 244 | source = "registry+https://github.com/rust-lang/crates.io-index" 245 | checksum = "8c2dd2df839b57db9ab69c2c9d8f3e8c81984781937fe2807dc6dcf3b2ad2939" 246 | dependencies = [ 247 | "futures-core", 248 | "futures-sink", 249 | ] 250 | 251 | [[package]] 252 | name = "futures-core" 253 | version = "0.3.13" 254 | source = "registry+https://github.com/rust-lang/crates.io-index" 255 | checksum = "15496a72fabf0e62bdc3df11a59a3787429221dd0710ba8ef163d6f7a9112c94" 256 | 257 | [[package]] 258 | name = "futures-io" 259 | version = "0.3.13" 260 | source = "registry+https://github.com/rust-lang/crates.io-index" 261 | checksum = "d71c2c65c57704c32f5241c1223167c2c3294fd34ac020c807ddbe6db287ba59" 262 | 263 | [[package]] 264 | name = "futures-sink" 265 | version = "0.3.13" 266 | source = "registry+https://github.com/rust-lang/crates.io-index" 267 | checksum = "85754d98985841b7d4f5e8e6fbfa4a4ac847916893ec511a2917ccd8525b8bb3" 268 | 269 | [[package]] 270 | name = "futures-task" 271 | version = "0.3.13" 272 | source = "registry+https://github.com/rust-lang/crates.io-index" 273 | checksum = "fa189ef211c15ee602667a6fcfe1c1fd9e07d42250d2156382820fba33c9df80" 274 | 275 | [[package]] 276 | name = "futures-util" 277 | version = "0.3.13" 278 | source = "registry+https://github.com/rust-lang/crates.io-index" 279 | checksum = "1812c7ab8aedf8d6f2701a43e1243acdbcc2b36ab26e2ad421eb99ac963d96d1" 280 | dependencies = [ 281 | "futures-core", 282 | "futures-sink", 283 | "futures-task", 284 | "pin-project-lite", 285 | "pin-utils", 286 | ] 287 | 288 | [[package]] 289 | name = "generic-array" 290 | version = "0.14.4" 291 | source = "registry+https://github.com/rust-lang/crates.io-index" 292 | checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" 293 | dependencies = [ 294 | "typenum", 295 | "version_check", 296 | ] 297 | 298 | [[package]] 299 | name = "getrandom" 300 | version = "0.2.2" 301 | source = "registry+https://github.com/rust-lang/crates.io-index" 302 | checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" 303 | dependencies = [ 304 | "cfg-if", 305 | "libc", 306 | "wasi", 307 | ] 308 | 309 | [[package]] 310 | name = "h2" 311 | version = "0.3.3" 312 | source = "registry+https://github.com/rust-lang/crates.io-index" 313 | checksum = "825343c4eef0b63f541f8903f395dc5beb362a979b5799a84062527ef1e37726" 314 | dependencies = [ 315 | "bytes", 316 | "fnv", 317 | "futures-core", 318 | "futures-sink", 319 | "futures-util", 320 | "http", 321 | "indexmap", 322 | "slab", 323 | "tokio", 324 | "tokio-util", 325 | "tracing", 326 | ] 327 | 328 | [[package]] 329 | name = "hashbrown" 330 | version = "0.9.1" 331 | source = "registry+https://github.com/rust-lang/crates.io-index" 332 | checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" 333 | 334 | [[package]] 335 | name = "headers" 336 | version = "0.3.4" 337 | source = "registry+https://github.com/rust-lang/crates.io-index" 338 | checksum = "f0b7591fb62902706ae8e7aaff416b1b0fa2c0fd0878b46dc13baa3712d8a855" 339 | dependencies = [ 340 | "base64", 341 | "bitflags", 342 | "bytes", 343 | "headers-core", 344 | "http", 345 | "mime", 346 | "sha-1", 347 | "time", 348 | ] 349 | 350 | [[package]] 351 | name = "headers-core" 352 | version = "0.2.0" 353 | source = "registry+https://github.com/rust-lang/crates.io-index" 354 | checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" 355 | dependencies = [ 356 | "http", 357 | ] 358 | 359 | [[package]] 360 | name = "hermit-abi" 361 | version = "0.1.18" 362 | source = "registry+https://github.com/rust-lang/crates.io-index" 363 | checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" 364 | dependencies = [ 365 | "libc", 366 | ] 367 | 368 | [[package]] 369 | name = "hex" 370 | version = "0.4.3" 371 | source = "registry+https://github.com/rust-lang/crates.io-index" 372 | checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" 373 | 374 | [[package]] 375 | name = "http" 376 | version = "0.2.4" 377 | source = "registry+https://github.com/rust-lang/crates.io-index" 378 | checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" 379 | dependencies = [ 380 | "bytes", 381 | "fnv", 382 | "itoa", 383 | ] 384 | 385 | [[package]] 386 | name = "http-body" 387 | version = "0.4.2" 388 | source = "registry+https://github.com/rust-lang/crates.io-index" 389 | checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" 390 | dependencies = [ 391 | "bytes", 392 | "http", 393 | "pin-project-lite", 394 | ] 395 | 396 | [[package]] 397 | name = "httparse" 398 | version = "1.3.5" 399 | source = "registry+https://github.com/rust-lang/crates.io-index" 400 | checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691" 401 | 402 | [[package]] 403 | name = "httpdate" 404 | version = "0.3.2" 405 | source = "registry+https://github.com/rust-lang/crates.io-index" 406 | checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" 407 | 408 | [[package]] 409 | name = "humantime" 410 | version = "1.3.0" 411 | source = "registry+https://github.com/rust-lang/crates.io-index" 412 | checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" 413 | dependencies = [ 414 | "quick-error", 415 | ] 416 | 417 | [[package]] 418 | name = "hyper" 419 | version = "0.14.5" 420 | source = "registry+https://github.com/rust-lang/crates.io-index" 421 | checksum = "8bf09f61b52cfcf4c00de50df88ae423d6c02354e385a86341133b5338630ad1" 422 | dependencies = [ 423 | "bytes", 424 | "futures-channel", 425 | "futures-core", 426 | "futures-util", 427 | "h2", 428 | "http", 429 | "http-body", 430 | "httparse", 431 | "httpdate", 432 | "itoa", 433 | "pin-project", 434 | "socket2", 435 | "tokio", 436 | "tower-service", 437 | "tracing", 438 | "want", 439 | ] 440 | 441 | [[package]] 442 | name = "impl-codec" 443 | version = "0.5.0" 444 | source = "registry+https://github.com/rust-lang/crates.io-index" 445 | checksum = "df170efa359aebdd5cb7fe78edcc67107748e4737bdca8a8fb40d15ea7a877ed" 446 | dependencies = [ 447 | "parity-scale-codec", 448 | ] 449 | 450 | [[package]] 451 | name = "indexmap" 452 | version = "1.6.2" 453 | source = "registry+https://github.com/rust-lang/crates.io-index" 454 | checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" 455 | dependencies = [ 456 | "autocfg", 457 | "hashbrown", 458 | ] 459 | 460 | [[package]] 461 | name = "itertools" 462 | version = "0.10.0" 463 | source = "registry+https://github.com/rust-lang/crates.io-index" 464 | checksum = "37d572918e350e82412fe766d24b15e6682fb2ed2bbe018280caa810397cb319" 465 | dependencies = [ 466 | "either", 467 | ] 468 | 469 | [[package]] 470 | name = "itoa" 471 | version = "0.4.7" 472 | source = "registry+https://github.com/rust-lang/crates.io-index" 473 | checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" 474 | 475 | [[package]] 476 | name = "lazy_static" 477 | version = "1.4.0" 478 | source = "registry+https://github.com/rust-lang/crates.io-index" 479 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 480 | 481 | [[package]] 482 | name = "libc" 483 | version = "0.2.88" 484 | source = "registry+https://github.com/rust-lang/crates.io-index" 485 | checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a" 486 | 487 | [[package]] 488 | name = "log" 489 | version = "0.4.14" 490 | source = "registry+https://github.com/rust-lang/crates.io-index" 491 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" 492 | dependencies = [ 493 | "cfg-if", 494 | ] 495 | 496 | [[package]] 497 | name = "matches" 498 | version = "0.1.8" 499 | source = "registry+https://github.com/rust-lang/crates.io-index" 500 | checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" 501 | 502 | [[package]] 503 | name = "memchr" 504 | version = "2.3.4" 505 | source = "registry+https://github.com/rust-lang/crates.io-index" 506 | checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" 507 | 508 | [[package]] 509 | name = "memoffset" 510 | version = "0.6.3" 511 | source = "registry+https://github.com/rust-lang/crates.io-index" 512 | checksum = "f83fb6581e8ed1f85fd45c116db8405483899489e38406156c25eb743554361d" 513 | dependencies = [ 514 | "autocfg", 515 | ] 516 | 517 | [[package]] 518 | name = "mimc" 519 | version = "0.1.0" 520 | dependencies = [ 521 | "primitive-types", 522 | ] 523 | 524 | [[package]] 525 | name = "mimc-fast" 526 | version = "0.1.0" 527 | dependencies = [ 528 | "darkforest", 529 | "itertools", 530 | "pretty_env_logger", 531 | "rayon", 532 | "serde", 533 | "tokio", 534 | "warp", 535 | ] 536 | 537 | [[package]] 538 | name = "mime" 539 | version = "0.3.16" 540 | source = "registry+https://github.com/rust-lang/crates.io-index" 541 | checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" 542 | 543 | [[package]] 544 | name = "mime_guess" 545 | version = "2.0.3" 546 | source = "registry+https://github.com/rust-lang/crates.io-index" 547 | checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" 548 | dependencies = [ 549 | "mime", 550 | "unicase", 551 | ] 552 | 553 | [[package]] 554 | name = "mio" 555 | version = "0.7.11" 556 | source = "registry+https://github.com/rust-lang/crates.io-index" 557 | checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" 558 | dependencies = [ 559 | "libc", 560 | "log", 561 | "miow", 562 | "ntapi", 563 | "winapi", 564 | ] 565 | 566 | [[package]] 567 | name = "miow" 568 | version = "0.3.7" 569 | source = "registry+https://github.com/rust-lang/crates.io-index" 570 | checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" 571 | dependencies = [ 572 | "winapi", 573 | ] 574 | 575 | [[package]] 576 | name = "ntapi" 577 | version = "0.3.6" 578 | source = "registry+https://github.com/rust-lang/crates.io-index" 579 | checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" 580 | dependencies = [ 581 | "winapi", 582 | ] 583 | 584 | [[package]] 585 | name = "num_cpus" 586 | version = "1.13.0" 587 | source = "registry+https://github.com/rust-lang/crates.io-index" 588 | checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" 589 | dependencies = [ 590 | "hermit-abi", 591 | "libc", 592 | ] 593 | 594 | [[package]] 595 | name = "opaque-debug" 596 | version = "0.3.0" 597 | source = "registry+https://github.com/rust-lang/crates.io-index" 598 | checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" 599 | 600 | [[package]] 601 | name = "parity-scale-codec" 602 | version = "2.1.1" 603 | source = "registry+https://github.com/rust-lang/crates.io-index" 604 | checksum = "e0f518afaa5a47d0d6386229b0a6e01e86427291d643aa4cabb4992219f504f8" 605 | dependencies = [ 606 | "arrayvec", 607 | "bitvec", 608 | "byte-slice-cast", 609 | "serde", 610 | ] 611 | 612 | [[package]] 613 | name = "percent-encoding" 614 | version = "2.1.0" 615 | source = "registry+https://github.com/rust-lang/crates.io-index" 616 | checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" 617 | 618 | [[package]] 619 | name = "pin-project" 620 | version = "1.0.6" 621 | source = "registry+https://github.com/rust-lang/crates.io-index" 622 | checksum = "bc174859768806e91ae575187ada95c91a29e96a98dc5d2cd9a1fed039501ba6" 623 | dependencies = [ 624 | "pin-project-internal", 625 | ] 626 | 627 | [[package]] 628 | name = "pin-project-internal" 629 | version = "1.0.6" 630 | source = "registry+https://github.com/rust-lang/crates.io-index" 631 | checksum = "a490329918e856ed1b083f244e3bfe2d8c4f336407e4ea9e1a9f479ff09049e5" 632 | dependencies = [ 633 | "proc-macro2", 634 | "quote", 635 | "syn", 636 | ] 637 | 638 | [[package]] 639 | name = "pin-project-lite" 640 | version = "0.2.6" 641 | source = "registry+https://github.com/rust-lang/crates.io-index" 642 | checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" 643 | 644 | [[package]] 645 | name = "pin-utils" 646 | version = "0.1.0" 647 | source = "registry+https://github.com/rust-lang/crates.io-index" 648 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 649 | 650 | [[package]] 651 | name = "ppv-lite86" 652 | version = "0.2.10" 653 | source = "registry+https://github.com/rust-lang/crates.io-index" 654 | checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" 655 | 656 | [[package]] 657 | name = "pretty_env_logger" 658 | version = "0.4.0" 659 | source = "registry+https://github.com/rust-lang/crates.io-index" 660 | checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" 661 | dependencies = [ 662 | "env_logger", 663 | "log", 664 | ] 665 | 666 | [[package]] 667 | name = "primitive-types" 668 | version = "0.9.0" 669 | source = "registry+https://github.com/rust-lang/crates.io-index" 670 | checksum = "2415937401cb030a2a0a4d922483f945fa068f52a7dbb22ce0fe5f2b6f6adace" 671 | dependencies = [ 672 | "fixed-hash", 673 | "impl-codec", 674 | "uint", 675 | ] 676 | 677 | [[package]] 678 | name = "proc-macro2" 679 | version = "1.0.24" 680 | source = "registry+https://github.com/rust-lang/crates.io-index" 681 | checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" 682 | dependencies = [ 683 | "unicode-xid", 684 | ] 685 | 686 | [[package]] 687 | name = "quick-error" 688 | version = "1.2.3" 689 | source = "registry+https://github.com/rust-lang/crates.io-index" 690 | checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" 691 | 692 | [[package]] 693 | name = "quote" 694 | version = "1.0.9" 695 | source = "registry+https://github.com/rust-lang/crates.io-index" 696 | checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" 697 | dependencies = [ 698 | "proc-macro2", 699 | ] 700 | 701 | [[package]] 702 | name = "radium" 703 | version = "0.6.2" 704 | source = "registry+https://github.com/rust-lang/crates.io-index" 705 | checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb" 706 | 707 | [[package]] 708 | name = "rand" 709 | version = "0.8.3" 710 | source = "registry+https://github.com/rust-lang/crates.io-index" 711 | checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" 712 | dependencies = [ 713 | "libc", 714 | "rand_chacha", 715 | "rand_core", 716 | ] 717 | 718 | [[package]] 719 | name = "rand_chacha" 720 | version = "0.3.0" 721 | source = "registry+https://github.com/rust-lang/crates.io-index" 722 | checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" 723 | dependencies = [ 724 | "ppv-lite86", 725 | "rand_core", 726 | ] 727 | 728 | [[package]] 729 | name = "rand_core" 730 | version = "0.6.2" 731 | source = "registry+https://github.com/rust-lang/crates.io-index" 732 | checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" 733 | dependencies = [ 734 | "getrandom", 735 | ] 736 | 737 | [[package]] 738 | name = "rayon" 739 | version = "1.5.0" 740 | source = "registry+https://github.com/rust-lang/crates.io-index" 741 | checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674" 742 | dependencies = [ 743 | "autocfg", 744 | "crossbeam-deque", 745 | "either", 746 | "rayon-core", 747 | ] 748 | 749 | [[package]] 750 | name = "rayon-core" 751 | version = "1.9.0" 752 | source = "registry+https://github.com/rust-lang/crates.io-index" 753 | checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" 754 | dependencies = [ 755 | "crossbeam-channel", 756 | "crossbeam-deque", 757 | "crossbeam-utils", 758 | "lazy_static", 759 | "num_cpus", 760 | ] 761 | 762 | [[package]] 763 | name = "regex" 764 | version = "1.4.6" 765 | source = "registry+https://github.com/rust-lang/crates.io-index" 766 | checksum = "2a26af418b574bd56588335b3a3659a65725d4e636eb1016c2f9e3b38c7cc759" 767 | dependencies = [ 768 | "aho-corasick", 769 | "memchr", 770 | "regex-syntax", 771 | ] 772 | 773 | [[package]] 774 | name = "regex-syntax" 775 | version = "0.6.25" 776 | source = "registry+https://github.com/rust-lang/crates.io-index" 777 | checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" 778 | 779 | [[package]] 780 | name = "rustc-hex" 781 | version = "2.1.0" 782 | source = "registry+https://github.com/rust-lang/crates.io-index" 783 | checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" 784 | 785 | [[package]] 786 | name = "ryu" 787 | version = "1.0.5" 788 | source = "registry+https://github.com/rust-lang/crates.io-index" 789 | checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" 790 | 791 | [[package]] 792 | name = "scoped-tls" 793 | version = "1.0.0" 794 | source = "registry+https://github.com/rust-lang/crates.io-index" 795 | checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" 796 | 797 | [[package]] 798 | name = "scopeguard" 799 | version = "1.1.0" 800 | source = "registry+https://github.com/rust-lang/crates.io-index" 801 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" 802 | 803 | [[package]] 804 | name = "serde" 805 | version = "1.0.124" 806 | source = "registry+https://github.com/rust-lang/crates.io-index" 807 | checksum = "bd761ff957cb2a45fbb9ab3da6512de9de55872866160b23c25f1a841e99d29f" 808 | dependencies = [ 809 | "serde_derive", 810 | ] 811 | 812 | [[package]] 813 | name = "serde_derive" 814 | version = "1.0.124" 815 | source = "registry+https://github.com/rust-lang/crates.io-index" 816 | checksum = "1800f7693e94e186f5e25a28291ae1570da908aff7d97a095dec1e56ff99069b" 817 | dependencies = [ 818 | "proc-macro2", 819 | "quote", 820 | "syn", 821 | ] 822 | 823 | [[package]] 824 | name = "serde_json" 825 | version = "1.0.64" 826 | source = "registry+https://github.com/rust-lang/crates.io-index" 827 | checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" 828 | dependencies = [ 829 | "itoa", 830 | "ryu", 831 | "serde", 832 | ] 833 | 834 | [[package]] 835 | name = "serde_urlencoded" 836 | version = "0.7.0" 837 | source = "registry+https://github.com/rust-lang/crates.io-index" 838 | checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" 839 | dependencies = [ 840 | "form_urlencoded", 841 | "itoa", 842 | "ryu", 843 | "serde", 844 | ] 845 | 846 | [[package]] 847 | name = "sha-1" 848 | version = "0.9.6" 849 | source = "registry+https://github.com/rust-lang/crates.io-index" 850 | checksum = "8c4cfa741c5832d0ef7fab46cabed29c2aae926db0b11bb2069edd8db5e64e16" 851 | dependencies = [ 852 | "block-buffer", 853 | "cfg-if", 854 | "cpufeatures", 855 | "digest", 856 | "opaque-debug", 857 | ] 858 | 859 | [[package]] 860 | name = "slab" 861 | version = "0.4.2" 862 | source = "registry+https://github.com/rust-lang/crates.io-index" 863 | checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" 864 | 865 | [[package]] 866 | name = "socket2" 867 | version = "0.4.0" 868 | source = "registry+https://github.com/rust-lang/crates.io-index" 869 | checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" 870 | dependencies = [ 871 | "libc", 872 | "winapi", 873 | ] 874 | 875 | [[package]] 876 | name = "static_assertions" 877 | version = "1.1.0" 878 | source = "registry+https://github.com/rust-lang/crates.io-index" 879 | checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" 880 | 881 | [[package]] 882 | name = "syn" 883 | version = "1.0.63" 884 | source = "registry+https://github.com/rust-lang/crates.io-index" 885 | checksum = "8fd9bc7ccc2688b3344c2f48b9b546648b25ce0b20fc717ee7fa7981a8ca9717" 886 | dependencies = [ 887 | "proc-macro2", 888 | "quote", 889 | "unicode-xid", 890 | ] 891 | 892 | [[package]] 893 | name = "tap" 894 | version = "1.0.1" 895 | source = "registry+https://github.com/rust-lang/crates.io-index" 896 | checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" 897 | 898 | [[package]] 899 | name = "termcolor" 900 | version = "1.1.2" 901 | source = "registry+https://github.com/rust-lang/crates.io-index" 902 | checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" 903 | dependencies = [ 904 | "winapi-util", 905 | ] 906 | 907 | [[package]] 908 | name = "time" 909 | version = "0.1.43" 910 | source = "registry+https://github.com/rust-lang/crates.io-index" 911 | checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" 912 | dependencies = [ 913 | "libc", 914 | "winapi", 915 | ] 916 | 917 | [[package]] 918 | name = "tokio" 919 | version = "1.5.0" 920 | source = "registry+https://github.com/rust-lang/crates.io-index" 921 | checksum = "83f0c8e7c0addab50b663055baf787d0af7f413a46e6e7fb9559a4e4db7137a5" 922 | dependencies = [ 923 | "autocfg", 924 | "bytes", 925 | "libc", 926 | "memchr", 927 | "mio", 928 | "num_cpus", 929 | "pin-project-lite", 930 | "tokio-macros", 931 | ] 932 | 933 | [[package]] 934 | name = "tokio-macros" 935 | version = "1.1.0" 936 | source = "registry+https://github.com/rust-lang/crates.io-index" 937 | checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" 938 | dependencies = [ 939 | "proc-macro2", 940 | "quote", 941 | "syn", 942 | ] 943 | 944 | [[package]] 945 | name = "tokio-stream" 946 | version = "0.1.5" 947 | source = "registry+https://github.com/rust-lang/crates.io-index" 948 | checksum = "e177a5d8c3bf36de9ebe6d58537d8879e964332f93fb3339e43f618c81361af0" 949 | dependencies = [ 950 | "futures-core", 951 | "pin-project-lite", 952 | "tokio", 953 | ] 954 | 955 | [[package]] 956 | name = "tokio-util" 957 | version = "0.6.6" 958 | source = "registry+https://github.com/rust-lang/crates.io-index" 959 | checksum = "940a12c99365c31ea8dd9ba04ec1be183ffe4920102bb7122c2f515437601e8e" 960 | dependencies = [ 961 | "bytes", 962 | "futures-core", 963 | "futures-sink", 964 | "log", 965 | "pin-project-lite", 966 | "tokio", 967 | ] 968 | 969 | [[package]] 970 | name = "tower-service" 971 | version = "0.3.1" 972 | source = "registry+https://github.com/rust-lang/crates.io-index" 973 | checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" 974 | 975 | [[package]] 976 | name = "tracing" 977 | version = "0.1.26" 978 | source = "registry+https://github.com/rust-lang/crates.io-index" 979 | checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" 980 | dependencies = [ 981 | "cfg-if", 982 | "log", 983 | "pin-project-lite", 984 | "tracing-core", 985 | ] 986 | 987 | [[package]] 988 | name = "tracing-core" 989 | version = "0.1.18" 990 | source = "registry+https://github.com/rust-lang/crates.io-index" 991 | checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052" 992 | dependencies = [ 993 | "lazy_static", 994 | ] 995 | 996 | [[package]] 997 | name = "try-lock" 998 | version = "0.2.3" 999 | source = "registry+https://github.com/rust-lang/crates.io-index" 1000 | checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" 1001 | 1002 | [[package]] 1003 | name = "typenum" 1004 | version = "1.12.0" 1005 | source = "registry+https://github.com/rust-lang/crates.io-index" 1006 | checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" 1007 | 1008 | [[package]] 1009 | name = "uint" 1010 | version = "0.9.0" 1011 | source = "registry+https://github.com/rust-lang/crates.io-index" 1012 | checksum = "e11fe9a9348741cf134085ad57c249508345fe16411b3d7fb4ff2da2f1d6382e" 1013 | dependencies = [ 1014 | "byteorder", 1015 | "crunchy", 1016 | "hex", 1017 | "static_assertions", 1018 | ] 1019 | 1020 | [[package]] 1021 | name = "unicase" 1022 | version = "2.6.0" 1023 | source = "registry+https://github.com/rust-lang/crates.io-index" 1024 | checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" 1025 | dependencies = [ 1026 | "version_check", 1027 | ] 1028 | 1029 | [[package]] 1030 | name = "unicode-xid" 1031 | version = "0.2.1" 1032 | source = "registry+https://github.com/rust-lang/crates.io-index" 1033 | checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" 1034 | 1035 | [[package]] 1036 | name = "version_check" 1037 | version = "0.9.2" 1038 | source = "registry+https://github.com/rust-lang/crates.io-index" 1039 | checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" 1040 | 1041 | [[package]] 1042 | name = "want" 1043 | version = "0.3.0" 1044 | source = "registry+https://github.com/rust-lang/crates.io-index" 1045 | checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" 1046 | dependencies = [ 1047 | "log", 1048 | "try-lock", 1049 | ] 1050 | 1051 | [[package]] 1052 | name = "warp" 1053 | version = "0.3.1" 1054 | source = "registry+https://github.com/rust-lang/crates.io-index" 1055 | checksum = "332d47745e9a0c38636dbd454729b147d16bd1ed08ae67b3ab281c4506771054" 1056 | dependencies = [ 1057 | "bytes", 1058 | "futures", 1059 | "headers", 1060 | "http", 1061 | "hyper", 1062 | "log", 1063 | "mime", 1064 | "mime_guess", 1065 | "percent-encoding", 1066 | "pin-project", 1067 | "scoped-tls", 1068 | "serde", 1069 | "serde_json", 1070 | "serde_urlencoded", 1071 | "tokio", 1072 | "tokio-stream", 1073 | "tokio-util", 1074 | "tower-service", 1075 | "tracing", 1076 | ] 1077 | 1078 | [[package]] 1079 | name = "wasi" 1080 | version = "0.10.2+wasi-snapshot-preview1" 1081 | source = "registry+https://github.com/rust-lang/crates.io-index" 1082 | checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" 1083 | 1084 | [[package]] 1085 | name = "winapi" 1086 | version = "0.3.9" 1087 | source = "registry+https://github.com/rust-lang/crates.io-index" 1088 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 1089 | dependencies = [ 1090 | "winapi-i686-pc-windows-gnu", 1091 | "winapi-x86_64-pc-windows-gnu", 1092 | ] 1093 | 1094 | [[package]] 1095 | name = "winapi-i686-pc-windows-gnu" 1096 | version = "0.4.0" 1097 | source = "registry+https://github.com/rust-lang/crates.io-index" 1098 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 1099 | 1100 | [[package]] 1101 | name = "winapi-util" 1102 | version = "0.1.5" 1103 | source = "registry+https://github.com/rust-lang/crates.io-index" 1104 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 1105 | dependencies = [ 1106 | "winapi", 1107 | ] 1108 | 1109 | [[package]] 1110 | name = "winapi-x86_64-pc-windows-gnu" 1111 | version = "0.4.0" 1112 | source = "registry+https://github.com/rust-lang/crates.io-index" 1113 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 1114 | 1115 | [[package]] 1116 | name = "wyz" 1117 | version = "0.2.0" 1118 | source = "registry+https://github.com/rust-lang/crates.io-index" 1119 | checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" 1120 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["mimc", "mimc-fast", "darkforest"] 3 | 4 | # force release mode for dev in case people dont use --release 5 | [profile.dev] 6 | opt-level = 3 7 | debug = false 8 | debug-assertions = false 9 | overflow-checks = false 10 | lto = false 11 | panic = 'unwind' 12 | incremental = false 13 | codegen-units = 16 14 | rpath = false 15 | -------------------------------------------------------------------------------- /darkforest/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "darkforest" 3 | version = "0.1.0" 4 | authors = ["Jacob Rosenthal "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | [dependencies] 9 | mimc = { version = "0.1.0", path = "../mimc" } 10 | serde = { version = "1.0.124", features = ["derive"] } 11 | 12 | [build-dependencies] 13 | lazy_static = "1.4.0" 14 | mimc = { version = "0.1.0", path = "../mimc" } 15 | 16 | [dev-dependencies] 17 | rayon = "1.5.0" 18 | itertools = "0.10.0" 19 | -------------------------------------------------------------------------------- /darkforest/build.rs: -------------------------------------------------------------------------------- 1 | use mimc::{PrimeElem, U512}; 2 | use std::env; 3 | use std::fs; 4 | use std::io::Write; 5 | use std::path::Path; 6 | 7 | lazy_static::lazy_static! { 8 | static ref P: U512 = U512::from_dec_str( 9 | "21888242871839275222246405745257275088548364400416034343698204186575808495617" 10 | ) 11 | .unwrap(); 12 | static ref C: Vec = { 13 | let consts = vec![ 14 | "0", 15 | "7120861356467848435263064379192047478074060781135320967663101236819528304084", 16 | "5024705281721889198577876690145313457398658950011302225525409148828000436681", 17 | "17980351014018068290387269214713820287804403312720763401943303895585469787384", 18 | "19886576439381707240399940949310933992335779767309383709787331470398675714258", 19 | "1213715278223786725806155661738676903520350859678319590331207960381534602599", 20 | "18162138253399958831050545255414688239130588254891200470934232514682584734511", 21 | "7667462281466170157858259197976388676420847047604921256361474169980037581876", 22 | "7207551498477838452286210989212982851118089401128156132319807392460388436957", 23 | "9864183311657946807255900203841777810810224615118629957816193727554621093838", 24 | "4798196928559910300796064665904583125427459076060519468052008159779219347957", 25 | "17387238494588145257484818061490088963673275521250153686214197573695921400950", 26 | "10005334761930299057035055370088813230849810566234116771751925093634136574742", 27 | "11897542014760736209670863723231849628230383119798486487899539017466261308762", 28 | "16771780563523793011283273687253985566177232886900511371656074413362142152543", 29 | "749264854018824809464168489785113337925400687349357088413132714480582918506", 30 | "3683645737503705042628598550438395339383572464204988015434959428676652575331", 31 | "7556750851783822914673316211129907782679509728346361368978891584375551186255", 32 | "20391289379084797414557439284689954098721219201171527383291525676334308303023", 33 | "18146517657445423462330854383025300323335289319277199154920964274562014376193", 34 | "8080173465267536232534446836148661251987053305394647905212781979099916615292", 35 | "10796443006899450245502071131975731672911747129805343722228413358507805531141", 36 | "5404287610364961067658660283245291234008692303120470305032076412056764726509", 37 | "4623894483395123520243967718315330178025957095502546813929290333264120223168", 38 | "16845753148201777192406958674202574751725237939980634861948953189320362207797", 39 | "4622170486584704769521001011395820886029808520586507873417553166762370293671", 40 | "16688277490485052681847773549197928630624828392248424077804829676011512392564", 41 | "11878652861183667748838188993669912629573713271883125458838494308957689090959", 42 | "2436445725746972287496138382764643208791713986676129260589667864467010129482", 43 | "1888098689545151571063267806606510032698677328923740058080630641742325067877", 44 | "148924106504065664829055598316821983869409581623245780505601526786791681102", 45 | "18875020877782404439294079398043479420415331640996249745272087358069018086569", 46 | "15189693413320228845990326214136820307649565437237093707846682797649429515840", 47 | "19669450123472657781282985229369348220906547335081730205028099210442632534079", 48 | "5521922218264623411380547905210139511350706092570900075727555783240701821773", 49 | "4144769320246558352780591737261172907511489963810975650573703217887429086546", 50 | "10097732913112662248360143041019433907849917041759137293018029019134392559350", 51 | "1720059427972723034107765345743336447947522473310069975142483982753181038321", 52 | "6302388219880227251325608388535181451187131054211388356563634768253301290116", 53 | "6745410632962119604799318394592010194450845483518862700079921360015766217097", 54 | "10858157235265583624235850660462324469799552996870780238992046963007491306222", 55 | "20241898894740093733047052816576694435372877719072347814065227797906130857593", 56 | "10165780782761211520836029617746977303303335603838343292431760011576528327409", 57 | "2832093654883670345969792724123161241696170611611744759675180839473215203706", 58 | "153011722355526826233082383360057587249818749719433916258246100068258954737", 59 | "20196970640587451358539129330170636295243141659030208529338914906436009086943", 60 | "3180973917010545328313139835982464870638521890385603025657430208141494469656", 61 | "17198004293191777441573635123110935015228014028618868252989374962722329283022", 62 | "7642160509228669138628515458941659189680509753651629476399516332224325757132", 63 | "19346204940546791021518535594447257347218878114049998691060016493806845179755", 64 | "11501810868606870391127866188394535330696206817602260610801897042898616817272", 65 | "3113973447392053821824427670386252797811804954746053461397972968381571297505", 66 | "6545064306297957002139416752334741502722251869537551068239642131448768236585", 67 | "5203908808704813498389265425172875593837960384349653691918590736979872578408", 68 | "2246692432011290582160062129070762007374502637007107318105405626910313810224", 69 | "11760570435432189127645691249600821064883781677693087773459065574359292849137", 70 | "5543749482491340532547407723464609328207990784853381797689466144924198391839", 71 | "8837549193990558762776520822018694066937602576881497343584903902880277769302", 72 | "12855514863299373699594410385788943772765811961581749194183533625311486462501", 73 | "5363660674689121676875069134269386492382220935599781121306637800261912519729", 74 | "13162342403579303950549728848130828093497701266240457479693991108217307949435", 75 | "916941639326869583414469202910306428966657806899788970948781207501251816730", 76 | "15618589556584434434009868216186115416835494805174158488636000580759692174228", 77 | "8959562060028569701043973060670353733575345393653685776974948916988033453971", 78 | "16390754464333401712265575949874369157699293840516802426621216808905079127650", 79 | "168282396747788514908709091757591226095443902501365500003618183905496160435", 80 | "8327443473179334761744301768309008451162322941906921742120510244986704677004", 81 | "17213012626801210615058753489149961717422101711567228037597150941152495100640", 82 | "10394369641533736715250242399198097296122982486516256408681925424076248952280", 83 | "17784386835392322654196171115293700800825771210400152504776806618892170162248", 84 | "16533189939837087893364000390641148516479148564190420358849587959161226782982", 85 | "18725396114211370207078434315900726338547621160475533496863298091023511945076", 86 | "7132325028834551397904855671244375895110341505383911719294705267624034122405", 87 | "148317947440800089795933930720822493695520852448386394775371401743494965187", 88 | "19001050671757720352890779127693793630251266879994702723636759889378387053056", 89 | "18824274411769830274877839365728651108434404855803844568234862945613766611460", 90 | "12771414330193951156383998390424063470766226667986423961689712557338777174205", 91 | "11332046574800279729678603488745295198038913503395629790213378101166488244657", 92 | "9607550223176946388146938069307456967842408600269548190739947540821716354749", 93 | "8756385288462344550200229174435953103162307705310807828651304665320046782583", 94 | "176061952957067086877570020242717222844908281373122372938833890096257042779", 95 | "12200212977482648306758992405065921724409841940671166017620928947866825250857", 96 | "10868453624107875516866146499877130701929063632959660262366632833504750028858", 97 | "2016095394399807253596787752134573207202567875457560571095586743878953450738", 98 | "21815578223768330433802113452339488275704145896544481092014911825656390567514", 99 | "4923772847693564777744725640710197015181591950368494148029046443433103381621", 100 | "1813584943682214789802230765734821149202472893379265320098816901270224589984", 101 | "10810123816265612772922113403831964815724109728287572256602010709288980656498", 102 | "1153669123397255702524721206511185557982017410156956216465120456256288427021", 103 | "5007518659266430200134478928344522649876467369278722765097865662497773767152", 104 | "2511432546938591792036639990606464315121646668029252285288323664350666551637", 105 | "32883284540320451295484135704808083452381176816565850047310272290579727564", 106 | "10484856914279112612610993418405543310546746652738541161791501150994088679557", 107 | "2026733759645519472558796412979210009170379159866522399881566309631434814953", 108 | "14731806221235869882801331463708736361296174006732553130708107037190460654379", 109 | "14740327483193277147065845135561988641238516852487657117813536909482068950652", 110 | "18787428285295558781869865751953016580493190547148386433580291216673009884554", 111 | "3804047064713122820157099453648459188816376755739202017447862327783289895072", 112 | "16709604795697901641948603019242067672006293290826991671766611326262532802914", 113 | "11061717085931490100602849654034280576915102867237101935487893025907907250695", 114 | "2821730726367472966906149684046356272806484545281639696873240305052362149654", 115 | "17467794879902895769410571945152708684493991588672014763135370927880883292655", 116 | "1571520786233540988201616650622796363168031165456869481368085474420849243232", 117 | "10041051776251223165849354194892664881051125330236567356945669006147134614302", 118 | "3981753758468103976812813304477670033098707002886030847251581853700311567551", 119 | "4365864398105436789177703571412645548020537580493599380018290523813331678900", 120 | "2391801327305361293476178683853802679507598622000359948432171562543560193350", 121 | "214219368547551689972421167733597094823289857206402800635962137077096090722", 122 | "18192064100315141084242006659317257023098826945893371479835220462302399655674", 123 | "15487549757142039139328911515400805508248576685795694919457041092150651939253", 124 | "10142447197759703415402259672441315777933858467700579946665223821199077641122", 125 | "11246573086260753259993971254725613211193686683988426513880826148090811891866", 126 | "6574066859860991369704567902211886840188702386542112593710271426704432301235", 127 | "11311085442652291634822798307831431035776248927202286895207125867542470350078", 128 | "20977948360215259915441258687649465618185769343138135384346964466965010873779", 129 | "792781492853909872425531014397300057232399608769451037135936617996830018501", 130 | "5027602491523497423798779154966735896562099398367163998686335127580757861872", 131 | "14595204575654316237672764823862241845410365278802914304953002937313300553572", 132 | "13973538843621261113924259058427434053808430378163734641175100160836376897004", 133 | "16395063164993626722686882727042150241125309409717445381854913964674649318585", 134 | "8465768840047024550750516678171433288207841931251654898809033371655109266663", 135 | "21345603324471810861925019445720576814602636473739003852898308205213912255830", 136 | "21171984405852590343970239018692870799717057961108910523876770029017785940991", 137 | "10761027113757988230637066281488532903174559953630210849190212601991063767647", 138 | "6678298831065390834922566306988418588227382406175769592902974103663687992230", 139 | "4993662582188632374202316265508850988596880036291765531885657575099537176757", 140 | "18364168158495573675698600238443218434246806358811328083953887470513967121206", 141 | "3506345610354615013737144848471391553141006285964325596214723571988011984829", 142 | "248732676202643792226973868626360612151424823368345645514532870586234380100", 143 | "10090204501612803176317709245679152331057882187411777688746797044706063410969", 144 | "21297149835078365363970699581821844234354988617890041296044775371855432973500", 145 | "16729368143229828574342820060716366330476985824952922184463387490091156065099", 146 | "4467191506765339364971058668792642195242197133011672559453028147641428433293", 147 | "8677548159358013363291014307402600830078662555833653517843708051504582990832", 148 | "1022951765127126818581466247360193856197472064872288389992480993218645055345", 149 | "1888195070251580606973417065636430294417895423429240431595054184472931224452", 150 | "4221265384902749246920810956363310125115516771964522748896154428740238579824", 151 | "2825393571154632139467378429077438870179957021959813965940638905853993971879", 152 | "19171031072692942278056619599721228021635671304612437350119663236604712493093", 153 | "10780807212297131186617505517708903709488273075252405602261683478333331220733", 154 | "18230936781133176044598070768084230333433368654744509969087239465125979720995", 155 | "16901065971871379877929280081392692752968612240624985552337779093292740763381", 156 | "146494141603558321291767829522948454429758543710648402457451799015963102253", 157 | "2492729278659146790410698334997955258248120870028541691998279257260289595548", 158 | "2204224910006646535594933495262085193210692406133533679934843341237521233504", 159 | "16062117410185840274616925297332331018523844434907012275592638570193234893570", 160 | "5894928453677122829055071981254202951712129328678534592916926069506935491729", 161 | "4947482739415078212217504789923078546034438919537985740403824517728200332286", 162 | "16143265650645676880461646123844627780378251900510645261875867423498913438066", 163 | "397690828254561723549349897112473766901585444153303054845160673059519614409", 164 | "11272653598912269895509621181205395118899451234151664604248382803490621227687", 165 | "15566927854306879444693061574322104423426072650522411176731130806720753591030", 166 | "14222898219492484180162096141564251903058269177856173968147960855133048449557", 167 | "16690275395485630428127725067513114066329712673106153451801968992299636791385", 168 | "3667030990325966886479548860429670833692690972701471494757671819017808678584", 169 | "21280039024501430842616328642522421302481259067470872421086939673482530783142", 170 | "15895485136902450169492923978042129726601461603404514670348703312850236146328", 171 | "7733050956302327984762132317027414325566202380840692458138724610131603812560", 172 | "438123800976401478772659663183448617575635636575786782566035096946820525816", 173 | "814913922521637742587885320797606426167962526342166512693085292151314976633", 174 | "12368712287081330853637674140264759478736012797026621876924395982504369598764", 175 | "2494806857395134874309386694756263421445039103814920780777601708371037591569", 176 | "16101132301514338989512946061786320637179843435886825102406248183507106312877", 177 | "6252650284989960032925831409804233477770646333900692286731621844532438095656", 178 | "9277135875276787021836189566799935097400042171346561246305113339462708861695", 179 | "10493603554686607050979497281838644324893776154179810893893660722522945589063", 180 | "8673089750662709235894359384294076697329948991010184356091130382437645649279", 181 | "9558393272910366944245875920138649617479779893610128634419086981339060613250", 182 | "19012287860122586147374214541764572282814469237161122489573881644994964647218", 183 | "9783723818270121678386992630754842961728702994964214799008457449989291229500", 184 | "15550788416669474113213749561488122552422887538676036667630838378023479382689", 185 | "15016165746156232864069722572047169071786333815661109750860165034341572904221", 186 | "6506225705710197163670556961299945987488979904603689017479840649664564978574", 187 | "10796631184889302076168355684722130903785890709107732067446714470783437829037", 188 | "19871836214837460419845806980869387567383718044439891735114283113359312279540", 189 | "20871081766843466343749609089986071784031203517506781251203251608363835140622", 190 | "5100105771517691442278432864090229416166996183792075307747582375962855820797", 191 | "8777887112076272395250620301071581171386440850451972412060638225741125310886", 192 | "5300440870136391278944213332144327695659161151625757537632832724102670898756", 193 | "1205448543652932944633962232545707633928124666868453915721030884663332604536", 194 | "5542499997310181530432302492142574333860449305424174466698068685590909336771", 195 | "11028094245762332275225364962905938096659249161369092798505554939952525894293", 196 | "19187314764836593118404597958543112407224947638377479622725713735224279297009", 197 | "17047263688548829001253658727764731047114098556534482052135734487985276987385", 198 | "19914849528178967155534624144358541535306360577227460456855821557421213606310", 199 | "2929658084700714257515872921366736697080475676508114973627124569375444665664", 200 | "15092262360719700162343163278648422751610766427236295023221516498310468956361", 201 | "21578580340755653236050830649990190843552802306886938815497471545814130084980", 202 | "1258781501221760320019859066036073675029057285507345332959539295621677296991", 203 | "3819598418157732134449049289585680301176983019643974929528867686268702720163", 204 | "8653175945487997845203439345797943132543211416447757110963967501177317426221", 205 | "6614652990340435611114076169697104582524566019034036680161902142028967568142", 206 | "19212515502973904821995111796203064175854996071497099383090983975618035391558", 207 | "18664315914479294273286016871365663486061896605232511201418576829062292269769", 208 | "11498264615058604317482574216318586415670903094838791165247179252175768794889", 209 | "10814026414212439999107945133852431304483604215416531759535467355316227331774", 210 | "17566185590731088197064706533119299946752127014428399631467913813769853431107", 211 | "14016139747289624978792446847000951708158212463304817001882956166752906714332", 212 | "8242601581342441750402731523736202888792436665415852106196418942315563860366", 213 | "9244680976345080074252591214216060854998619670381671198295645618515047080988", 214 | "12216779172735125538689875667307129262237123728082657485828359100719208190116", 215 | "10702811721859145441471328511968332847175733707711670171718794132331147396634", 216 | "6479667912792222539919362076122453947926362746906450079329453150607427372979", 217 | "15117544653571553820496948522381772148324367479772362833334593000535648316185", 218 | "6842203153996907264167856337497139692895299874139131328642472698663046726780", 219 | "12732823292801537626009139514048596316076834307941224506504666470961250728055", 220 | "6936272626871035740815028148058841877090860312517423346335878088297448888663", 221 | "17297554111853491139852678417579991271009602631577069694853813331124433680030", 222 | "16641596134749940573104316021365063031319260205559553673368334842484345864859", 223 | "7400481189785154329569470986896455371037813715804007747228648863919991399081", 224 | "2273205422216987330510475127669563545720586464429614439716564154166712854048", 225 | "15162538063742142685306302282127534305212832649282186184583465569986719234456", 226 | "5628039096440332922248578319648483863204530861778160259559031331287721255522", 227 | "16085392195894691829567913404182676871326863890140775376809129785155092531260", 228 | "14227467863135365427954093998621993651369686288941275436795622973781503444257", 229 | "18224457394066545825553407391290108485121649197258948320896164404518684305122", 230 | "274945154732293792784580363548970818611304339008964723447672490026510689427", 231 | "11050822248291117548220126630860474473945266276626263036056336623671308219529", 232 | "2119542016932434047340813757208803962484943912710204325088879681995922344971", 233 | "0", 234 | ]; 235 | consts 236 | .into_iter() 237 | .map(|c| PrimeElem { 238 | x: U512::from_dec_str(c).unwrap(), 239 | }) 240 | .collect::>() 241 | }; 242 | } 243 | 244 | fn main() { 245 | let out_dir = env::var_os("OUT_DIR").unwrap(); 246 | let dest_path = Path::new(&out_dir).join("constants.rs"); 247 | let mut f = fs::File::create(&dest_path).unwrap(); 248 | 249 | writeln!(&mut f, "const C: [PrimeElem; {}] = [", C.len()).unwrap(); 250 | for v in C.iter() { 251 | writeln!(&mut f, "PrimeElem {{x: U512([").unwrap(); 252 | for byte in v.x.as_ref().iter() { 253 | writeln!(&mut f, " {},", &format!("{:?}", byte)).unwrap(); 254 | } 255 | writeln!(&mut f, "])}},").unwrap(); 256 | } 257 | writeln!(&mut f, "];").unwrap(); 258 | 259 | writeln!(&mut f, "const P: U512 = U512([").unwrap(); 260 | for byte in P.as_ref().iter() { 261 | writeln!(&mut f, " {},", &format!("{:?}", byte)).unwrap(); 262 | } 263 | writeln!(&mut f, "]);").unwrap(); 264 | 265 | println!("cargo:rerun-if-changed=build.rs"); 266 | } 267 | -------------------------------------------------------------------------------- /darkforest/examples/standalone.rs: -------------------------------------------------------------------------------- 1 | //! This is an example of a standalone miner that doesn't require a Dark Forest 2 | //! game to connect and drive it. It hardcodes the key and rarity which need to 3 | //! be updated based on whatever version of Dark Forest you're running or will 4 | //! produce bad data. You would want to stick the results in a database or 5 | //! somethig, but for this example theyre simply debug printed out as json. 6 | //! 7 | //! cargo run --release --example standalone 8 | 9 | use darkforest::{mimc_hash, threshold, ChunkFootprint, Coords, Planet, SpiralExplorer, U512}; 10 | use itertools::iproduct; 11 | use rayon::prelude::*; 12 | 13 | // SnarkConstants.PLANETHASH_KEY 14 | const PLANETHASH_KEY: u32 = 420; 15 | // GameConstants.PLANET_RARITY 16 | const PLANET_RARITY: u32 = 16384; 17 | 18 | fn main() { 19 | // how big of chunks, client default is 16, remote miner default is 256 20 | const CHUNK_SIZE: u16 = 256; 21 | 22 | // set where you want to mine here 23 | let center = Coords { x: 0, y: 0 }; 24 | 25 | let threshold: U512 = threshold(PLANET_RARITY); 26 | let mut explorer = SpiralExplorer::new(center, CHUNK_SIZE); 27 | 28 | loop { 29 | if let Some(chunk) = explorer.next() { 30 | let found = explore(chunk.clone(), threshold); 31 | // storing in a database or flatfile is an exercise left up to reader 32 | println!("{:?} {:?} ", chunk, found); 33 | } 34 | } 35 | } 36 | 37 | fn explore(chunk: ChunkFootprint, threshold: U512) -> Vec { 38 | let ChunkFootprint { 39 | sideLength: size, 40 | bottomLeft: Coords { x, y }, 41 | } = chunk; 42 | 43 | iproduct!(x..(x + size), y..(y + size)) 44 | .par_bridge() 45 | .filter_map(|(xi, yi)| { 46 | let hash = mimc_hash(xi, yi, PLANETHASH_KEY); 47 | if hash < threshold { 48 | Some(Planet { 49 | coords: Coords { x: xi, y: yi }, 50 | hash: hash.to_string(), 51 | }) 52 | } else { 53 | None 54 | } 55 | }) 56 | .collect::>() 57 | } 58 | -------------------------------------------------------------------------------- /darkforest/src/explorers.rs: -------------------------------------------------------------------------------- 1 | use super::{ChunkFootprint, Coords}; 2 | 3 | /// A Spiral Iterator of ChunkFootprint 4 | pub struct SpiralExplorer { 5 | chunk_side_length: u16, 6 | from_chunk: ChunkFootprint, 7 | current_chunk: ChunkFootprint, 8 | } 9 | 10 | impl SpiralExplorer { 11 | pub fn new(center: Coords, chunk_side_length: u16) -> Self { 12 | //floor by default? 13 | 14 | let length = i64::from(chunk_side_length); 15 | 16 | let bottom_left_x = (center.x / length) * length; 17 | let bottom_left_y = (center.y / length) * length; 18 | let bottom_left = Coords { 19 | x: bottom_left_x, 20 | y: bottom_left_y, 21 | }; 22 | 23 | let from_chunk = ChunkFootprint { 24 | bottomLeft: bottom_left, 25 | sideLength: length, 26 | }; 27 | 28 | Self { 29 | chunk_side_length, 30 | from_chunk: from_chunk.clone(), 31 | current_chunk: from_chunk, 32 | } 33 | } 34 | } 35 | 36 | impl Iterator for SpiralExplorer { 37 | type Item = ChunkFootprint; 38 | fn next(&mut self) -> Option { 39 | let Coords { 40 | x: home_x, 41 | y: home_y, 42 | } = self.from_chunk.bottomLeft; 43 | let Coords { 44 | x: curr_x, 45 | y: curr_y, 46 | } = self.current_chunk.bottomLeft; 47 | 48 | let mut next_bottom_left = self.current_chunk.bottomLeft.clone(); 49 | 50 | let length = i64::from(self.chunk_side_length); 51 | 52 | if curr_x == home_x && curr_y == home_y { 53 | next_bottom_left.y = home_y + length; 54 | } else if curr_y - curr_x > home_y - home_x && curr_y + curr_x >= home_x + home_y { 55 | if curr_y + curr_x == home_x + home_y { 56 | // break the circle 57 | next_bottom_left.y = curr_y + length; 58 | } else { 59 | next_bottom_left.x = curr_x + length; 60 | } 61 | } else if curr_x + curr_y > home_x + home_y && curr_y - curr_x <= home_y - home_x { 62 | next_bottom_left.y = curr_y - length; 63 | } else if curr_x + curr_y <= home_x + home_y && curr_y - curr_x < home_y - home_x { 64 | next_bottom_left.x = curr_x - length; 65 | } else { 66 | // if (curr_x + curr_y < home_x + home_y && curr_y - curr_x >= home_y - home_x) 67 | next_bottom_left.y = curr_y + length; 68 | } 69 | 70 | self.current_chunk = ChunkFootprint { 71 | bottomLeft: next_bottom_left, 72 | sideLength: length, 73 | }; 74 | Some(self.current_chunk.clone()) 75 | } 76 | } 77 | 78 | #[cfg(test)] 79 | mod tests { 80 | use super::*; 81 | 82 | #[test] 83 | fn sixteen_iter() { 84 | let center = Coords { x: 0, y: 0 }; 85 | let chunk_side_length = 16; 86 | let mut explorer = SpiralExplorer::new(center, chunk_side_length); 87 | 88 | assert_eq!( 89 | explorer.next(), 90 | Some(ChunkFootprint { 91 | bottomLeft: Coords { 92 | x: 0, 93 | y: chunk_side_length as i64, 94 | }, 95 | sideLength: chunk_side_length as i64 96 | }) 97 | ); 98 | 99 | assert_eq!( 100 | explorer.next(), 101 | Some(ChunkFootprint { 102 | bottomLeft: Coords { 103 | x: chunk_side_length as i64, 104 | y: chunk_side_length as i64, 105 | }, 106 | sideLength: chunk_side_length as i64 107 | }) 108 | ); 109 | 110 | assert_eq!( 111 | explorer.next(), 112 | Some(ChunkFootprint { 113 | bottomLeft: Coords { 114 | x: chunk_side_length as i64, 115 | y: 0, 116 | }, 117 | sideLength: chunk_side_length as i64 118 | }) 119 | ); 120 | 121 | assert_eq!( 122 | explorer.next(), 123 | Some(ChunkFootprint { 124 | bottomLeft: Coords { 125 | x: chunk_side_length as i64, 126 | y: -(chunk_side_length as i64), 127 | }, 128 | sideLength: chunk_side_length as i64 129 | }) 130 | ); 131 | 132 | assert_eq!( 133 | explorer.next(), 134 | Some(ChunkFootprint { 135 | bottomLeft: Coords { 136 | x: 0, 137 | y: -(chunk_side_length as i64), 138 | }, 139 | sideLength: chunk_side_length as i64 140 | }) 141 | ); 142 | } 143 | 144 | #[test] 145 | fn thirtytwo_iter() { 146 | let center = Coords { x: 0, y: 0 }; 147 | let chunk_side_length = 32; 148 | let mut explorer = SpiralExplorer::new(center, chunk_side_length); 149 | 150 | assert_eq!( 151 | explorer.next(), 152 | Some(ChunkFootprint { 153 | bottomLeft: Coords { 154 | x: 0, 155 | y: chunk_side_length as i64, 156 | }, 157 | sideLength: chunk_side_length as i64 158 | }) 159 | ); 160 | 161 | assert_eq!( 162 | explorer.next(), 163 | Some(ChunkFootprint { 164 | bottomLeft: Coords { 165 | x: chunk_side_length as i64, 166 | y: chunk_side_length as i64, 167 | }, 168 | sideLength: chunk_side_length as i64 169 | }) 170 | ); 171 | 172 | assert_eq!( 173 | explorer.next(), 174 | Some(ChunkFootprint { 175 | bottomLeft: Coords { 176 | x: chunk_side_length as i64, 177 | y: 0, 178 | }, 179 | sideLength: chunk_side_length as i64 180 | }) 181 | ); 182 | 183 | assert_eq!( 184 | explorer.next(), 185 | Some(ChunkFootprint { 186 | bottomLeft: Coords { 187 | x: chunk_side_length as i64, 188 | y: -(chunk_side_length as i64), 189 | }, 190 | sideLength: chunk_side_length as i64 191 | }) 192 | ); 193 | 194 | assert_eq!( 195 | explorer.next(), 196 | Some(ChunkFootprint { 197 | bottomLeft: Coords { 198 | x: 0, 199 | y: -(chunk_side_length as i64), 200 | }, 201 | sideLength: chunk_side_length as i64 202 | }) 203 | ); 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /darkforest/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub use mimc::U512; 2 | use mimc::{sponge, PrimeElem}; 3 | use serde::{Deserialize, Serialize}; 4 | use std::cmp::PartialEq; 5 | use std::ops::Div; 6 | 7 | mod explorers; 8 | pub use explorers::*; 9 | 10 | include!(concat!(env!("OUT_DIR"), "/constants.rs")); 11 | 12 | pub fn mimc_hash(x: i64, y: i64, key: u32) -> U512 { 13 | mimc_hash_rounds(x, y, key, C.len()) 14 | } 15 | 16 | pub fn mimc_hash_rounds(x: i64, y: i64, key: u32, rounds: usize) -> U512 { 17 | assert!(rounds <= C.len()); 18 | sponge(&[x, y], 1, rounds, key, &P, &C)[0].x 19 | } 20 | 21 | pub fn threshold(rarity: u32) -> U512 { 22 | P.div(U512::from(rarity)) 23 | } 24 | 25 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] 26 | pub struct Coords { 27 | pub x: i64, 28 | pub y: i64, 29 | } 30 | 31 | #[derive(Serialize, Deserialize, Debug)] 32 | pub struct Planet { 33 | pub coords: Coords, 34 | pub hash: String, 35 | } 36 | 37 | #[allow(non_snake_case)] 38 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] 39 | pub struct ChunkFootprint { 40 | pub bottomLeft: Coords, 41 | pub sideLength: i64, 42 | } 43 | 44 | #[cfg(test)] 45 | mod tests { 46 | use super::*; 47 | 48 | #[test] 49 | fn constants_p() { 50 | let p: U512 = U512::from_dec_str( 51 | "21888242871839275222246405745257275088548364400416034343698204186575808495617", 52 | ) 53 | .unwrap(); 54 | 55 | assert_eq!(P, p); 56 | } 57 | 58 | #[test] 59 | fn sponge() { 60 | let hash = mimc_hash(216, 158, 8); 61 | assert_eq!( 62 | hash.to_string(), 63 | String::from( 64 | "243586509754089793444036766672578053539607441572992882184488791828676079" 65 | ) 66 | ) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /mimc-fast/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mimc-fast" 3 | version = "0.1.0" 4 | authors = ["Jacob Rosenthal "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | [dependencies] 9 | rayon = "1.5.0" 10 | itertools = "0.10.0" 11 | darkforest = { version = "0.1.0", path = "../darkforest" } 12 | serde = { version = "1.0.124", features = ["derive"] } 13 | tokio = { version = "1", features = ["macros", "rt-multi-thread"] } 14 | warp = { version = "0.3", default-features = false } 15 | pretty_env_logger = "0.4.0" 16 | -------------------------------------------------------------------------------- /mimc-fast/readme.md: -------------------------------------------------------------------------------- 1 | # Dark forest mimc miner 2 | 3 | [Dark Forest](https://zkga.me/), the world's first decentralized real-time strategy game. Built on Ethereum with zkSNARKsis a 4 | 5 | Note if you're not technical and cant get through this guide, remember you can get a lot of speedup by just having the stock game use more cores with something like `df.setMinerCores(16)` in the console. So try that first. 6 | 7 | This rust package pulls out the fog of war miner to its own binary with a webserver for in game plugins to talk to it. It provides faster results than the built in javascript miner on the same machine. If you're using it on the same machine as the game Pause your in game miner as theyll just compete with eachother and give WORSE results. It also can run remotely in the cloud or even a rapsberry pi 4 has been found to provide 1-2k hashes. 8 | 9 | ## Install 10 | 11 | The rust miner on the same machine as your game can be faster than the javascript because it can more fully utilize the processor. But if you're running on the same machine as the game, pause the in game miner. They're just going to compete with eachother and give you worse peformance. 12 | 13 | - Install [rust for your operating system](https://www.rust-lang.org/tools/install) probably with `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` 14 | - Install with `cargo install --git https://github.com/projectsophon/darkforest-rs --bin mimc-fast --force --branch=main` 15 | - Run it (with logging enabled environment variable) with `mimc-fast` or with logging enabled `RUST_LOG=info mimc-fast` 16 | - Connect to it with the built in plugin "Remote Explore" 17 | - Finally if your server does't have an ssl cert on it (it probably doesn't) then you also need to cripple ssl security for the Dark Forest game domain. NOTE THIS IS VERY DANGEROUS. See [enabling mixed content](https://github.com/darkforest-eth/plugins/blob/dc1e024ac658ef34873f8b36176cca2945e52e7c/content/productivity/remote-explore/enable-mixed.md) for an example of how thats done. 18 | 19 | Remember to pause the built in miner if you're running it on the same machine as the game client or they'll just fight eachother for resources and give LESS hashes overall. 20 | 21 | ### Windows 22 | - Install [rust for your operating system](https://www.rust-lang.org/tools/install) probably with `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` 23 | - Install with `cargo install --git https://github.com/projectsophon/darkforest-rs --bin mimc-fast --force --branch=main` 24 | - mimc-fast.exe is located at `C:\Users\\.cargo\bin` you can copy past it where you want 25 | - Create a miner.bat file in the same directory as mimc-fast.exe with 26 | 27 | set RAYON_NUM_THREADS=16 28 | set RUST_LOG=info 29 | mimc-fast.exe 30 | - Open miner.bat to start the server 31 | - Use `http://localhost:8000/mine` to connect to your local miner with the built in plugin "Remote Explore" 32 | 33 | ## Troubleshooting 34 | To test its working to the mining url, in the case of your local machine `curl --data '{"chunkFootprint": { "bottomLeft": { "x": 0, "y": 0 }, "sideLength": 256 }, "planetRarity":16384, "planetHashKey": 8}' -H "Content-Type: application/json" -X POST localhost:8000/mine` 35 | 36 | You can get far more debug logs by running with `RUST_LOG=trace cargo run` 37 | 38 | ### Performance tuning 39 | 40 | By defualt the miner uses as much of your processor as possible. This is good if you're on a cloud machine, but not great if you're also trying to run the game. A single processor machine with 4 cores, and 2 threads per core, has 8 threads available. Adjust for your machine, but you might try 4 or 6 threads and see if you dont get even a little better performance because its not competing with the game for resources. You can set the amount of threads to use with an environment variable before the executable like `RAYON_NUM_THREADS=4 mimc-fast` 41 | 42 | -------------------------------------------------------------------------------- /mimc-fast/src/main.rs: -------------------------------------------------------------------------------- 1 | use darkforest::{mimc_hash, threshold, ChunkFootprint, Coords, Planet}; 2 | use itertools::iproduct; 3 | use rayon::prelude::*; 4 | use serde::{Deserialize, Serialize}; 5 | use std::env; 6 | use warp::{http::Method, Filter}; 7 | 8 | async fn mine(task: Task) -> Result { 9 | let x = task.chunkFootprint.bottomLeft.x; 10 | let y = task.chunkFootprint.bottomLeft.y; 11 | let size = task.chunkFootprint.sideLength; 12 | let key = task.planetHashKey; 13 | 14 | let threshold = threshold(task.planetRarity); 15 | 16 | let planets = iproduct!(x..(x + size), y..(y + size)) 17 | .par_bridge() 18 | .filter_map(|(xi, yi)| { 19 | let hash = mimc_hash(xi, yi, key); 20 | if hash < threshold { 21 | Some(Planet { 22 | coords: Coords { x: xi, y: yi }, 23 | hash: hash.to_string(), 24 | }) 25 | } else { 26 | None 27 | } 28 | }) 29 | .collect::>(); 30 | 31 | let rsp = Response { 32 | chunkFootprint: task.chunkFootprint, 33 | planetLocations: planets, 34 | }; 35 | 36 | Ok(warp::reply::json(&rsp)) 37 | } 38 | 39 | #[tokio::main] 40 | async fn main() { 41 | pretty_env_logger::init(); 42 | 43 | let log = warp::log("mimc-fast"); 44 | 45 | let port = env::var("PORT") 46 | .unwrap_or_else(|_| "8000".into()) 47 | .parse::() 48 | .unwrap(); 49 | 50 | let cors = warp::cors() 51 | .allow_methods(&[Method::GET, Method::POST, Method::OPTIONS]) 52 | .allow_any_origin() 53 | .allow_header("content-type"); 54 | 55 | let route = warp::post() 56 | .and(warp::path("mine")) 57 | // Only accept bodies smaller than 16kb... 58 | .and(warp::body::content_length_limit(1024 * 16)) 59 | .and(warp::body::json()) 60 | .and_then(mine) 61 | .with(log) 62 | .with(cors); 63 | 64 | warp::serve(route).run(([0, 0, 0, 0], port)).await 65 | } 66 | 67 | #[allow(non_snake_case)] 68 | #[derive(Deserialize)] 69 | pub struct Task { 70 | pub chunkFootprint: ChunkFootprint, 71 | pub planetRarity: u32, 72 | pub planetHashKey: u32, 73 | } 74 | 75 | #[allow(non_snake_case)] 76 | #[derive(Serialize)] 77 | pub struct Response { 78 | pub chunkFootprint: ChunkFootprint, 79 | pub planetLocations: Vec, 80 | } 81 | -------------------------------------------------------------------------------- /mimc/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mimc" 3 | version = "0.1.0" 4 | authors = ["Alex Gajewski "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | [dependencies] 9 | primitive-types = "0.9.0" 10 | -------------------------------------------------------------------------------- /mimc/README.md: -------------------------------------------------------------------------------- 1 | # mimc 2 | 3 | This work originated with 4 | -------------------------------------------------------------------------------- /mimc/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub use primitive_types::U512; 2 | use std::ops::Rem; 3 | 4 | #[derive(Debug, Clone)] 5 | pub struct PrimeElem { 6 | pub x: U512, 7 | } 8 | 9 | impl PrimeElem { 10 | fn plus(&self, rhs: &PrimeElem, p: &U512) -> PrimeElem { 11 | let (sum, overflowed) = self.x.overflowing_add(rhs.x); 12 | assert!(!overflowed); 13 | let res = sum.rem(p); 14 | PrimeElem { x: res } 15 | } 16 | 17 | fn times(&self, rhs: &PrimeElem, p: &U512) -> PrimeElem { 18 | let (prod, overflowed) = self.x.overflowing_mul(rhs.x); 19 | assert!(!overflowed); 20 | let res = prod.rem(p); 21 | assert!(!overflowed); 22 | PrimeElem { x: res } 23 | } 24 | 25 | fn fifth_power(&self, p: &U512) -> PrimeElem { 26 | let s = self.times(self, p); 27 | let f = s.times(&s, p); 28 | f.times(self, p) 29 | } 30 | 31 | fn zero() -> PrimeElem { 32 | PrimeElem { x: U512::zero() } 33 | } 34 | } 35 | 36 | pub struct MimcState { 37 | l: PrimeElem, 38 | r: PrimeElem, 39 | rounds: usize, 40 | k: PrimeElem, 41 | } 42 | 43 | impl MimcState { 44 | fn new(rounds: usize, k: PrimeElem) -> MimcState { 45 | MimcState { 46 | l: PrimeElem::zero(), 47 | r: PrimeElem::zero(), 48 | rounds, 49 | k, 50 | } 51 | } 52 | 53 | fn inject(&mut self, elt: &PrimeElem, p: &U512) { 54 | self.l = self.l.plus(elt, p); 55 | } 56 | 57 | fn mix(&mut self, c: &[PrimeElem], p: &U512) { 58 | for item in c.iter().take(self.rounds - 1) { 59 | let t = self.k.plus(&self.l, p).plus(item, p); 60 | let l_new = t.fifth_power(p).plus(&self.r, p); 61 | self.r = self.l.clone(); 62 | self.l = l_new; 63 | } 64 | let t = self.k.plus(&self.l, p); 65 | self.r = t.fifth_power(p).plus(&self.r, p); 66 | } 67 | } 68 | 69 | pub fn sponge( 70 | inputs: &[i64], 71 | n_outputs: usize, 72 | rounds: usize, 73 | key: u32, 74 | p: &U512, 75 | c: &[PrimeElem], 76 | ) -> Vec { 77 | let inputs = inputs 78 | .iter() 79 | .map(|x| { 80 | let bigx = if x < &0 { 81 | let (diff, overflowed) = 82 | p.overflowing_sub(U512::from_big_endian(&((-x).to_be_bytes()))); 83 | assert!(!overflowed); 84 | diff 85 | } else { 86 | U512::from_big_endian(&x.to_be_bytes()) 87 | }; 88 | PrimeElem { x: bigx } 89 | }) 90 | .collect::>(); 91 | let mut state = MimcState::new(rounds, PrimeElem { x: U512::from(key) }); 92 | for elt in inputs { 93 | state.inject(&elt, p); 94 | state.mix(c, p); 95 | } 96 | let mut outputs = vec![state.l.clone()]; 97 | for _ in 1..n_outputs { 98 | state.mix(c, p); 99 | outputs.push(state.l.clone()); 100 | } 101 | outputs 102 | } 103 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # darkforest-rs 2 | 3 | [Dark Forest](https://zkga.me/), the world's first decentralized real-time strategy game. Built on Ethereum with zkSNARKsis a 4 | 5 | - For remote mining see the [mimc-fast](mimc-fast) subdirectory 6 | - For Darkforest rust developers see the [darkforest](darkforest) subdirectory 7 | --------------------------------------------------------------------------------