Skip to content

Commit 6559263

Browse files
jonasmartincrivasr
andauthored
Update cpu with tests and new challenges (#35)
* add coinspect tests * merge with dev * align imm to multiple of 4 in op_conditional fuzzer * increase tables for multiplication again * fix sign_check for zero quotient * fix div_rem fuzzer * add more sanity checks * add padding and alignment checks * return error if unaligned write or read * align reads and writes in tests * fix test_load_word_boundary * clear lsb in test * fix witness tests * fix jalr_enhanced test * add no-mapping flag * fix NUM_TEST_CASES value * use stdlib and optimizations * remove unnecessary moves * reuse common verify_file function * remove zero address asserts in input and rom challenges * warn about stdlib * update docker commit * fix address_in_sections when section is empty * assert nary value is a valid power of two * implement execute only memory protection * update docker commit * increase max steps for some tests * fix and use save-non-checkpoint-steps flag * remove wrong test case * remove outdated comments * limit sections count * add future read challenge * add different value test case for read challenge * enforce ReadValueChallenge is before ConflictStep * verify address in chunk range * improve and rename nibbles_to_number * separate big test in multiple tests * update submodule --------- Co-authored-by: crivasr <camilorivasramunni@gmail.com>
1 parent fedb8e9 commit 6559263

111 files changed

Lines changed: 53615 additions & 838 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ tests/resources/
2525
# checkpoints
2626
*.json
2727
.DS_Store
28+
29+
# Test error log
30+
_coin/reference_tests/error.log

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ It is not production-ready, has not been audited, and future updates may introdu
1313
## Structure
1414

1515
The repository contains three folders
16-
1. **docker-riscv32**: Contains the recipe for an image that allows the compilation of C programs into the RISCV-32i architecture. Currently, the programs must be carefully crafted to be used inside BitVMX, using specific memory layouts, predefined input sections and the lack of support for now of the stdlib.
16+
1. **docker-riscv32**: Contains the recipe for an image that allows the compilation of C programs into the RISCV-32i architecture. Currently, the programs must be carefully crafted to be used inside BitVMX, using specific memory layouts and predefined input sections. There is now the possibility to compile with the stdlib, it is not fully tested and may cause problems if it uses unimplemented syscalls.
1717
There are two subfolders: `compliance` which have the code necessary to create the RISCV compliance verification files, and `verifier` which helps with the compilation of a zero knowledge proof verifier program.
1818
2. **emulator**: The emulator is a library with a command line interface implemented in Rust which is used to execute the binary files compiled. Also this tool helps in the creation of the execution trace, the hash list of the execution necessary for the challenge protocol.
1919
3. **bitocoin-script-riscv**: This library contains the code that allows to verify any of the RISCV instructions on Bitcoin Script, and therefore challenge the execution of the CPU on-chain.

_coin/compliance_tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

_coin/compliance_tests/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM riscv32:latest
2+
3+
WORKDIR /riscv-tests
4+

_coin/compliance_tests/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# RISC-V Compliance Tests
2+
3+
This directory contains compliance tests that extend the tests from [riscv-tests](https://github.com/riscv-software-src/riscv-tests).
4+
5+
## Building and Running Tests
6+
7+
### 1. Build the Docker Image
8+
9+
```bash
10+
docker build -t riscv-coin .
11+
```
12+
13+
### 2. Compile the Tests
14+
15+
```bash
16+
sudo ./docker-run-coin-compliance.sh riscv-coin ./build_all.sh
17+
```
18+
19+
### 3. Run the Tests
20+
21+
```bash
22+
./run_tests.sh
23+
```
24+
25+
To verify that all scripts provide the same result in Bitcoin, use the `--verify` flag:
26+
27+
```bash
28+
./run_tests.sh --verify
29+
```
30+
31+
## Understanding Test Failures
32+
33+
When tests fail, they will output something like `halt(5,200)`. To identify which test is failing:
34+
35+
1. Take the first number (5 in this example)
36+
2. Subtract 1: `5 - 1 = 4`
37+
3. Divide by 2: `4 / 2 = 2`
38+
39+
The result (2) is the test number that is failing.
40+
41+
## Options
42+
43+
- `./run_tests.sh` - Run tests without Bitcoin verification (faster)
44+
- `./run_tests.sh --verify` - Run tests with Bitcoin verification (slower but more thorough)

_coin/compliance_tests/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$CC -static -march=rv32g -mabi=ilp32 -nostdlib -nostartfiles -Wl,--no-warn-rwx-segments -I./ -I./../../ -I/riscv-tests/isa/macros/scalar/ -T./linker/link.ld -o build/$1.elf /riscv-tests/isa/rv32ui/$1.S
2+
$QEMU -d in_asm -D build/$1.s build/$1.elf
3+
$DUMP -d build/$1.elf > build/$1_dump.s
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
echo "Executing build_all.sh"
2+
chmod +x build.sh
3+
chmod +x build_mul.sh
4+
dos2unix build.sh
5+
dos2unix build_mul.sh
6+
7+
for f in /riscv-tests/isa/rv32ui/*.S; do
8+
filename=$(basename "${f%.*}")
9+
echo $filename
10+
./build.sh $filename
11+
done
12+
13+
for f in /riscv-tests/isa/rv32um/*.S; do
14+
filename=$(basename "${f%.*}")
15+
echo $filename
16+
./build_mul.sh $filename
17+
done
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$CC -static -march=rv32g -mabi=ilp32 -nostdlib -nostartfiles -Wl,--no-warn-rwx-segments -I./ -I./../../ -I/riscv-tests/isa/macros/scalar/ -T./linker/link.ld -o build/$1.elf /riscv-tests/isa/rv32um/$1.S
2+
$QEMU -d in_asm -D build/$1.s build/$1.elf
3+
$DUMP -d build/$1.elf > build/$1_dump.s
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
# Check if at least two arguments are provided
4+
if [ $# -lt 2 ]; then
5+
echo "Usage: $0 container_name script_name [arguments]"
6+
exit 1
7+
fi
8+
9+
# Extract the first and second arguments
10+
container_name="$1"
11+
script_name="$2"
12+
13+
# Collect all remaining arguments (starting from the third)
14+
arguments="${@:3}"
15+
16+
echo "Using $container_name to execute script $script_name with arguments: $arguments"
17+
18+
docker run --rm -it --name riscv-coin \
19+
-v "$PWD":/riscv-tests \
20+
riscv-coin:latest \
21+
sh -c "chmod +x /riscv-tests/$script_name && /riscv-tests/$script_name $arguments"

_coin/compliance_tests/env/LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2012-2015, The Regents of the University of California (Regents).
2+
All Rights Reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
1. Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
2. Redistributions in binary form must reproduce the above copyright
9+
notice, this list of conditions and the following disclaimer in the
10+
documentation and/or other materials provided with the distribution.
11+
3. Neither the name of the Regents nor the
12+
names of its contributors may be used to endorse or promote products
13+
derived from this software without specific prior written permission.
14+
15+
IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
16+
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
17+
OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
18+
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19+
20+
REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22+
PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
23+
HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
24+
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

0 commit comments

Comments
 (0)