Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task7,8 #2177

Merged
merged 1 commit into from
Dec 18, 2024
Merged

task7,8 #2177

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions mover/looikaizhi/code/task7/checkin/Move.toml
Original file line number Diff line number Diff line change
@@ -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"

26 changes: 26 additions & 0 deletions mover/looikaizhi/code/task7/checkin/sources/checkin.move
Original file line number Diff line number Diff line change
@@ -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<u8>,
}

fun init(ctx: &mut TxContext){
let vectorAns = VectorAns{
id: object::new(ctx),
vec: vector::empty<u8>(),
};
transfer::share_object(vectorAns);
}

public entry fun getHash(github_id: String, flagStr: String, vectorAns: &mut VectorAns){
let mut v0 = to_bytes(&flagStr);
vector::append<u8>(&mut v0, *github_id.as_bytes());
vectorAns.vec = hash::sha3_256(v0);
}

}

Empty file.
35 changes: 35 additions & 0 deletions mover/looikaizhi/code/task7/task7.ts
Original file line number Diff line number Diff line change
@@ -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);
48 changes: 48 additions & 0 deletions mover/looikaizhi/code/task8/task8.ts
Original file line number Diff line number Diff line change
@@ -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);
Binary file added mover/looikaizhi/images/task7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions mover/looikaizhi/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Loading