Skip to content

Commit

Permalink
task7+task8
Browse files Browse the repository at this point in the history
  • Loading branch information
lizhe committed Nov 15, 2024
1 parent 5a7b933 commit b40b6fd
Show file tree
Hide file tree
Showing 16 changed files with 466 additions and 4 deletions.
34 changes: 34 additions & 0 deletions mover/lizhecome/code/task7/check_in_task/Move.lock
Original file line number Diff line number Diff line change
@@ -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"
37 changes: 37 additions & 0 deletions mover/lizhecome/code/task7/check_in_task/Move.toml
Original file line number Diff line number Diff line change
@@ -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 ([email protected])", "John Snow ([email protected])"]

[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"

Original file line number Diff line number Diff line change
@@ -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<u8>
}

public struct GetCheckinString has drop,copy{
sender:address,
checkin_string:vector<u8>,
github_id:String
}

fun init(ctx:& mut TxContext){
let checkin_string = CheckinString {
id: object::new(ctx),
key: vector::empty<u8>(),
};
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<u8>(&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
});
}
Original file line number Diff line number Diff line change
@@ -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
}
*/
43 changes: 43 additions & 0 deletions mover/lizhecome/code/task8/gen_proof/Move.lock
Original file line number Diff line number Diff line change
@@ -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"
38 changes: 38 additions & 0 deletions mover/lizhecome/code/task8/gen_proof/Move.toml
Original file line number Diff line number Diff line change
@@ -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 ([email protected])", "John Snow ([email protected])"]

[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"

34 changes: 34 additions & 0 deletions mover/lizhecome/code/task8/gen_proof/sources/gen_proof.move
Original file line number Diff line number Diff line change
@@ -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<u8>
}


/// 初始化 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)
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

42 changes: 42 additions & 0 deletions mover/lizhecome/code/task8/get_proof.py
Original file line number Diff line number Diff line change
@@ -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}")
34 changes: 34 additions & 0 deletions mover/lizhecome/code/task8/lets_move/Move.lock
Original file line number Diff line number Diff line change
@@ -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"
37 changes: 37 additions & 0 deletions mover/lizhecome/code/task8/lets_move/Move.toml
Original file line number Diff line number Diff line change
@@ -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 ([email protected])", "John Snow ([email protected])"]

[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"

Loading

0 comments on commit b40b6fd

Please sign in to comment.