Standalone

Brainfuck VM

close button

Part II

Brainfuck VM

With Brainfuck programs implemented in Cairo, how can we port them over to Starknet?

VM Contract

We want to deploy a Starknet contract that will act as an on-chain Brainfuck VM. Through this contract, we will be able to deploy and execute arbitrary Brainfuck programs.

Every deployed program will have a u8 id. We can assume that the VM will not need to store more than 255 programs!

The VM contract will support the following three entry points.

Function

Description

deploy(ref self: ContractState, program: Array<felt252>) → u8

Deploy a new program and return its id. Reverts if the program has invalid syntax.

get_program(self: @ContractState, program_id: u8) → Array<felt252>

Returns the program with the specified id.

call(self: @ContractState, program_id: u8, input: Array<u8>) → Array<u8>

Execute the program at the given id with the given input. Returns the output.

Here are some important constraints:

  • You can assume that the maximum size of a program is 256 short strings.

Your Task

Implement BrainfuckVM in src/contracts/brainfuck_vm.cairo.

Run tests in Questplay

Submit work in Questplay

You’ve got it! At least, you think you have. But can you and Seraphina figure out a way to transcribe this writing into the common tongue…?