Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f5f7309
feat: bump to cartesi/sdk:0.12.0
endersonmaia Oct 10, 2024
4c30f95
feat: bump CLI to v2
tuler Oct 22, 2024
bc99c1c
feat: update cpp-low-level template
endersonmaia Oct 23, 2024
cfdf7ed
feat(typescript): update rollups http interface
tuler Oct 24, 2024
df834c5
feat(javascript): remove ethers dependency
tuler Oct 24, 2024
58044eb
feat(ruby): bump dependencies
tuler Oct 24, 2024
b97be28
feat: remove --platform=linux/riscv64
endersonmaia Oct 25, 2024
b734eda
feat: bump to ubuntu:24.04
endersonmaia Sep 9, 2024
e475de1
feat: use apt --snapshot for reproducibility
endersonmaia Sep 27, 2024
d67548d
feat: bump golang to 1.23.2
endersonmaia Sep 10, 2024
04633c1
chore: go fmt
endersonmaia Sep 10, 2024
a30e5a3
chore: fix golang warnings
endersonmaia Sep 10, 2024
7ffdf92
feat: bump rust to 1.81.0
endersonmaia Oct 1, 2024
d3d51d1
feat: use machine-guest-tools 0.17.0-test3
endersonmaia Mar 27, 2025
7bb3675
ci: bump @cartesi/cli to v2.0.0-alpha.8
endersonmaia Mar 28, 2025
0a5878f
feat: apt --snapshot for {type,java}script templates
endersonmaia Mar 28, 2025
a2c6e98
feat: apt --snapshot for python template
endersonmaia Apr 1, 2025
c9cd7ee
chore: bump ubuntu snapshot to 20250408
endersonmaia Apr 8, 2025
993df45
chore: bump guest-tools to 0.17.0-test6
endersonmaia Apr 8, 2025
45f8e30
chore: bump ubuntu baseimage to noble-20250404
endersonmaia Apr 9, 2025
4b69b7b
feat: move rollups templates to its own dir
endersonmaia Apr 8, 2025
9516dd9
feat: coprocessor templates
Nonnyjoe Apr 10, 2025
b085c6b
ci: coprocessor templates build
tuler Apr 22, 2025
946f724
feat: solidity coprocessor template
Nonnyjoe Apr 4, 2025
537c99c
feat: bump machine-guest-tools to 0.17.0
tuler Apr 25, 2025
e9efe5d
feat: bump APT_UPDATE_SNAPSHOT to 20250424T030400Z
endersonmaia Apr 25, 2025
2124619
feat: add lua chiselled template
endersonmaia Apr 25, 2025
b41d080
feat: add chiselled cpp template
endersonmaia Apr 28, 2025
dae6381
feat: add golang chiselled template
endersonmaia Apr 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
framework:
- rollups
- coprocessor
template:
[
cpp,
cpp-low-level,
go,
javascript,
lua,
python,
ruby,
rust,
typescript,
]
- cpp
- cpp-low-level
- go
- javascript
- lua
- python
- ruby
- rust
- typescript
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -35,14 +36,14 @@ jobs:
node-version: current

- name: Install Cartesi CLI
run: npm install -g @cartesi/cli
run: npm install -g @cartesi/cli@2.0.0-alpha.8

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Check system requirements
run: cartesi doctor

- name: Build
- name: Build ${{ matrix.framework}} ${{ matrix.template }}
run: cartesi build
working-directory: ${{ matrix.template }}
working-directory: ${{ matrix.framework}}/${{ matrix.template }}/
File renamed without changes.
File renamed without changes.
81 changes: 81 additions & 0 deletions coprocessor/cpp-low-level/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# syntax=docker.io/docker/dockerfile:1
ARG MACHINE_GUEST_TOOLS_VERSION=0.17.0

# This enforces that the packages downloaded from the repositories are the same
# for the defined date, no matter when the image is built.
ARG UBUNTU_TAG=noble-20250404
ARG APT_UPDATE_SNAPSHOT=20250424T030400Z

################################################################################
# riscv64 base stage
FROM --platform=linux/riscv64 ubuntu:${UBUNTU_TAG} AS base

ARG APT_UPDATE_SNAPSHOT
ARG DEBIAN_FRONTEND=noninteractive
RUN <<EOF
set -eu
apt-get update
apt-get install -y --no-install-recommends ca-certificates curl
apt-get update --snapshot=${APT_UPDATE_SNAPSHOT}
EOF

################################################################################
# riscv64 builder stage
FROM base AS builder

