Skip to content

Commit 32ec195

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

15 files changed

Lines changed: 237 additions & 101 deletions

File tree

Dockerfile

Lines changed: 9 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,8 @@ 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
169169
apt-get update
170170
apt-get install -y --no-install-recommends \
171171
ca-certificates \

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ env:
123123
@echo export CARTESI_BLOCKCHAIN_HTTP_ENDPOINT="http://localhost:8545"
124124
@echo export CARTESI_BLOCKCHAIN_WS_ENDPOINT="ws://localhost:8545"
125125
@echo export CARTESI_BLOCKCHAIN_ID="31337"
126-
@echo export CARTESI_CONTRACTS_INPUT_BOX_ADDRESS="0x1b51e2992A2755Ba4D6F7094032DF91991a0Cfac"
126+
@echo export CARTESI_CONTRACTS_INPUT_BOX_ADDRESS="0x606c3Ab81a862BEA826Fb3C9395F328f0E465294"
127127
@echo export CARTESI_CONTRACTS_AUTHORITY_FACTORY_ADDRESS="0x5E96408CFE423b01dADeD3bc867E6013135990cc"
128128
@echo export CARTESI_CONTRACTS_APPLICATION_FACTORY_ADDRESS="0x26E758238CB6eC5aB70ce0dd52aF2d7b82e1972E"
129129
@echo export CARTESI_CONTRACTS_SELF_HOSTED_APPLICATION_FACTORY_ADDRESS="0x010D3CbB4223F5bCc7b7B03cEE59f3aAea8eDb8A"
130-
@echo export CARTESI_CONTRACTS_DAVE_APP_FACTORY_ADDRESS="0xfC2DBC639b5FB9AfE66A8696eC14EaD9FbFBC404"
130+
@echo export CARTESI_CONTRACTS_DAVE_APP_FACTORY_ADDRESS="0xbE70ae667546d5C0C57a0c96018C327bCb0fe796"
131131
@echo export CARTESI_AUTH_MNEMONIC=\"test test test test test test test test test test test junk\"
132132
@echo export CARTESI_DATABASE_CONNECTION="postgres://postgres:password@localhost:5432/rollupsdb?sslmode=disable"
133133
@echo export CARTESI_SNAPSHOTS_DIR="snapshots"

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

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

15-
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/root/app/util"
1615
"github.com/cartesi/rollups-node/internal/config"
1716
"github.com/cartesi/rollups-node/internal/model"
1817
"github.com/cartesi/rollups-node/internal/repository/factory"
1918
"github.com/cartesi/rollups-node/pkg/contracts/dataavailability"
19+
"github.com/cartesi/rollups-node/pkg/emulator"
2020
"github.com/cartesi/rollups-node/pkg/ethutil"
2121

