Skip to content

Commit 2b0eac3

Browse files
committed
feat: bump emulator to v0.20.0
1 parent 95a9ecb commit 2b0eac3

14 files changed

Lines changed: 145 additions & 102 deletions

File tree

Dockerfile

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
# syntax=docker.io/docker/dockerfile:1
55

6-
ARG EMULATOR_VERSION=0.19.0
6+
ARG EMULATOR_VERSION=0.20.0
77

88
# Build directories.
99
ARG GO_BUILD_PATH=/build/cartesi/go
1010

11-
FROM debian:bookworm-20250407 AS common-env
11+
FROM debian:trixie-20250811 AS common-env
1212

1313
USER root
1414

@@ -22,13 +22,13 @@ RUN <<EOF
2222
apt-get update
2323
apt-get install -y --no-install-recommends \
2424
ca-certificates curl wget build-essential pkg-config libssl-dev
25-
addgroup --system --gid 102 cartesi
26-
adduser --system --uid 102 --ingroup cartesi --disabled-login --no-create-home --home /nonexistent --gecos "cartesi user" --shell /bin/false cartesi
25+
groupadd --system --gid 102 cartesi
26+
useradd --system --uid 102 --gid cartesi --shell /usr/sbin/nologin --no-create-home cartesi
2727
ARCH=$(dpkg --print-architecture)
2828
wget -O /tmp/cartesi-machine-emulator.deb "https://github.com/cartesi/machine-emulator/releases/download/v${EMULATOR_VERSION}/machine-emulator_${ARCH}.deb"
2929
case "$ARCH" in
30-
amd64) echo "adae6b030a8990e316997aad53d175192bfeaa84ad12ee19491366377073572b /tmp/cartesi-machine-emulator.deb" | sha256sum --check ;;
31-
arm64) echo "15ebb64d8cd3296564d2297dd809d1d72c13a938976bb4ecc5e5c82e71bb8069 /tmp/cartesi-machine-emulator.deb" | sha256sum --check ;;
30+
amd64) echo "46b2f37b889091df3b89a8909467935f8dd4a1426eeb0491b6a346a12f0c341c /tmp/cartesi-machine-emulator.deb" | sha256sum --check ;;
31+
arm64) echo "27ea10571335ad174b75388e7de54a3d3434bd607554d8c0bdf6abca47ceae0d /tmp/cartesi-machine-emulator.deb" | sha256sum --check ;;
3232
*) echo "unsupported architecture: $ARCH"; exit 1 ;;
3333
esac
3434
apt-get install -y --no-install-recommends /tmp/cartesi-machine-emulator.deb
@@ -146,7 +146,7 @@ RUN make build-debian-package DESTDIR=$PWD/_install
146146
# (This stage copies the binaries from previous stages.)
147147
# =============================================================================
148148

149-
FROM debian:bookworm-20250407 AS rollups-node
149+
FROM debian:trixie-20250811 AS rollups-node
150150

151151
ARG NODE_RUNTIME_DIR=/var/lib/cartesi-rollups-node
152152
ARG GO_BUILD_PATH
@@ -164,8 +164,9 @@ COPY --from=debian-packager \
164164
ARG DEBIAN_FRONTEND=noninteractive
165165
RUN <<EOF
166166
set -e
167-
addgroup --system --gid 102 cartesi
168-
adduser --system --uid 102 --ingroup cartesi --disabled-login --no-create-home --home /nonexistent --gecos "cartesi user" --shell /bin/false cartesi
167+
groupadd --system --gid 102 cartesi
168+
useradd --system --uid 102 --gid cartesi --shell /usr/sbin/nologin --no-create-home cartesi
169+
passwd --lock cartesi
169170
apt-get update
170171
apt-get install -y --no-install-recommends \
171172
ca-certificates \

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ We provide packages for debian (.deb) in **amd64** and **arm64** variants on the
1616

1717
##### System Requirements
1818

19-
- Cartesi Machine emulator == 0.19.x
19+
- Cartesi Machine emulator == 0.20.x
2020
- GNU Make >= 3.81
2121
- Go >= 1.24.1
2222