ARG DEBIAN_FRONTEND=noninteractive
RUN <<EOF
set -e
apt-get install -y --no-install-recommends \
autoconf \
automake \
build-essential \
busybox-static \
libtool \
pkg-config
rm -rf /var/lib/apt/lists/*
EOF

ARG MACHINE_GUEST_TOOLS_VERSION
ADD https://github.com/cartesi/machine-guest-tools/releases/download/v${MACHINE_GUEST_TOOLS_VERSION}/machine-guest-tools_riscv64.deb /tmp/machine-guest-tools_riscv64.deb

RUN <<EOF
set -e
echo "973943b3a3e40164175da7d7b5b7857642d1277e1fd38be268da12daca5ff458735f93a7ac25b350b3de58b073a25b64c860d9eb92157bfc946b03dd1a345cc9 /tmp/machine-guest-tools_riscv64.deb" \
| sha512sum -c
apt-get install -y --no-install-recommends \
/tmp/machine-guest-tools_riscv64.deb
rm /tmp/machine-guest-tools_riscv64.deb
EOF

WORKDIR /opt/cartesi/dapp
COPY . .
RUN make

################################################################################
# runtime stage: produces final image that will be executed
FROM base

ARG MACHINE_GUEST_TOOLS_VERSION
ARG DEBIAN_FRONTEND=noninteractive
RUN <<EOF
set -e
apt-get install -y --no-install-recommends \
busybox-static

cd /tmp
busybox wget https://github.com/cartesi/machine-guest-tools/releases/download/v${MACHINE_GUEST_TOOLS_VERSION}/machine-guest-tools_riscv64.deb
echo "973943b3a3e40164175da7d7b5b7857642d1277e1fd38be268da12daca5ff458735f93a7ac25b350b3de58b073a25b64c860d9eb92157bfc946b03dd1a345cc9 /tmp/machine-guest-tools_riscv64.deb" \
| sha512sum -c
apt-get install -y --no-install-recommends \
/tmp/machine-guest-tools_riscv64.deb
rm /tmp/machine-guest-tools_riscv64.deb

rm -rf /var/lib/apt/lists/* /var/log/* /var/cache/*
EOF

ENV PATH="/opt/cartesi/bin:${PATH}"

WORKDIR /opt/cartesi/dapp
COPY --from=builder /opt/cartesi/dapp/dapp .
CMD ["/opt/cartesi/dapp/dapp"]
32 changes: 32 additions & 0 deletions coprocessor/cpp-low-level/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright Cartesi and individual authors (see AUTHORS)
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

UNAME:=$(shell uname)

CC = gcc
STRIP = strip
CFLAGS +=-Wall -Wextra -pedantic -O2 `pkg-config --cflags libcmt`
LDLIBS += `pkg-config --libs libcmt`

all: dapp

dapp: export PKG_CONFIG_PATH ?= /usr/riscv64-linux-gnu/lib/pkgconfig
dapp: dapp.c
$(CC) $(CFLAGS) -o dapp dapp.c $(LDLIBS)
$(STRIP) dapp

clean:
@rm -rf dapp
80 changes: 80 additions & 0 deletions coprocessor/cpp-low-level/dapp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* Copyright Cartesi and individual authors (see AUTHORS)
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>

#include "libcmt/rollup.h"

static int finish_request(cmt_rollup_t *me, cmt_rollup_finish_t *finish) {
finish->accept_previous_request = true;
return cmt_rollup_finish(me, finish);
}

static int handle_advance_state_request(cmt_rollup_t *me, uint64_t *index) {
cmt_rollup_advance_t advance;
int rc = cmt_rollup_read_advance_state(me, &advance);
if (rc)
return rc;
*index = advance.index;
fprintf(stderr, "handling advance with index %d\n", (int) advance.index);
return 0;
}

static int handle_request(cmt_rollup_t *me, cmt_rollup_finish_t *finish, uint64_t *index) {
switch (finish->next_request_type) {
case HTIF_YIELD_REASON_ADVANCE:
return handle_advance_state_request(me, index);
default:
/* unknown request type */
fprintf(stderr, "Unknown request type %d\n", finish->next_request_type);
return -1;
}
return 0;
}

