Skip to content

Commit

Permalink
task 8
Browse files Browse the repository at this point in the history
  • Loading branch information
dop0 committed Dec 7, 2024
1 parent 3b38c05 commit c0bd1a6
Show file tree
Hide file tree
Showing 5 changed files with 398 additions and 2 deletions.
41 changes: 41 additions & 0 deletions mover/sahab328/code/task8/get_flag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { getFullnodeUrl, SuiClient } from "@mysten/sui/client";
import { bcs, toHex, fromHex, fromBase64 } from '@mysten/bcs';
import { createHash, getRandomValues } from "crypto";


async function get_flag(sender: string) {
const obj_id = "0x19e76ca504c5a5fa5e214a45fca6c058171ba333f6da897b82731094504d5ab9";
const client = new SuiClient({ url: getFullnodeUrl("testnet") });

const obj = await client.getObject({
id: obj_id,
options: {
showBcs: true,
showContent: true,
}
});
const content = obj.data!.content as any;
const difficulty = content.fields['difficulity'];

const Address = bcs.bytes(32).transform({
input: (val: string) => fromHex(val),
output: (val) => toHex(val),
});
const sender_bcs_bytes = Address.serialize(sender).toBytes();
const obj_bcs_bytes = fromBase64((obj.data!.bcs as any)["bcsBytes"])
const proof_length = difficulty * 2;
const proof_bytes = new Uint8Array(proof_length);
while(true) {
getRandomValues(proof_bytes);
const buffer = Buffer.concat([proof_bytes, sender_bcs_bytes, obj_bcs_bytes]);
const hash = createHash('sha3-256').update(buffer).digest();
let prefix_sum = 0;
for (let k = 0; k < difficulty; ++k) {
prefix_sum += hash[k];
}
if (prefix_sum == 0) {
console.log(toHex(proof_bytes));
break;
}
}
}
15 changes: 15 additions & 0 deletions mover/sahab328/code/task8/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "task7",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@mysten/sui": "^1.16.0"
}
}
230 changes: 230 additions & 0 deletions mover/sahab328/code/task8/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c0bd1a6

Please sign in to comment.