diff --git a/mover/looikaizhi/code/task7/checkin/Move.toml b/mover/looikaizhi/code/task7/checkin/Move.toml new file mode 100644 index 000000000..2f96ef63f --- /dev/null +++ b/mover/looikaizhi/code/task7/checkin/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "checkin" +edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move +# license = "" # e.g., "MIT", "GPL", "Apache 2.0" +# authors = ["..."] # e.g., ["Joe Smith (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"] + +[dependencies] +Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } + +# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`. +# Revision can be a branch, a tag, and a commit hash. +# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" } + +# For local dependencies use `local = path`. Path is relative to the package root +# Local = { local = "../path/to" } + +# To resolve a version conflict and force a specific version for dependency +# override use `override = true` +# Override = { local = "../conflicting/version", override = true } + +[addresses] +checkin = "0x0" + +# Named addresses will be accessible in Move as `@name`. They're also exported: +# for example, `std = "0x1"` is exported by the Standard Library. +# alice = "0xA11CE" + +[dev-dependencies] +# The dev-dependencies section allows overriding dependencies for `--test` and +# `--dev` modes. You can introduce test-only dependencies here. +# Local = { local = "../path/to/dev-build" } + +[dev-addresses] +# The dev-addresses section allows overwriting named addresses for the `--test` +# and `--dev` modes. +# alice = "0xB0B" + diff --git a/mover/looikaizhi/code/task7/checkin/sources/checkin.move b/mover/looikaizhi/code/task7/checkin/sources/checkin.move new file mode 100644 index 000000000..8604c0f7f --- /dev/null +++ b/mover/looikaizhi/code/task7/checkin/sources/checkin.move @@ -0,0 +1,26 @@ +module checkin::checkin{ + use std::ascii::String; + use std::hash; + use sui::bcs::to_bytes; + + public struct VectorAns has key{ + id: UID, + vec: vector, + } + + fun init(ctx: &mut TxContext){ + let vectorAns = VectorAns{ + id: object::new(ctx), + vec: vector::empty(), + }; + transfer::share_object(vectorAns); + } + + public entry fun getHash(github_id: String, flagStr: String, vectorAns: &mut VectorAns){ + let mut v0 = to_bytes(&flagStr); + vector::append(&mut v0, *github_id.as_bytes()); + vectorAns.vec = hash::sha3_256(v0); + } + +} + diff --git a/mover/looikaizhi/code/task7/checkin/tests/checkin_tests.move b/mover/looikaizhi/code/task7/checkin/tests/checkin_tests.move new file mode 100644 index 000000000..e69de29bb diff --git a/mover/looikaizhi/code/task7/task7.ts b/mover/looikaizhi/code/task7/task7.ts new file mode 100644 index 000000000..36466a30e --- /dev/null +++ b/mover/looikaizhi/code/task7/task7.ts @@ -0,0 +1,35 @@ +import { getFullnodeUrl, SuiClient } from '@mysten/sui/client'; +import { createHash } from 'crypto'; +import { bcs } from '@mysten/sui/bcs'; + +const rpcUrl = getFullnodeUrl('testnet'); +const client = new SuiClient({url: rpcUrl}); +const flagStringId = '0xc8dcd54baa7724177593a9f70598a09ae6a4286f996542e058f248209db08147'; +const githubID = 'looikaizhi'; + +async function getFlagStringData() { + const flagObject = await client.getObject({id: flagStringId, options: {showContent: true}}); + const content = flagObject.data?.content; + console.log(content); + return content.fields.str; +} + +async function calVector() { + const flagStr = await getFlagStringData(); + // 使用BCS序列化 + const flagStrBytes = bcs.String.serialize(flagStr).toBytes(); + const githubBytes = Buffer.from(githubID,'utf-8'); + // 字符串字节添加在BCS后面 + const combinedBytes = new Uint8Array(flagStrBytes.length + githubBytes.length); + combinedBytes.set(flagStrBytes, 0); + combinedBytes.set(githubBytes, flagStrBytes.length); + // 测试 + console.log(flagStrBytes); + console.log(githubBytes); + console.log(combinedBytes); + const hash1 = createHash('sha3-256').update(combinedBytes).digest(); + console.log('最终哈希值:', JSON.stringify(Array.from(hash1))); + console.log("hash: ", "0x" + hash1.toString('hex')); +} + +calVector().catch(console.error); \ No newline at end of file diff --git a/mover/looikaizhi/code/task8/task8.ts b/mover/looikaizhi/code/task8/task8.ts new file mode 100644 index 000000000..b4aa4f1ec --- /dev/null +++ b/mover/looikaizhi/code/task8/task8.ts @@ -0,0 +1,48 @@ +import {getFullnodeUrl, SuiClient} from '@mysten/sui/client'; +import {fromBase64} from '@mysten/bcs'; +import { bcs } from '@mysten/sui/bcs'; +import {createHash} from 'crypto'; + +const rpcUrl = getFullnodeUrl('testnet'); +const client = new SuiClient({url: rpcUrl}); +const challengeID = '0x19e76ca504c5a5fa5e214a45fca6c058171ba333f6da897b82731094504d5ab9'; +const address = '0x0234bddfc4deb68aaddd61b79a5857c1b0a29268a3b2e9d162bc13f45be60e1a'; +// const githubID = 'looikaizhi'; + +async function findAnswer(){ + const challenge = await client.getObject({id : challengeID, options:{showBcs:true, showContent: true}}); + console.log(challenge.data); + const data = challenge.data; + const content = data?.content; + console.log(content); + + const addressBytes = bcs.Address.serialize(address).toBytes(); + const challengeBytes1 = fromBase64((data!.bcs as any)['bcsBytes']); + let nonce = 0; + do { + const proofBytes = bcs.U64.serialize(nonce).toBytes(); + const combinedBytes = new Uint8Array(proofBytes.length + addressBytes.length + challengeBytes1.length); + combinedBytes.set(proofBytes, 0); + combinedBytes.set(addressBytes, proofBytes.length); + combinedBytes.set(challengeBytes1, proofBytes.length + addressBytes.length); + + const hash = Array.from(createHash('sha3-256').update(combinedBytes).digest()); + let prefix_sum = 0; + let i = 0; + while(i < content?.fields.difficulity){ + prefix_sum = prefix_sum + hash[i]; + i += 1; + } + if(prefix_sum == 0){ + console.log(`第${nonce}次成功:`, JSON.stringify(Array.from(proofBytes))); + console.log("proof: ", "0x" + Buffer.from(proofBytes).toString('hex')) + break; + }else{ + nonce++; + //console.log(`第${nonce}次失败:`, proofBytes); + } + + }while(true) +} + +findAnswer().catch(console.error); diff --git a/mover/looikaizhi/images/task7.png b/mover/looikaizhi/images/task7.png new file mode 100644 index 000000000..0dd86e4da Binary files /dev/null and b/mover/looikaizhi/images/task7.png differ diff --git a/mover/looikaizhi/readme.md b/mover/looikaizhi/readme.md index a5d5a92c3..ac405b33d 100644 --- a/mover/looikaizhi/readme.md +++ b/mover/looikaizhi/readme.md @@ -47,9 +47,9 @@ - [x] save hash : `4tXQJ9i55KWrTbp3to2xtSeckkAVTrkbEuq32iY5dLds` ## 07 Move CTF Check In -- [] CLI call 截图 : ![截图](./images/你的图片地址) -- [] flag hash : +- [x] CLI call 截图 : ![截图](./images/task7.png) +- [x] flag hash : `Czc3VuGA8ouXBgV9zjNSjD828ni6zUqK9PYPW9YkctRK` ## 08 Move CTF Lets Move -- [] proof : -- [] flag hash : +- [x] proof : `0x4b8edc0000000000` +- [x] flag hash : `2UPwTETe1trUAEVuGh9tvzRsrUVZF8Rqgw8zGLCsUZZt`