[bisq-network/bisq] Provide ASIC resistant PoW scheme for BSQ swaps (PR #5858)

Steven Barclay notifications at github.com
Sat Dec 4 07:31:21 CET 2021


@stejbac commented on this pull request.



> +        return CompletableFuture.supplyAsync(() -> {
+            long ts = System.currentTimeMillis();
+            byte[] solution = new Equihash(90, 5, difficulty).puzzle(challenge).findSolution().serialize();
+            long counter = Longs.fromByteArray(Arrays.copyOf(solution, 8));
+            var proofOfWork = new ProofOfWork(solution, counter, challenge, log2Difficulty,
+                    System.currentTimeMillis() - ts, getVersion());
+            log.info("Completed minting proofOfWork: {}", proofOfWork);
+            return proofOfWork;
+        });
+    }
+
+    @Override
+    public byte[] getChallenge(String itemId, String ownerId) {
+        checkArgument(!StringUtils.contains(itemId, '\0'));
+        checkArgument(!StringUtils.contains(ownerId, '\0'));
+        return Hash.getSha256Hash(checkNotNull(itemId) + "\0" + checkNotNull(ownerId));

Perhaps it would be better to do something like the following:

>◌◌◌◌public◌byte[]◌getChallenge(String◌itemId,◌String◌ownerId)◌{
>◌◌◌◌◌◌◌◌String◌escapedItemId◌=◌itemId.replace("◌", "◌◌");
>◌◌◌◌◌◌◌◌String◌escapedOwnerId◌=◌ownerId.replace("◌", "◌◌");
>◌◌◌◌◌◌◌◌return◌Hash.getSha256Hash(escapedItemId◌+◌"◌"◌+◌escapedOwnerId);
>◌◌◌◌}

That way `getChallenge` accepts all pairs of non-null string arguments and it is collision-resistant over them.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/bisq-network/bisq/pull/5858#discussion_r762392990
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bisq.network/pipermail/bisq-github/attachments/20211203/fbb203a6/attachment.htm>


More information about the bisq-github mailing list