Skip to content

Instantly share code, notes, and snippets.

@rustyrussell
Last active September 15, 2023 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rustyrussell/bc8313a84e4d66c625b3faf371b6fbfc to your computer and use it in GitHub Desktop.
Save rustyrussell/bc8313a84e4d66c625b3faf371b6fbfc to your computer and use it in GitHub Desktop.
Quick hack to create nodeid flags using block hashes
#include <ccan/crypto/sha256/sha256.h>
#include <ccan/err/err.h>
#include <ccan/opt/opt.h>
#include <ccan/short_types/short_types.h>
#include <ccan/str/hex/hex.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
int main(int argc, char *argv[])
{
u8 nodeid[33];
struct sha256_ctx sha_base;
opt_register_noarg("--usage|--help|-h", opt_usage_and_exit,
"nodeid blockhash...\n"
"Calculates an RGB color combining nodeid and blockhash",
"Print this message");
opt_parse(&argc, argv, opt_log_stderr_exit);
if (argc < 3)
opt_usage_and_exit(NULL);
if (!hex_decode(argv[1], strlen(argv[1]), nodeid, sizeof(nodeid)))
errx(1, "bad nodeid");
/* Start by hashing node id */
sha256_init(&sha_base);
sha256_update(&sha_base, nodeid, sizeof(nodeid));
for (size_t i = 2; i < argc; i++) {
struct sha256_ctx sha = sha_base;
struct sha256 res;
u8 blockhash[32];
if (!hex_decode(argv[i], strlen(argv[i]), blockhash, sizeof(blockhash)))
errx(1, "bad blockhash %s", argv[i]);
sha256_update(&sha, blockhash, sizeof(blockhash));
sha256_done(&sha, &res);
printf("%02x%02x%02x\n", res.u.u8[0], res.u.u8[1], res.u.u8[2]);
}
/* For example, block 807747 ... 807744 gives flag:
$ ~/devel/cvs/rustyjunk/nodeid-flag 024b9a1fa8e006f1e3937f65f66c408e6da8e1ca728ea43222a7381df1cc449605 00000000000000000001f305cf8a3ae017a4e50468e981516b7c976a78fc5055 000000000000000000034934f36ef2518fbe17b53922cddd6dc849d789f06bf3 000000000000000000048abe38b874abb9a17c1f6cf5113a6e80e9af79743003 000000000000000000051b87289ac16d2a9cb0227602faf1b47e546037b45390
3d7de3
d3a7c1
98d552
fe8ea3
*/
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment