Blockchain

Name
Solves

solantol 🥉

10

solantol 2

7

solantol 3

7

solantol

Description

Author: dimas

Challenge solana pertama di TCP1P :)

Connect: http://playground.tcp1p.team:7752

Initial Analysis

We are given a Solana smart contract

use anchor_lang::prelude::*;

declare_id!("CZY19xitzMjHWa25P3rzWsz3BLuBRpBnby2FQ7LTE4mQ");

#[program]
pub mod setup {
    use super::*;

    pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
        let solved_account = &mut ctx.accounts.solved_account;
        solved_account.solved = false;
        Ok(())
    }

    pub fn solve(ctx: Context<Solve>) -> Result<()> {
        let solved_account = &mut ctx.accounts.solved_account;
        solved_account.solved = true;
        Ok(())
    }

    pub fn is_solved(ctx: Context<IsSolved>) -> Result<bool> {
        let solved_account = &ctx.accounts.solved_account;
        Ok(solved_account.solved)
    }
}

#[derive(Accounts)]
pub struct Initialize<'info> {
    #[account(
        init,
        payer = user,
        space = 8 + 1,
    )]
    pub solved_account: Account<'info, SolvedState>,
    #[account(mut)]
    pub user: Signer<'info>,
    pub system_program: Program<'info, System>,
}

#[derive(Accounts)]
pub struct Solve<'info> {
    #[account(mut)]
    pub solved_account: Account<'info, SolvedState>,
}

#[derive(Accounts)]
pub struct IsSolved<'info> {
    pub solved_account: Account<'info, SolvedState>,
}

#[account]
pub struct SolvedState {
    pub solved: bool,
}

The objective is simple, we just need to call the solve function to flip the isSolved variable to True.

Exploitation

Basically we need to call the solve function

First, we need to sets up the credentials given from the server. Then we define the program interface (IDL) so we can match it with the real contract. Then in here:

We just call the solve function. Then it is solved!

Solved!

solantol 2

Description

Author: dimas

Challenge solana kedua di TCP1P :)

Connect: http://playground.tcp1p.team:8752

Initial Analysis

We are given yet another Solana smart contract:

The vulnerability lies in:

The program stores the password as a plaintext string. Since all Solana account data is public. We can read it from the VaultState.

Then to solve it, we need to call solve, with the argument, of the password.

Exploitation

Well because the password is stored as plaintext on the vault. We can just read the vault, get the password and submit it to the solve function. We sets up the IDL just like before to make our life easier.

Solved!

solantol 3

Description

Author: dimas

Challenge solana ke-tiga di TCP1P :)

Connect: http://playground.tcp1p.team:9752

Initial Analysis

We are given yet another Solana smart contract:

The vault password here is hashed. But there's a logic error here:

It checks if the hash result of the passed password is equal to the accounts password_hash, where it should have been compared to vault.password_hash. With this logic, we can just create an account, with a known password. Then pass it to the attempt_solve method.

Exploitation

The exploit is simple enough, i don't think i can provide much explanation:

First we create a new account by calling initialize function on the contract:

Then we just call the attempt_solve function with our known password to solve it:

isSolved = True
Solved!

Last updated