C 602: Capture the Ether Warmup: Choose a Nickname (15 pts.)

What You Need

Purpose

To learn Solidity hacking.

Preparation

You should already have the MetaMask browser extension, some Ropsten test Eth, and have completed the first Capture The Ether challenge.

Choose a Nickname

In your browser, go to: https://capturetheether.com/challenges/warmup/nickname/

You see the "Choose a nickname" page, as shown below.

Look at the Solidity code at the bottom.

We'll only use the first contract, CaptureTheEther.

This contract has only one function, setNickname, which takes a nickname in "bytes32" format.

On the left side, click the "Begin Challenge" button.

A MetaMask box pops up. Click Confirm.

After a few seconds, the left side of the page shows your contract's address, as shown below.

Note: for this challenge, don't use your contract's address. Use the address shown on the right side, outlined in green in the image below.

Using Remix

You should already have a Remix tab open. If you don't, open a new browser tab and go to

http://remix.ethereum.org/

Pasting in the Solidity Code

On the left side, in the FILE EXPLORERS pane, click the "File explorers" icon, outlined in green in the image below.

Right-click the contracts folder and click "New File".

Name the new file nickname.sol

Paste in the code for the first contract on the "Choose a nickname" page, as shown below.

On the left side of the Remix page, click the Compile icon, outlined in red in the image above.

Click the "Compile nickname.sol" button.

Then click the Deploy icon, outlined in light blue in the image above.

Connecting to the Deployed Contract

In the Remix page, on the left, in the "DEPLOY & RUN TRANSACTIONS" pane, make sure the ENVIRONMENT is set to "Injected Web3".

On the "Choose a nickname" page, copy the address on the right side of the page, ending in "4fee".

In the Remix page, in the lower portion of the "DEPLOY & RUN TRANSACTIONS" pane, paste that address into the box next to the "At Address" button, outlined in red in the image below.

Click the "At Address button.

Calling the setNickname Function

In the Remix page, at the bottom of the "DEPLOY & RUN TRANSACTIONS" pane, expand the "CAPTURETHEETHER AT ..." container.

In the field next to the orange setNickname button, enter your name, as outlined in green in the image below.

Click the orange setNickname button.

At the lower right, an error message appears, saying "Error encoding arguments", outlined in green in the image below.

Formatting Your Name Correctly

The nickname is a "bytes32" value. This means it must be a 32-byte hexadecimal value, prefixed by "0x". This results in a total of 66 characters.

You can convert your name on this page:

https://www.testcoins.io/str-bytes32

as shown below:

Setting your Nickname

Paste the bytes32 version of your name into the field next to the orange setNickname button, and click the orange setNickname button.

A Metamask box pops up. Click Confirm.

When the function call succeeds, you'll see a green check mark in the lower right pane of the Remix window, outlined in green in the image below.

Completing the Challenge

On the "Call me" page, on the left side, click the "Check Solution" button.

A MetaMask box pops up. Click Confirm. You win, and a little dancing figure appears on the lower left, as shown below.

Flag C 602.1 GIF Name (15 pts)

In your browser, on the top right, right-click your name, outlined in red in the image above, and click Inspect.

The flag is the filename of this GIF image, covered by a green rectangle in the image below.

Sources

Ethereum Smart Contract Development | Capture the Ether Problem 1 & 2
Capture the Ether (Part 1 of 3): Exploring Ethereum Lottery Vulnerabilities
Capture The Ether: token sale
Capture The Ether: token whale
Solidity array overflow

Posted 5-20-22 by Sam Bowne