diff --git a/mover/lizhecome/code/task7/check_in_task/Move.lock b/mover/lizhecome/code/task7/check_in_task/Move.lock new file mode 100644 index 000000000..a092855f0 --- /dev/null +++ b/mover/lizhecome/code/task7/check_in_task/Move.lock @@ -0,0 +1,34 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "38F91517243B65BA1C6310088E81D2A9961A2D05092A4621F67E633D77AE81BF" +deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[move.toolchain-version] +compiler-version = "1.37.2" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.testnet] +chain-id = "4c78adac" +original-published-id = "0x26a47876f0640ad190679ad0307aa60c77b6009b214f867ef7a24be1f084d51d" +latest-published-id = "0x26a47876f0640ad190679ad0307aa60c77b6009b214f867ef7a24be1f084d51d" +published-version = "1" diff --git a/mover/lizhecome/code/task7/check_in_task/Move.toml b/mover/lizhecome/code/task7/check_in_task/Move.toml new file mode 100644 index 000000000..852f66f45 --- /dev/null +++ b/mover/lizhecome/code/task7/check_in_task/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "check_in_task" +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] +check_in_task = "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/lizhecome/code/task7/check_in_task/sources/check_in_task.move b/mover/lizhecome/code/task7/check_in_task/sources/check_in_task.move new file mode 100644 index 000000000..52b57ac79 --- /dev/null +++ b/mover/lizhecome/code/task7/check_in_task/sources/check_in_task.move @@ -0,0 +1,37 @@ +/// Module: check_in_task +module check_in_task::check_in_task; +use std::ascii::{String,string}; +use sui::transfer::share_object; +use std::bcs; +use sui::event; +use std::hash::sha3_256; + +public struct CheckinString has key { + id: UID, + key: vector +} + +public struct GetCheckinString has drop,copy{ + sender:address, + checkin_string:vector, + github_id:String +} + +fun init(ctx:& mut TxContext){ + let checkin_string = CheckinString { + id: object::new(ctx), + key: vector::empty(), + }; + share_object(checkin_string); +} + +entry fun getCheckinString(github_id:String, check_string:&mut CheckinString, flagString:String, ctx:&TxContext){ + let mut bcs_flag = bcs::to_bytes(&flagString); + vector::append(&mut bcs_flag, *github_id.as_bytes()); + check_string.key =sha3_256(bcs_flag); + event::emit(GetCheckinString { + sender: ctx.sender(), + checkin_string: check_string.key, + github_id + }); +} \ No newline at end of file diff --git a/mover/lizhecome/code/task7/check_in_task/tests/check_in_task_tests.move b/mover/lizhecome/code/task7/check_in_task/tests/check_in_task_tests.move new file mode 100644 index 000000000..6c0013f55 --- /dev/null +++ b/mover/lizhecome/code/task7/check_in_task/tests/check_in_task_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module check_in_task::check_in_task_tests; +// uncomment this line to import the module +// use check_in_task::check_in_task; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_check_in_task() { + // pass +} + +#[test, expected_failure(abort_code = ::check_in_task::check_in_task_tests::ENotImplemented)] +fun test_check_in_task_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/lizhecome/code/task8/gen_proof/Move.lock b/mover/lizhecome/code/task8/gen_proof/Move.lock new file mode 100644 index 000000000..faa02479d --- /dev/null +++ b/mover/lizhecome/code/task8/gen_proof/Move.lock @@ -0,0 +1,43 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "FD7281619B1D5F46D8575E8C43537192F9D6B8E63A32E0E4989C0014A7678C17" +deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" +dependencies = [ + { id = "Sui", name = "Sui" }, + { id = "lets_move", name = "lets_move" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[[move.package]] +id = "lets_move" +source = { local = "../lets_move" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[move.toolchain-version] +compiler-version = "1.37.2" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.testnet] +chain-id = "4c78adac" +original-published-id = "0x1df6e78eb65ec032e83bf7a7070cd5f41f1d72e9c52fbdad3cddc18590fc3325" +latest-published-id = "0x1df6e78eb65ec032e83bf7a7070cd5f41f1d72e9c52fbdad3cddc18590fc3325" +published-version = "1" diff --git a/mover/lizhecome/code/task8/gen_proof/Move.toml b/mover/lizhecome/code/task8/gen_proof/Move.toml new file mode 100644 index 000000000..3407415b4 --- /dev/null +++ b/mover/lizhecome/code/task8/gen_proof/Move.toml @@ -0,0 +1,38 @@ +[package] +name = "gen_proof" +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" } +lets_move = { local = "../lets_move" } +# 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] +gen_proof = "0x0" +random = "0x8" + +# 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/lizhecome/code/task8/gen_proof/sources/gen_proof.move b/mover/lizhecome/code/task8/gen_proof/sources/gen_proof.move new file mode 100644 index 000000000..97f54a231 --- /dev/null +++ b/mover/lizhecome/code/task8/gen_proof/sources/gen_proof.move @@ -0,0 +1,34 @@ +/* +/// Module: gen_proof +module gen_proof::gen_proof; +*/ +module gen_proof::gen_proof { + use std::ascii::{String, string}; + use std::hash; + use sui::event; + use sui::bcs; + use sui::random; + use sui::transfer::share_object; + use sui::tx_context::{TxContext, sender}; + use sui::random::Random; + use lets_move::lets_move::Challenge; + + + + public struct ChallengeBytes has copy, drop { + object_bytes :vector + } + + + /// 初始化 Challenge 对象 + public fun init_challenge(ctx: &mut TxContext) { + + } + + + public entry fun get_challenge_bytes(challenge: &Challenge,ctx:&TxContext){ + event::emit(ChallengeBytes { + object_bytes:bcs::to_bytes(challenge) + }); + } +} \ No newline at end of file diff --git a/mover/lizhecome/code/task8/gen_proof/tests/gen_proof_tests.move b/mover/lizhecome/code/task8/gen_proof/tests/gen_proof_tests.move new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/mover/lizhecome/code/task8/gen_proof/tests/gen_proof_tests.move @@ -0,0 +1 @@ + diff --git a/mover/lizhecome/code/task8/get_proof.py b/mover/lizhecome/code/task8/get_proof.py new file mode 100644 index 000000000..57a6f6a98 --- /dev/null +++ b/mover/lizhecome/code/task8/get_proof.py @@ -0,0 +1,42 @@ +import hashlib +import random + +def sha3_256(data: bytes) -> bytes: + """计算 sha3_256 哈希""" + return hashlib.sha3_256(data).digest() + +def find_proof(sender_bytes: bytes, challenge_bytes: bytes, difficulity: int = 3) -> list: + """寻找满足条件的 proof 并返回字节数组""" + while True: + # 随机生成 8 字节的 proof + proof = random.randbytes(8) + + # 构建 full_proof = proof + sender_bytes + challenge_bytes + full_proof = proof + sender_bytes + bytes(challenge_bytes) + + # 计算 sha3_256 哈希 + hash_result = sha3_256(full_proof) + + # 计算前 difficulity 个字节的前缀和 + prefix_sum = sum(hash_result[i] for i in range(difficulity)) + + # 满足 prefix_sum == 0 的条件 + if prefix_sum == 0: + print(f"Proof found (byte array): {[b for b in proof]}") + return [b for b in proof] + +# 将 sender 转换为字节数组(16 进制字符串转为 bytes) +sender_hex = "43d945f82670c017d1989a6613612092e07560dcf88580f6649c4c0b7aa54e44" +sender_bytes = bytes.fromhex(sender_hex) + +# 使用提供的 challenge_bytes +challenge_bytes = [ + 25, 231, 108, 165, 4, 197, 165, 250, 94, 33, 74, 69, 252, 166, 192, 88, + 23, 27, 163, 51, 246, 218, 137, 123, 130, 115, 16, 148, 80, 77, 90, 185, + 24, 53, 123, 75, 62, 115, 100, 82, 75, 76, 48, 74, 44, 60, 65, 40, 94, 45, + 126, 115, 77, 126, 95, 121, 51, 3, 0, 0, 0, 0, 0, 0, 0, 88, 0, 0, 0, 0, 0, 0, 0 +] + +# 计算 proof 并输出为字节数组 +proof = find_proof(sender_bytes, challenge_bytes) +print(f"Calculated proof as byte array: {proof}") \ No newline at end of file diff --git a/mover/lizhecome/code/task8/lets_move/Move.lock b/mover/lizhecome/code/task8/lets_move/Move.lock new file mode 100644 index 000000000..200f3a7d9 --- /dev/null +++ b/mover/lizhecome/code/task8/lets_move/Move.lock @@ -0,0 +1,34 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "786B91A5B97E30CFE4109DB806C7FDAA208AD34906C77AB899770D4D0AEB5DB1" +deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[move.toolchain-version] +compiler-version = "1.37.2" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.testnet] +chain-id = "4c78adac" +original-published-id = "0x097a3833b6b5c62ca6ad10f0509dffdadff7ce31e1d86e63e884a14860cedc0f" +latest-published-id = "0x097a3833b6b5c62ca6ad10f0509dffdadff7ce31e1d86e63e884a14860cedc0f" +published-version = "1" diff --git a/mover/lizhecome/code/task8/lets_move/Move.toml b/mover/lizhecome/code/task8/lets_move/Move.toml new file mode 100644 index 000000000..2c2ad6ae1 --- /dev/null +++ b/mover/lizhecome/code/task8/lets_move/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "lets_move" +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] +lets_move = "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/lizhecome/code/task8/lets_move/sources/lets_move.move b/mover/lizhecome/code/task8/lets_move/sources/lets_move.move new file mode 100644 index 000000000..7fd6fd550 --- /dev/null +++ b/mover/lizhecome/code/task8/lets_move/sources/lets_move.move @@ -0,0 +1,87 @@ +module lets_move::lets_move { + use std::ascii::{String, string}; + use std::hash; + use sui::event; + use sui::bcs; + use sui::random; + use sui::random::Random; + use sui::transfer::share_object; + + const EPROOF: u64 = 0; + + public struct Flag has copy, drop { + sender: address, + flag: bool, + ture_num: u64, + github_id: String + } + + public struct Challenge has key { + id: UID, + str: String, + difficulity: u64, + ture_num: u64 + } + + fun init(ctx: &mut TxContext) { + let flag_str = Challenge { + id: object::new(ctx), + str: string(b"LetsMoveCTF"), + difficulity: 3, + ture_num: 0, + }; + share_object(flag_str); + } + + + entry fun get_flag( + proof: vector, + github_id: String, + challenge: &mut Challenge, + rand: &Random, + ctx: &mut TxContext + ) { + let mut full_proof: vector = vector::empty(); + vector::append(&mut full_proof, proof); + vector::append(&mut full_proof, tx_context::sender(ctx).to_bytes()); + vector::append(&mut full_proof, bcs::to_bytes(challenge)); + + let hash: vector = hash::sha3_256(full_proof); + + let mut prefix_sum: u32 = 0; + let mut i: u64 = 0; + while (i < challenge.difficulity) { + prefix_sum = prefix_sum + (*vector::borrow(&hash, i) as u32); + i = i + 1; + }; + + assert!(prefix_sum == 0, EPROOF); + + challenge.str = getRandomString(rand, ctx); + challenge.ture_num = challenge.ture_num + 1; + + event::emit(Flag { + sender: tx_context::sender(ctx), + flag: true, + ture_num: challenge.ture_num, + github_id + }); + } + + + fun getRandomString(rand: &Random, ctx: &mut TxContext): String { + let mut gen = random::new_generator(rand, ctx); + + let mut str_len = random::generate_u8_in_range(&mut gen, 4, 30); + + let mut rand: vector = b""; + while (str_len != 0) { + let rand_num = random::generate_u8_in_range(&mut gen, 34, 126); + vector::push_back(&mut rand, rand_num); + str_len = str_len - 1; + }; + + string(rand) + } +} + diff --git a/mover/lizhecome/code/task8/lets_move/tests/lets_move_tests.move b/mover/lizhecome/code/task8/lets_move/tests/lets_move_tests.move new file mode 100644 index 000000000..4febaae1a --- /dev/null +++ b/mover/lizhecome/code/task8/lets_move/tests/lets_move_tests.move @@ -0,0 +1,19 @@ +/* +#[test_only] +module lets_move::lets_move_tests { + // uncomment this line to import the module + // use lets_move::lets_move; + + const ENotImplemented: u64 = 0; + + #[test] + fun test_lets_move() { + // pass + } + + #[test, expected_failure(abort_code = ::lets_move::lets_move_tests::ENotImplemented)] + fun test_lets_move_fail() { + abort ENotImplemented + } +} +*/ diff --git a/mover/lizhecome/images/task7.png b/mover/lizhecome/images/task7.png new file mode 100644 index 000000000..717687799 Binary files /dev/null and b/mover/lizhecome/images/task7.png differ diff --git a/mover/lizhecome/images/task8.png b/mover/lizhecome/images/task8.png new file mode 100644 index 000000000..77e27ee46 Binary files /dev/null and b/mover/lizhecome/images/task8.png differ diff --git a/mover/lizhecome/readme.md b/mover/lizhecome/readme.md index d91d87981..0e4ade5ed 100644 --- a/mover/lizhecome/readme.md +++ b/mover/lizhecome/readme.md @@ -49,9 +49,10 @@ - [x] save hash : 3BUnnzzjgi7nzZ1q53nLgAhWYWzdYb7Ststp6GciPtE5 ## 07 Move CTF Check In -- [] CLI call 截图 : ![截图](./images/你的图片地址) -- [] flag hash : +- [x] CLI call 截图 : ![截图](./images/task7.png) +- [x] flag hash :En5nJpBQ1QUNtux8cF25WbZDRsfubqfyBfuDhpAew8Rp ## 08 Move CTF Lets Move -- [] proof : -- [] flag hash : +- [x] proof :证明方法见mover/lizhecome/code/task8/get_proof.py,以及move项目gen_proof + CLI call 截图 : ![截图](./images/task8.png) +- [x] flag hash : DfyvNhuyZk6wk17B2Hwz3NUWLQ6Abndp2Xou2uaNxb7X