> For the complete documentation index, see [llms.txt](https://miraicantsleep.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://miraicantsleep.gitbook.io/notes/ctf/cyber-jawara-international-2024/intro-to-eth.md).

# Intro to ETH

## Description

> Author: Chovid99\
> Welcome to the world of Ethereum smart contracts! This warmup challenge is designed to introduce newcomers to the basics of interacting with Ethereum blockchain technology. You'll get hands-on experience with a simple smart contract, learning how to read and interact with it. No prior blockchain knowledge is required – just bring your curiosity and problem-solving skills. Are you ready to take your first steps into the exciting realm of decentralized applications?
>
> <http://152.42.183.87:59117>

We are given a file `Setup.sol`

```solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

contract Setup {
    bool private solved;

    constructor() payable {
    }

    function solve(bytes calldata secret) public {
        require(keccak256(secret) == keccak256(bytes("CJ_INTERNATIONAL_2024-CHOVID99")), "Wrong password");
        solved = true;
    }

    function isSolved() external view returns (bool) {
        return solved;
    }
}
```

Looking at the source code above, there are some functions we can interact with.

## Functions

### solve(bytes calldata secret)

```solidity
function solve(bytes calldata secret) public {
    require(keccak256(secret) == keccak256(bytes("CJ_INTERNATIONAL_2024-CHOVID99")), "Wrong password");
    solved = true;
}
```

This function takes a `bytes` parameter called secret. Then it uses the `keccak256` hash to match the hash of secret with the hash of the string `CJ_INTERNATIONAL_2024-CHOVID99`, if it matches, then it flips the variable `solved` to true.

### isSolved()

```solidity
function isSolved() external view returns (bool) {
    return solved;
}
```

This function will return a true/false boolean value. If it returns true, then the challenge is solved and otherwise if it returns false, the challenge is not solved.

### Ethernet Launcher

We were also given a web to launch our private blockchain server.

<figure><img src="/files/OUdqyiCiOT9vhTFLfS6b" alt=""><figcaption><p>Ethernet Launcher</p></figcaption></figure>

## Solve

To solve this, it is very straightforward. We just need to do `cast send` (because we are altering the blockchain state and we need our private key to do that) to the `solve` function with the parameter `CJ_INTERNATIONAL_2024-CHOVID99` converted to hex.

We can use the help of foundry to do that.

First we call the solve function.

```solidity
cast send 0xA2Fa474F768F08e202294763b23B96c484763EB8 "solve(bytes)" 0x434a5f494e5445524e4154494f4e414c5f323032342d43484f5649443939 --rpc-url http://152.42.183.87:59117/ca1cf1a0-82e8-4f63-b573-61206fc3b88d --private-key 0x3359d77020acd3a10f9b5503824f8866c67f769398a2891b37dfecaf9ac2fdda
```

<figure><img src="/files/sMITJhpaKWrHfuqZO56J" alt=""><figcaption><p>Successful transaction</p></figcaption></figure>

And we check if our challenge is solved by calling the `isSolved()` function.

```solidity
cast call 0xA2Fa474F768F08e202294763b23B96c484763EB8 "isSolved()(bool)" --rpc-url http://152.42.183.87:59117/ca1cf1a0-82e8-4f63-b573-61206fc3b88d
```

<figure><img src="/files/id6VEiys1UZ7rmqWMUtG" alt=""><figcaption></figcaption></figure>

And with that, our challenge is solved!

<figure><img src="/files/7eUPX4sWD00Ofr6LWh6N" alt=""><figcaption><p>Solved!</p></figcaption></figure>

{% hint style="success" %}
***Flag: CJ{m0mMy\_I\_s0lv3d\_bL0cKch41n\_ch4ll3ng3zZ}***
{% endhint %}
