Skip to content

Commit

Permalink
Merge pull request #2181 from linqining/task/task7
Browse files Browse the repository at this point in the history
task/task7
  • Loading branch information
Sifotd authored Dec 20, 2024
2 parents ab57498 + 34f11af commit 99fe021
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 2 deletions.
2 changes: 2 additions & 0 deletions mover/linqining/code/task7/call.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sui client call --package 0x914099b4d1b4f5513acc8aaa4fdc1f67578522b81d818f61bae527d590c6d87d --module check_in --function get_flag \
--args 0x9338c2a31b74acfaa28613a4cfcf8878f41bb96d6d52b5288760d5261a2bf897 linqining 0xc8dcd54baa7724177593a9f70598a09ae6a4286f996542e058f248209db08147 0x8 --gas-budget 3000000
26 changes: 26 additions & 0 deletions mover/linqining/code/task7/check_in/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "CADBA560F959A19B76FB7025DC2079CCDB1E948BF9F3E73E0C1FEF81CA1F31FB"
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.1"
edition = "2024.beta"
flavor = "sui"
37 changes: 37 additions & 0 deletions mover/linqining/code/task7/check_in/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "check_in"
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 = "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"

76 changes: 76 additions & 0 deletions mover/linqining/code/task7/check_in/sources/check_in.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
module check_in::check_in;
use std::ascii::{String, string};
use std::bcs;
use std::hash::sha3_256;
use std::vector;
use sui::event;
use sui::object;
use sui::random;
use sui::random::Random;
use sui::transfer::share_object;
use sui::tx_context::{Self, TxContext};

const ESTRING: u64 = 0;

public struct Flag has copy, drop {
sender: address,
flag: bool,
ture_num: u64,
github_id: String
}

public struct FlagString has key {
id: UID,
str: String,
ture_num: u64
}

fun init(ctx: &mut TxContext) {
let flag_str = FlagString {
id: object::new(ctx),
str: string(b"LetsMoveCTF"),
ture_num: 0
};
share_object(flag_str);
}


entry fun get_flag(
flag: vector<u8>,
github_id: String,
flag_str: &mut FlagString,
rand: &Random,
ctx: &mut TxContext
) {
let mut bcs_flag = bcs::to_bytes(&flag_str.str);
vector::append<u8>(&mut bcs_flag, *github_id.as_bytes());

assert!(flag == sha3_256(bcs_flag), ESTRING);

flag_str.str = getRandomString(rand, ctx);

flag_str.ture_num = flag_str.ture_num + 1;

event::emit(Flag {
sender: tx_context::sender(ctx),
flag: true,
ture_num: flag_str.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<u8> = 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)
}
Binary file not shown.
19 changes: 19 additions & 0 deletions mover/linqining/code/task7/check_in/sources/decode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::io::{self, Write};
use std::bcs;

fn main() {
let str = r">1}y^:jDt$C}M\6(r.-F";
let strbyte = str.to_bytes();
let unescaped_string = unescape(string_with_escapes).unwrap();
let bcs_flag = unescaped_string.bytes();
let github_id = b"linqining";

vector::append<u8>(&mut bcs_flag, github_id);
print(&bcs_flag);
let str: std::string::String = std::string::utf8(bcs_flag);
// print(&str);

let data = sha3_256(bcs_flag);
// let databyte = bcs::to_bytes(&data);
print!(data)
}
18 changes: 18 additions & 0 deletions mover/linqining/code/task7/check_in/tests/check_in_tests.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#[test_only]
module check_in::check_in_tests;
// uncomment this line to import the module
use check_in::check_in;

const ENotImplemented: u64 = 0;

#[test,]
fun check_in() {
check_in::check_in::get_flag()
}


// #[test, expected_failure(abort_code = ::check_in::check_in_tests::ENotImplemented)]
// fun test_check_in_fail() {
// abort ENotImplemented
// }

Binary file added mover/linqining/images/cli_call.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions mover/linqining/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
- [x] save hash : Cssqi4bop5TejjA8AiV9bmEryy3tThXqpWguT1qmxqt3

## 07 Move CTF Check In
- [] CLI call 截图 : ![截图](./images/你的图片地址)
- [] flag hash :
- [x] CLI call 截图 : ![截图](./images/cli_call.png)
- [x] flag hash : 7SW1NGXYLjPuLLbxrHe4ceDwDe1xjcuvEBCjub11GMYG

## 08 Move CTF Lets Move
- [] proof :
Expand Down

0 comments on commit 99fe021

Please sign in to comment.