 // Cuckoo Cycle, a memory-hard proof-of-work
 // Copyright (c) 2013-2014 John Tromp
 
-#include <stdlib.h>
+// The edge=trimming time-memory trade-off is due to Dave Anderson:
+// http://da-data.blogspot.com/2014/03/a-public-review-of-cuckoo-cycle.html
+
 #include <stdint.h>
 #include <string.h>
-#include <openssl/sha.h> // if openssl absent, use #include "sha256.c"
-#include <unistd.h>
-#include <stdio.h>
-#include <assert.h>
+#include <openssl/sha.h>
 
 // proof-of-work parameters
-#ifndef SIZEMULT 
-#define SIZEMULT 1
-#endif
 #ifndef SIZESHIFT 
-#define SIZESHIFT 20
-#endif
-
-#define SIZE (SIZEMULT*((unsigned)1<<SIZESHIFT))
-// relatively prime partition sizes, assuming SIZESHIFT >= 2
-#define PARTU (SIZE/2+1)
-#define PARTV (SIZE/2-1)
-
+#define SIZESHIFT 25
+#endif
+#ifndef PROOFSIZE
+#define PROOFSIZE 42
+#endif
+
+#define SIZE (1UL<<SIZESHIFT)
+#define HALFSIZE (SIZE/2)
+#define NODEMASK (HALFSIZE-1)
+
+typedef uint32_t u32;
 typedef uint64_t u64;
+typedef u64 nonce_t;
+typedef u64 node_t;
+
 typedef struct {
   u64 v[4];
 } siphash_ctx;


  for (int s = 0; s < ctx.ncycles; s++)
    printf("% 4d-cycle found at %d:%d%%\n", cycles[s].len, cycles[s].id, cycles[s].pct);
  checkCudaErrors(cudaFree(device_ctx));
  checkCudaErrors(cudaFree(ctx.cycles));
  checkCudaErrors(cudaFree(ctx.cuckoo));
  return 0;
}

  cudaMemcpy(device_ctx, &ctx, sizeof(cuckoo_ctx), cudaMemcpyHostToDevice);

  worker<<<nthreads,1>>>(device_ctx);
  // assert(tp->buckets = (u64 (*)[BUCKETSIZE])calloc(NBUCKETS * BUCKETSIZE, sizeof(u64)));

  shrinkingset *alive = ctx->alive;
  u32 load = 100 * HALFSIZE / CUCKOO_SIZE;
  if (tp->id == 0)
    printf("initial load %d%%\n", load);
  for (u32 round=1; round <= ctx->ntrims; round++)
    trim_edges(tp, round);

  cudaMemcpy(&ctx, device_ctx, sizeof(cuckoo_ctx), cudaMemcpyDeviceToHost);
  cycle *cycles;
  cycles = (cycle *)calloc(maxcycles, sizeof(cycle));