int main() {
cmt_rollup_t rollup;
uint64_t advance_index = 0;

if (cmt_rollup_init(&rollup) != 0)
return EXIT_FAILURE;

/* Accept the initial request */
cmt_rollup_finish_t finish;
if (finish_request(&rollup, &finish) != 0) {
exit(1);
}

/* handle a request, then wait for next */
for (;;) {
if (handle_request(&rollup, &finish, &advance_index) != 0) {
break;
}
if (finish_request(&rollup, &finish) != 0) {
break;
}
}

cmt_rollup_fini(&rollup);
fprintf(stderr, "Exiting...\n");
return 1;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions cpp/3rdparty/Makefile → coprocessor/cpp/3rdparty/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
all: cpp-httplib picojson

cpp-httplib:
wget https://github.com/yhirose/cpp-httplib/archive/refs/tags/v0.10.4.tar.gz && \
curl -fsSL -O https://github.com/yhirose/cpp-httplib/archive/refs/tags/v0.10.4.tar.gz && \
tar xvf v0.10.4.tar.gz && \
rm v0.10.4.tar.gz && \
mv cpp-httplib-0.10.4 cpp-httplib

picojson:
wget https://github.com/kazuho/picojson/archive/refs/tags/v1.3.0.tar.gz && \
curl -fsSL -O https://github.com/kazuho/picojson/archive/refs/tags/v1.3.0.tar.gz && \
tar xvf v1.3.0.tar.gz && \
rm v1.3.0.tar.gz && \
mv picojson-1.3.0 picojson
Expand Down
70 changes: 70 additions & 0 deletions coprocessor/cpp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# syntax=docker.io/docker/dockerfile:1

# This enforces that the packages downloaded from the repositories are the same
# for the defined date, no matter when the image is built.
ARG UBUNTU_TAG=noble-20250404
ARG APT_UPDATE_SNAPSHOT=20250424T030400Z

################################################################################
# riscv64 base stage
FROM --platform=linux/riscv64 ubuntu:${UBUNTU_TAG} AS base

ARG APT_UPDATE_SNAPSHOT
ARG DEBIAN_FRONTEND=noninteractive
RUN <<EOF
set -eu
apt-get update
apt-get install -y --no-install-recommends ca-certificates curl
apt-get update --snapshot=${APT_UPDATE_SNAPSHOT}
EOF

################################################################################
# riscv64 builder stage
FROM base AS builder

ARG DEBIAN_FRONTEND=noninteractive
RUN <<EOF
set -e
apt-get install -y --no-install-recommends \
autoconf \
automake \
build-essential \
libtool
rm -rf /var/lib/apt/lists/*
EOF

WORKDIR /opt/cartesi/dapp
COPY . .
RUN make

################################################################################
# runtime stage: produces final image that will be executed
FROM base

ARG MACHINE_GUEST_TOOLS_VERSION=0.17.0
ARG DEBIAN_FRONTEND=noninteractive
RUN <<EOF
set -e
apt-get install -y --no-install-recommends \
busybox-static

cd /tmp
busybox wget https://github.com/cartesi/machine-guest-tools/releases/download/v${MACHINE_GUEST_TOOLS_VERSION}/machine-guest-tools_riscv64.deb
echo "973943b3a3e40164175da7d7b5b7857642d1277e1fd38be268da12daca5ff458735f93a7ac25b350b3de58b073a25b64c860d9eb92157bfc946b03dd1a345cc9 /tmp/machine-guest-tools_riscv64.deb" \
| sha512sum -c
apt-get install -y --no-install-recommends \
/tmp/machine-guest-tools_riscv64.deb
rm /tmp/machine-guest-tools_riscv64.deb

rm -rf /var/lib/apt/lists/* /var/log/* /var/cache/*
EOF

ENV PATH="/opt/cartesi/bin:${PATH}"

WORKDIR /opt/cartesi/dapp
COPY --from=builder /opt/cartesi/dapp/dapp .

ENV ROLLUP_HTTP_SERVER_URL="http://127.0.0.1:5004"

ENTRYPOINT ["rollup-init"]
CMD ["/opt/cartesi/dapp/dapp"]
File renamed without changes.
45 changes: 45 additions & 0 deletions coprocessor/cpp/dapp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <stdio.h>
#include <iostream>

#include "3rdparty/cpp-httplib/httplib.h"
#include "3rdparty/picojson/picojson.h"

std::string handle_advance(httplib::Client &cli, picojson::value data)
{
std::cout << "Received advance request data " << data << std::endl;
return "accept";
}


int main(int argc, char **argv)
{
std::map<std::string, decltype(&handle_advance)> handlers = {
{std::string("advance_state"), &handle_advance},
};
httplib::Client cli(getenv("ROLLUP_HTTP_SERVER_URL"));
cli.set_read_timeout(20, 0);
std::string status("accept");
std::string rollup_address;
while (true)
{
std::cout << "Sending finish" << std::endl;
auto finish = std::string("{\"status\":\"") + status + std::string("\"}");
auto r = cli.Post("/finish", finish, "application/json");
std::cout << "Received finish status " << r.value().status << std::endl;
if (r.value().status == 202)
{
std::cout << "No pending rollup request, trying again" << std::endl;
}
else
{
picojson::value rollup_request;
picojson::parse(rollup_request, r.value().body);
picojson::value metadata = rollup_request.get("data").get("metadata");
auto request_type = rollup_request.get("request_type").get<std::string>();
auto handler = handlers.find(request_type)->second;
auto data = rollup_request.get("data");
status = (*handler)(cli, data);
}
}
return 0;
}
File renamed without changes.
File renamed without changes.
Loading