2222
"github.com/ethereum/go-ethereum/common"
@@ -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 := emulator.ReadHash(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,14 +8,14 @@ import (
88
"encoding/json"
99
"fmt"
1010
"os"
11-
"path"
1211
"strings"
1312

1413
"github.com/cartesi/rollups-node/internal/config"
1514
"github.com/cartesi/rollups-node/internal/config/auth"
1615
"github.com/cartesi/rollups-node/internal/model"
1716
"github.com/cartesi/rollups-node/internal/repository/factory"
1817
"github.com/cartesi/rollups-node/pkg/contracts/iconsensus"
18+
"github.com/cartesi/rollups-node/pkg/emulator"
1919
"github.com/cartesi/rollups-node/pkg/ethutil"
2020
"github.com/ethereum/go-ethereum/accounts/abi/bind"
2121
"github.com/ethereum/go-ethereum/common"
@@ -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 = emulator.ReadHash(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 = emulator.ReadHash(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 = emulator.ReadHash(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))

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ func SpawnServer(address string, timeout time.Duration) (*RemoteMachine, string,
5050

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

pkg/emulator/machine.go

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ import (
1919

2020
const HashSize = C.sizeof_cm_hash
2121

22+
type SharingMode = C.cm_sharing_mode
23+
24+
const (
25+
SharingNone SharingMode = iota
26+
SharingConfig
27+
SharingAll
28+
)
29+
2230
// Common type aliases
2331
type Hash = [HashSize]byte
2432

@@ -58,11 +66,12 @@ func (m *Machine) Delete() {
5866
}
5967

6068
// create
61-
func (m *Machine) Create(config, runtimeConfig string) error {
69+
func (m *Machine) Create(config, runtimeConfig, dir string) error {
6270
var err error
6371
m.callCAPI(func() {
6472
var cConfig *C.char
6573
var cRuntime *C.char
74+
var cDir *C.char
6675
if config != "" {
6776
cConfig = C.CString(config)
6877
defer C.free(unsafe.Pointer(cConfig))
@@ -71,7 +80,11 @@ func (m *Machine) Create(config, runtimeConfig string) error {
7180
cRuntime = C.CString(runtimeConfig)
7281
defer C.free(unsafe.Pointer(cRuntime))
7382
}
74-
err = newError(C.cm_create_new(cConfig, cRuntime, &m.ptr))
83+
if dir != "" {
84+
cDir = C.CString(dir)
85+
defer C.free(unsafe.Pointer(cDir))
86+
}
87+
err = newError(C.cm_create_new(cConfig, cRuntime, cDir, &m.ptr))
7588
})
7689
return err
7790
}
@@ -119,35 +132,14 @@ func (m *Machine) GetInitialConfig() (string, error) {
119132
return res, nil
120133
}
121134

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-
143135
// get_proof
144136
func (m *Machine) GetProof(address uint64, log2size int32) (string, error) {
145137
var proof *C.char
146138
var err error
147139
var res string
148140

149141
m.callCAPI(func() {
150-
err = newError(C.cm_get_proof(m.ptr, C.uint64_t(address), C.int32_t(log2size), &proof))
142+
err = newError(C.cm_get_proof(m.ptr, C.uint64_t(address), C.int32_t(log2size), C.int32_t(HashTreeLog2RootSize), &proof))
151143
if err != nil || proof == nil {
152144
return
153145
}
@@ -241,7 +233,7 @@ func (m *Machine) Load(dir string, runtimeConfig string) error {
241233
cRuntime = C.CString(runtimeConfig)
242234
defer C.free(unsafe.Pointer(cRuntime))
243235
}
244-
err = newError(C.cm_load(m.ptr, cDir, cRuntime))
236+
err = newError(C.cm_load(m.ptr, cDir, cRuntime, SharingNone))
245237
})
246238

247239
return err
@@ -369,6 +361,53 @@ func (m *Machine) Run(mcycleEnd uint64) (BreakReason, error) {
369361
return BreakReason(br), nil
370362
}
371363

364+
// collect_mcycle_root_hashes
365+
func (m *Machine) CollectMCycleRootHashes(mcycleEnd, mcyclePeriod, mcyclePhase uint64, log2BundleMcycleCount int32, previousBackTree string) ([]byte, error) {
366+
var err error
367+
var result *C.char
368+
369+
m.callCAPI(func() {
370+
var previousBackTreeC *C.char
371+
if previousBackTree != "" {
372+
previousBackTreeC = C.CString(previousBackTree)
373+
defer C.free(unsafe.Pointer(previousBackTreeC))
374+
}
375+
err = newError(C.cm_collect_mcycle_root_hashes(
376+
m.ptr,
377+
C.uint64_t(mcycleEnd),
378+
C.uint64_t(mcyclePeriod),
379+
C.uint64_t(mcyclePhase),
380+
C.int32_t(log2BundleMcycleCount),
381+
previousBackTreeC,
382+
&result))
383+
})
384+
385+
if err != nil {
386+
return []byte{}, err
387+
}
388+
return []byte(C.GoString(result)), nil
389+
}
390+
391+
// collect_uarch_cycle_root_hashes
392+
func (m *Machine) CollectUarchCycleRootHashes(mcycleEnd uint64, log2BundleMcycleCount int32) ([]byte, error) {
393+
var err error
394+
var result *C.char
395+
396+
m.callCAPI(func() {
397+
err = newError(C.cm_collect_uarch_cycle_root_hashes(
398+
m.ptr,
399+
C.uint64_t(mcycleEnd),
400+
C.int32_t(log2BundleMcycleCount),
401+
&result))
402+
})
403+
404+
if err != nil {
405+
return []byte{}, err
406+
}
407+
return []byte(C.GoString(result)), nil
408+
}
409+
410+
372411
// send_cmio_response
373412
func (m *Machine) SendCmioResponse(reason uint16, data []byte) error {
374413
var err error
@@ -414,7 +453,7 @@ func (m *Machine) Store(directory string) error {
414453
m.callCAPI(func() {
415454
cDir := C.CString(directory)
416455
defer C.free(unsafe.Pointer(cDir))
417-
err = newError(C.cm_store(m.ptr, cDir))
456+
err = newError(C.cm_store(m.ptr, cDir, SharingAll))
418457
})
419458

420459
return err

0 commit comments

Comments
 (0)