2323
Follow the Cartesi Machine installation instructions [here](https://github.com/cartesi/machine-emulator?tab=readme-ov-file#installation).
2424

2525
##### Build
2626

27+
With the Cartesi machine emulator installed, build the rollups-node:
28+
2729
```sh
28-
# clone a stable branch of the emulator
29-
git clone --branch v2.0.0 https://github.com/cartesi/rollups-node.git
30+
# clone a branch of the rollups-node
31+
git clone --branch next/2.0 https://github.com/cartesi/rollups-node.git
3032
cd rollups-node
3133

3234
# compile

cmd/cartesi-rollups-cli/root/app/register/register.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"os"
1313
"strings"
1414

15-
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/root/app/util"
15+
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/util"
1616
"github.com/cartesi/rollups-node/internal/config"
1717
"github.com/cartesi/rollups-node/internal/model"
1818
"github.com/cartesi/rollups-node/internal/repository/factory"
@@ -143,12 +143,11 @@ func run(cmd *cobra.Command, args []string) {
143143
checkEnabled, err := config.GetFeatureMachineHashCheckEnabled()
144144
cobra.CheckErr(err)
145145
if checkEnabled {
146-
templateHash, err := util.ReadHash(templatePath)
146+
snapshotTemplateHash, err := util.ReadRootHash(templatePath)
147147
if err != nil {
148148
fmt.Fprintf(os.Stderr, "Read machine template hash failed: %v\n", err)
149149
os.Exit(1)
150150
}
151-
snapshotTemplateHash := common.HexToHash(templateHash)
152151
if parsedTemplateHash != snapshotTemplateHash {
153152
fmt.Fprintf(os.Stderr, "Template hash mismatch: contract has %s but machine has %s\n",
154153
parsedTemplateHash.Hex(), snapshotTemplateHash.Hex())

cmd/cartesi-rollups-cli/root/app/util/machine.go

Lines changed: 0 additions & 29 deletions
This file was deleted.

cmd/cartesi-rollups-cli/root/deploy/application.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"encoding/json"
99
"fmt"
1010
"os"
11-
"path"
1211
"strings"
1312

13+
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/util"
1414
"github.com/cartesi/rollups-node/internal/config"
1515
"github.com/cartesi/rollups-node/internal/config/auth"
1616
"github.com/cartesi/rollups-node/internal/model"
@@ -360,7 +360,7 @@ func buildSelfhostedApplicationDeployment(
360360

361361
if !cmd.Flags().Changed("template-hash") {
362362
if len(args) >= 2 { // args[1] is mandatory if `template-hash` was absent
363-
request.TemplateHash, err = readHash(args[1])
363+
request.TemplateHash, err = util.ReadRootHash(args[1])
364364
} else {
365365
err = fmt.Errorf("missing argument. One of `template-path` or `template-hash` is required")
366366
}
@@ -435,7 +435,7 @@ func buildApplicationOnlyDeployment(
435435

436436
if !cmd.Flags().Changed("template-hash") {
437437
if len(args) >= 2 { // args[1] is mandatory if `template-hash` was absent
438-
request.TemplateHash, err = readHash(args[1])
438+
request.TemplateHash, err = util.ReadRootHash(args[1])
439439
} else {
440440
err = fmt.Errorf("missing argument. One of `template-path` or `template-hash` is required")
441441
}
@@ -515,7 +515,7 @@ func buildPrtApplicationDeployment(
515515

516516
if !cmd.Flags().Changed("template-hash") {
517517
if len(args) >= 2 { // args[1] is mandatory if `template-hash` was absent
518-
request.TemplateHash, err = readHash(args[1])
518+
request.TemplateHash, err = util.ReadRootHash(args[1])
519519
} else {
520520
err = fmt.Errorf("missing argument. One of `template-path` or `template-hash` is required")
521521
}
@@ -535,23 +535,6 @@ func buildPrtApplicationDeployment(
535535
return request, nil
536536
}
537537

538-
// read the hash value from the cartesi machine hash file
539-
func readHash(machineDir string) (common.Hash, error) {
540-
zero := common.Hash{}
541-
path := path.Join(machineDir, "hash")
542-
hash, err := os.ReadFile(path)
543-
if err != nil {
544-
return zero, fmt.Errorf("read hash: %w", err)
545-
} else if len(hash) != common.HashLength {
546-
return zero, fmt.Errorf(
547-
"read hash: wrong size; expected %v bytes but read %v",
548-
common.HashLength,
549-
len(hash),
550-
)
551-
}
552-
return common.BytesToHash(hash), nil
553-
}
554-
555538
func parseHexHash(hash string) (common.Hash, error) {
556539
out := common.Hash{}
557540
return out, out.UnmarshalText([]byte(hash))
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// (c) Cartesi and individual authors (see AUTHORS)
2+
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)
3+
4+
package util
5+
6+
import (
7+
"io"
8+
"os"
9+
"path"
10+
11+
"github.com/ethereum/go-ethereum/common"
12+
)
13+
14+
// Reads the Cartesi Machine hash from machineDir. Returns it as a commonHash
15+
// or an error
16+
func ReadRootHash(machineDir string) (common.Hash, error) {
17+
zero := common.Hash{}
18+
path := path.Join(machineDir, "hash_tree.sht")
19+
f, err := os.Open(path)
20+
if err != nil {
21+
return zero, err
22+
}
23+
defer f.Close()
24+
25+
// root hash is located at this offset (0x60). Double check its value
26+
// with the cartesi-machine-stored-hash tool.
27+
_, err = f.Seek(0x60, io.SeekStart)
28+
if err != nil {
29+
return zero, err
30+
}
31+
32+
hash := common.Hash{}
33+
_, err = io.ReadFull(f, hash[:])
34+
if err != nil {
35+
return zero, err
36+
}
37+
return hash, nil
38+
}

control.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Homepage: https://docs.cartesi.io/cartesi-rollups/
55
Architecture: ARG_ARCH
66
Maintainer: Node Reference Unit <https://discord.com/channels/600597137524391947/1110564973115097179>
77
Provides: cartesi-rollups-node
8-
Depends: cartesi-machine-emulator (>= 0.19.0), cartesi-machine-emulator (<< 0.20.0)
8+
Depends: cartesi-machine-emulator (>= 0.20.0), cartesi-machine-emulator (<< 0.21.0)
99
Section: net
1010
Priority: optional
1111
Multi-Arch: no

pkg/emulator/emulator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ func SpawnServer(address string, timeout time.Duration) (*RemoteMachine, string,
4848
return &RemoteMachine{Machine: Machine{ptr: cm}}, C.GoString(boundAddr), uint32(pid), nil
4949
}
5050

51-
func CreateMachine(config, runtimeConfig string) (*Machine, error) {
51+
func CreateMachine(config, runtimeConfig, dir string) (*Machine, error) {
5252
machine := &Machine{}
53-
err := machine.Create(config, runtimeConfig)
53+
err := machine.Create(config, runtimeConfig, dir)
5454
return machine, err
5555
}

pkg/emulator/machine.go

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ func (m *Machine) Delete() {
5858
}
5959

6060
// create
61-
func (m *Machine) Create(config, runtimeConfig string) error {
61+
func (m *Machine) Create(config, runtimeConfig, dir string) error {
6262
var err error
6363
m.callCAPI(func() {
6464
var cConfig *C.char
6565
var cRuntime *C.char
66+
var cDir *C.char
6667
if config != "" {
6768
cConfig = C.CString(config)
6869
defer C.free(unsafe.Pointer(cConfig))
@@ -71,7 +72,11 @@ func (m *Machine) Create(config, runtimeConfig string) error {
7172
cRuntime = C.CString(runtimeConfig)
7273
defer C.free(unsafe.Pointer(cRuntime))
7374
}
74-
err = newError(C.cm_create_new(cConfig, cRuntime, &m.ptr))
75+
if dir != "" {
76+
cDir = C.CString(dir)
77+
defer C.free(unsafe.Pointer(cDir))
78+
}
79+
err = newError(C.cm_create_new(cConfig, cRuntime, cDir, &m.ptr))
7580
})
7681
return err
7782
}
@@ -119,35 +124,14 @@ func (m *Machine) GetInitialConfig() (string, error) {
119124
return res, nil
120125
}
121126

122-
// get_memory_ranges
123-
func (m *Machine) GetMemoryRanges() (string, error) {
124-
var ranges *C.char
125-
var err error
126-
var res string
127-
128-
m.callCAPI(func() {
129-
err = newError(C.cm_get_memory_ranges(m.ptr, &ranges))
130-
if err != nil || ranges == nil {
131-
return
132-
}
133-
res = C.GoString(ranges)
134-
// no need to free 'ranges' here, as it is a static string
135-
})
136-
137-
if err != nil {
138-
return "", err
139-
}
140-
return res, nil
141-
}
142-
143127
// get_proof
144128
func (m *Machine) GetProof(address uint64, log2size int32) (string, error) {
145129
var proof *C.char
146130
var err error
147131
var res string
148132

149133
m.callCAPI(func() {
150-
err = newError(C.cm_get_proof(m.ptr, C.uint64_t(address), C.int32_t(log2size), &proof))
134+
err = newError(C.cm_get_proof(m.ptr, C.uint64_t(address), C.int32_t(log2size), C.int32_t(HashTreeLog2RootSize), &proof))
151135
if err != nil || proof == nil {
152136
return
153137
}
@@ -241,7 +225,7 @@ func (m *Machine) Load(dir string, runtimeConfig string) error {
241225
cRuntime = C.CString(runtimeConfig)
242226
defer C.free(unsafe.Pointer(cRuntime))
243227
}
244-
err = newError(C.cm_load(m.ptr, cDir, cRuntime))
228+
err = newError(C.cm_load(m.ptr, cDir, cRuntime, SharingNone))
245229
})
246230

247231
return err
@@ -369,6 +353,56 @@ func (m *Machine) Run(mcycleEnd uint64) (BreakReason, error) {
369353
return BreakReason(br), nil
370354
}
371355

356+
// collect_mcycle_root_hashes
357+
func (m *Machine) CollectMCycleRootHashes(mcycleEnd, mcyclePeriod, mcyclePhase uint64, log2BundleMcycleCount int32, previousBackTree string) ([]byte, error) {
358+
var err error
359+
var result []byte
360+
361+
m.callCAPI(func() {
362+
var cResult *C.char
363+
var previousBackTreeC *C.char
364+
if previousBackTree != "" {
365+
previousBackTreeC = C.CString(previousBackTree)
366+
defer C.free(unsafe.Pointer(previousBackTreeC))
367+
}
368+
err = newError(C.cm_collect_mcycle_root_hashes(
369+
m.ptr,
370+
C.uint64_t(mcycleEnd),
371+
C.uint64_t(mcyclePeriod),
372+
C.uint64_t(mcyclePhase),
373+
C.int32_t(log2BundleMcycleCount),
374+
previousBackTreeC,
375+
&cResult))
376+
result = []byte(C.GoString(cResult))
377+
})
378+
if err != nil {
379+
return nil, err
380+
}
381+
382+
return result, nil
383+
}
384+
385+
// collect_uarch_cycle_root_hashes
386+
func (m *Machine) CollectUarchCycleRootHashes(mcycleEnd uint64, log2BundleMcycleCount int32) ([]byte, error) {
387+
var err error
388+
var result []byte
389+
390+
m.callCAPI(func() {
391+
var cResult *C.char
392+
err = newError(C.cm_collect_uarch_cycle_root_hashes(
393+
m.ptr,
394+
C.uint64_t(mcycleEnd),
395+
C.int32_t(log2BundleMcycleCount),
396+
&cResult))
397+
result = []byte(C.GoString(cResult))
398+
})
399+
400+
if err != nil {
401+
return nil, err
402+
}
403+
return result, nil
404+
}
405+
372406
// send_cmio_response
373407
func (m *Machine) SendCmioResponse(reason uint16, data []byte) error {
374408
var err error
@@ -414,7 +448,7 @@ func (m *Machine) Store(directory string) error {
414448
m.callCAPI(func() {
415449
cDir := C.CString(directory)
416450
defer C.free(unsafe.Pointer(cDir))
417-
err = newError(C.cm_store(m.ptr, cDir))
451+
err = newError(C.cm_store(m.ptr, cDir, SharingAll))
418452
})
419453

420454
return err

0 commit comments

Comments
 (0)