Welcome to Decoding the Blockchain: Cryptography and the Power of Proof! This page will contain all information related to the workshop. Currently, it contains all the prerequisites that need to be set up before the workshop in order to have a functional environment.

Part 1: Prerequisites

The following steps will allow you to setup the development environment we will be using in the workshop. After completing all the steps you should be able to run a simple example generating a sha256 hash. Please make sure you have the setup ready at the time of the workshop.

Software

This software is required to setup the development environment:

Code Editor

VSCode is a popular choice, but you should use your usual editor. We will be programming in C++, so make sure your setup is optimal for the language. This includes installing any needed plugins, extensions or LSPs to ensure you have code completion and error checking. For VSCode you can use the cpp extension, or if you like LSPs, clangd is a good option (you can see an example in my Neovim configuration).

Linux Environment

The development environment is much easier to setup in a Linux system, as all the compilation dependencies are available in default repositories. If you have a native Linux system, then you can skip this step. If not, then there are two options in order to achieve the setup:

  1. WSL (recommended): The Windows Subsystem for Linux is recommended for Windows, as it allows you to run a Linux system your terminal. Then you can execute the bash commands as if you were using Linux. Using a Ubuntu image is recommended.
  2. Docker Container: I will provide a docker container with all the compilation dependencies already installed, so you can use this container as your development environment. However, for an optimal development experience, you will need to be able to connect your editor to the container. Here, Docker Volumes are an option.

Git

We will be using git to clone the workshop code, so make sure it is installed on your system. In Unix-based systems, it should be trivial to install using your package manager of choice. In Windows systems you can download it from the official website. You can also use a Git GUI application if you prefer.

Docker (optional)

If your system is not able to install all the compilation dependencies natively, then you can use the docker container bellow to run the development environment. For this, you will have to install Docker.

Compilation Dependencies

Our development environment depends on the following packages:

  • cmake: C++ build system
  • build-essential: Set of basic tools for compilation, includes the gcc compiler.
  • libsodium: Powerful cryptographic library with a simple API
  • pkg-config: Package compiler and linker, used to link libsodium

Native Install

In most Linux distributions all the dependencies can be installed via a package manager.

For debian-based distributions:

sudo apt install cmake build-essential pkg-config libsodium-dev

For arch-based distributions:

sudo pacman -S cmake base-devel pkgconf libsodium

Docker Container

After installing docker, you can use the following Dockerfile to run an image with all the dependencies installed:

 1# Dockerfile
 2FROM ubuntu:24.10
 3
 4ENV DEBIAN_FRONTEND=noninteractive
 5
 6# Update and install dependencies
 7RUN apt update && apt upgrade -y
 8
 9RUN apt install -y \
10  git \
11  cmake \
12  build-essential \
13  pkg-config \
14  libsodium-dev
15
16CMD ["bash"]

You can then build it:

docker build -t blockchain-workshop .

And run it, creating a volume in your current directory (will be useful to edit code in your editor, and compile in the container). In this example, we map our current directory to /test in the container:

docker run -it -v `pwd`:/test blockchain-workshop

Now, you have all the dependencies in your docker container and you can proceed to running the test setup.

Testing the Setup

To test the setup, we will use a simple program to get the sha256 hash of the hello world! string using libsodium and print the result to the screen. To get started, create a new directory in your system and place this file there:

 1// filename: test-setup.cpp
 2#include <iomanip>
 3#include <iostream>
 4#include <sodium.h>
 5#include <sstream>
 6#include <string>
 7
 8
 9std::string to_hex(unsigned char* hash, size_t len) {
10  std::ostringstream os;
11  for (size_t i =0; i < len; i++) {
12    os << std::hex << std::setw(2) << std::setfill('0');
13    os << (unsigned) hash[i];
14  }
15  return os.str();
16}
17
18
19int main() {
20  if (sodium_init() < 0) {
21    std::cerr << "Could not init libsodium" << std::endl;
22    return 1;
23  }
24
25  std::string hello = "hello world!";
26  unsigned char hash[crypto_hash_sha512_BYTES];
27  auto data_ptr = reinterpret_cast<const unsigned char*>(hello.data());
28  
29  crypto_hash_sha256(hash,data_ptr,hello.size());
30
31  std::cout << "hash: " << to_hex(hash,crypto_hash_sha512_BYTES); 
32
33  return 0;
34}

We also need the following CMakeLists.txt file in the same directory to compile our program and link libsodium:

 1# filename: CMakeLists.txt
 2cmake_minimum_required(VERSION 3.16)
 3
 4set(CMAKE_CXX_STANDARD 17)
 5set(CMAKE_CXX_STANDARD_REQUIRED ON)
 6set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
 7
 8project(test-setup VERSION 0.0.1 LANGUAGES CXX)
 9
10# Import libsodium
11find_package(PkgConfig REQUIRED)
12pkg_check_modules(SODIUM REQUIRED libsodium)
13
14# Add executable
15add_executable(test-setup test-setup.cpp)
16
17
18# Set include directories
19target_include_directories(test-setup PUBLIC 
20  ${CMAKE_CURRENT_SOURCE_DIR} 
21  ${SODIUM_INCLUDE_DIRS}
22)
23
24# Link with libsodium
25target_link_libraries(test-setup PRIVATE ${SODIUM_LIBRARIES})

Now we can create our build system by telling cmake to source from our current directory and the create build in the new ./build directory:

cmake -S . -B build

And we can compile the contents of ./build:

cmake --build build

If your setup is correct, the program should compile without errors and you should be able to execute it:

./build/test-setup

After executing, you should be able to see the following output:

hash:  7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9

Part 2 - Workshop Activities

You can access the workshop repository at https://github.com/leonardofmoura/blockchain-workshop.

You can clone the repository, test your setup and the proceed to he activities:

git clone https://github.com/leonardofmoura/blockchain-workshop.git

Activities

All the activities refer to directories in the workshop repository and should be done from there.

Task 1 - Cryptography

The files for task one are inside 1-cryptography. The steps are the following:

  1. Use Blake2b to hash the string: “Blockchain is cool!”
  2. Create a ed2559 keypair
  3. Sign the message “ENEI 2025”
  4. Verify the signature
  5. Try again with a different key/message and see the verification failing

Note: You can use the libsodium API directly for a slightly bigger challenge. You can check documentation here.

Task 2.1 - Simple Block

The files for task one are inside 2.1-simple-block. The steps are the following:

  1. Implement a SimpleBlock class including
    • The hash of the block
    • The hash of the parent
    • A string of data
  2. Create a simple blockchain by chaining those blocks

Task 2.2 - Simple Cyptocurrency

The files for task one are inside 2.2-blockchain and you should edit the 2.2-blockchain/block-test file. The steps are the following:

  1. Create a Genesis Block
  2. Create your two wallets
  3. Add a coinbase transaction to the block
  4. Mine it
  5. Create a Second Block
  6. Send coins to the second wallet
  7. Add a coinbase transaction to the second block
  8. Mine the block
  9. See the resulting blockchain

Task 2.3 - Simple Cryptocurrency Node

The files for task one are inside 2.2-blockchain and you should edit the 2.2-blockchain/node-test file. The steps are the following:

  1. Create a node
  2. Create another wallet
  3. Create a genesis block and mine it
  4. Send money to the second wallet
  5. Mine the second block
  6. Check the balances of both wallets