Skip to content

Commit 3e8ec67

Browse files
committed
feat(emulator): bump emulator (v0.21.0) and rootfs (v0.18.0). make it build
1 parent deb34e0 commit 3e8ec67

21 files changed

Lines changed: 152 additions & 200 deletions

Dockerfile

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

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

6-
ARG EMULATOR_VERSION=0.20.0
6+
ARG EMULATOR_VERSION=0.21.0-test6
77

88
# Build directories.
99
ARG GO_BUILD_PATH=/build/cartesi/go
@@ -29,8 +29,8 @@ RUN <<EOF
2929
ARCH=$(dpkg --print-architecture)
3030
wget -O /tmp/cartesi-machine-emulator.deb "https://github.com/cartesi/machine-emulator/releases/download/v${EMULATOR_VERSION}/machine-emulator_${ARCH}.deb"
3131
case "$ARCH" in
32-
amd64) echo "46b2f37b889091df3b89a8909467935f8dd4a1426eeb0491b6a346a12f0c341c /tmp/cartesi-machine-emulator.deb" | sha256sum --check ;;
33-
arm64) echo "27ea10571335ad174b75388e7de54a3d3434bd607554d8c0bdf6abca47ceae0d /tmp/cartesi-machine-emulator.deb" | sha256sum --check ;;
32+
amd64) echo "df61b4ce4cfef1783dc378ad7647a83a337ac83ba2c78988b0717449d8b9f941 /tmp/cartesi-machine-emulator.deb" | sha256sum --check ;;
33+
arm64) echo "29cea4a43416c4c173c3db7b7892878c5968928c753779e9f0aebdc7524f9759 /tmp/cartesi-machine-emulator.deb" | sha256sum --check ;;
3434
*) echo "unsupported architecture: $ARCH"; exit 1 ;;
3535
esac
3636
apt-get install -y --no-install-recommends /tmp/cartesi-machine-emulator.deb

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,13 @@ withdraw-wallet: cartesi-rollups-cli ## Send a test withdrawal request from the
414414

415415
# Temporary test dependencies target while we are not using distribution packages
416416
DOWNLOADS_DIR = test/downloads
417-
CARTESI_TEST_MACHINE_IMAGES = $(DOWNLOADS_DIR)/linux.bin
417+
CARTESI_TEST_MACHINE_IMAGES = $(DOWNLOADS_DIR)/linux.bin $(DOWNLOADS_DIR)/rootfs.ext2
418418
$(CARTESI_TEST_MACHINE_IMAGES):
419419
@mkdir -p $(DOWNLOADS_DIR)
420420
@wget -nc -i test/dependencies -P $(DOWNLOADS_DIR)
421421
@shasum -ca 256 test/dependencies.sha256
422422
@cd $(DOWNLOADS_DIR) && ln -s rootfs-tools.ext2 rootfs.ext2
423-
@cd $(DOWNLOADS_DIR) && ln -s linux-6.5.13-ctsi-1-v0.20.0.bin linux.bin
423+
@cd $(DOWNLOADS_DIR) && ln -s linux-6.5.13-ctsi-2-uio-test1-v0.21.0.bin linux.bin
424424

425425
download-test-dependencies: | $(CARTESI_TEST_MACHINE_IMAGES)
426426

cmd/cartesi-rollups-machine-tool/main.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package main
66
import (
77
"bytes"
88
"context"
9+
"encoding/base64"
910
"encoding/json"
1011
"errors"
1112
"fmt"
@@ -165,7 +166,7 @@ func replayInputsBatch(ctx context.Context, opts replayOptions, tmp string, inpu
165166

166167
args := []string{
167168
"--quiet",
168-
"--no-rollback",
169+
"--no-revert",
169170
"--load=" + opts.Template,
170171
fmt.Sprintf("--cmio-advance-state=input:%s,input_index_begin:0,input_index_end:%d",
171172
filepath.Join(tmp, "input-%i.bin"), len(inputs)),
@@ -374,7 +375,7 @@ func generateMachineProof(
374375

375376
args := []string{
376377
"--quiet",
377-
"--no-rollback",
378+
"--no-revert",
378379
"--load=" + snapshot,
379380
fmt.Sprintf("--initial-proof=address:0x%x,log2_size:%d,filename:%s", address, log2Size, tmpPath),
380381
"--",
@@ -392,6 +393,23 @@ func generateMachineProof(
392393
if err := json.Unmarshal(raw, &proof); err != nil {
393394
return nil, fmt.Errorf("parse machine proof: %w", err)
394395
}
396+
397+
// convert the file hashes from base64 to hex
398+
proof.RootHash, err = base64ToHex(proof.RootHash)
399+
if err != nil {
400+
return nil, err
401+
}
402+
proof.TargetHash, err = base64ToHex(proof.TargetHash)
403+
if err != nil {
404+
return nil, err
405+
}
406+
for i := range proof.SiblingHashes {
407+
proof.SiblingHashes[i], err = base64ToHex(proof.SiblingHashes[i])
408+
if err != nil {
409+
return nil, err
410+
}
411+
}
412+
395413
return &proof, nil
396414
}
397415

@@ -478,3 +496,11 @@ func ensure0x(s string) string {
478496
func strip0x(s string) string {
479497
return strings.TrimPrefix(strings.TrimPrefix(s, "0x"), "0X")
480498
}
499+
500+
func base64ToHex(s string) (string, error) {
501+
raw, err := base64.StdEncoding.DecodeString(s)
502+
if err != nil {
503+
return "", fmt.Errorf("expected %s to be a hash in base64. %w", s, err)
504+
}
505+
return common.Hash(raw).Hex(), nil
506+
}

cmd/cartesi-rollups-machine-tool/replay_dave.lua

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
local cartesi = require("cartesi")
55

6-
local checkpoint_address = 0xfe0
7-
86
local function usage(message)
97
if message then io.stderr:write(message, "\n") end
108
io.stderr:write(
@@ -75,16 +73,15 @@ end
7573

7674
local function advance_one(machine, input_path, input_number)
7775
local checkpoint = machine:get_root_hash()
78-
machine:write_memory(checkpoint_address, checkpoint)
79-
machine:send_cmio_response(cartesi.CMIO_YIELD_REASON_ADVANCE_STATE, read_all(input_path))
76+
machine:send_cmio_response(checkpoint, cartesi.HTIF_YIELD_REASON_ADVANCE_STATE, read_all(input_path))
8077
run_until_manual_yield(machine)
8178

8279
local _, reason, data = machine:receive_cmio_request()
83-
if reason == cartesi.CMIO_YIELD_MANUAL_REASON_RX_REJECTED then
80+
if reason == cartesi.HTIF_YIELD_MANUAL_REASON_RX_REJECTED then
8481
error(string.format("Dave replay input %d was rejected", input_number))
85-
elseif reason == cartesi.CMIO_YIELD_MANUAL_REASON_TX_EXCEPTION then
82+
elseif reason == cartesi.HTIF_YIELD_MANUAL_REASON_TX_EXCEPTION then
8683
error(string.format("Dave replay input %d raised an exception", input_number))
87-
elseif reason ~= cartesi.CMIO_YIELD_MANUAL_REASON_RX_ACCEPTED then
84+
elseif reason ~= cartesi.HTIF_YIELD_MANUAL_REASON_RX_ACCEPTED then
8885
error(string.format("Dave replay input %d ended with unexpected yield reason %s", input_number, tostring(reason)))
8986
end
9087
if #data ~= 32 then

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.20.0), cartesi-machine-emulator (<< 0.21.0)
8+
Depends: cartesi-machine-emulator (>= 0.21.0), cartesi-machine-emulator (<< 0.22.0)
99
Section: net
1010
Priority: optional
1111
Multi-Arch: no

internal/manager/instance.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,6 @@ func (m *MachineInstanceImpl) Advance(ctx context.Context, input []byte, epochIn
299299
advanceCtx, cancel := context.WithTimeout(ctx, m.advanceTimeout)
300300
defer cancel()
301301

302-
if computeHashes {
303-
// write the checkpoint hash before processing
304-
err = fork.WriteCheckpointHash(advanceCtx, prevMachineHash)
305-
if err != nil {
306-
return nil, errors.Join(err, fork.Close())
307-
}
308-
}
309-
310302
// Process the input
311303
advanceResp, err := fork.Advance(advanceCtx, input, computeHashes)
312304
status, err := toInputStatus(advanceResp.Accepted, err)

internal/manager/instance_test.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,6 @@ func (s *MachineInstanceSuite) TestAdvance() {
507507
require := s.Require()
508508
inner, fork, machine := s.setupAdvance()
509509

510-
// Set up WriteCheckpointHash to succeed
511-
fork.CheckpointHashError = nil
512-
513510
res, err := machine.Advance(context.Background(), []byte{}, 0, 5, true)
514511
require.Nil(err)
515512
require.NotNil(res)
@@ -523,20 +520,6 @@ func (s *MachineInstanceSuite) TestAdvance() {
523520
_ = inner
524521
})
525522

526-
s.Run("CollectHashesWriteCheckpointError", func() {
527-
require := s.Require()
528-
_, fork, machine := s.setupAdvance()
529-
530-
errCheckpoint := errors.New("checkpoint write error")
531-
fork.CheckpointHashError = errCheckpoint
532-
533-
res, err := machine.Advance(context.Background(), []byte{}, 0, 5, true)
534-
require.Error(err)
535-
require.Nil(res)
536-
require.ErrorIs(err, errCheckpoint)
537-
require.Equal(uint64(5), machine.processedInputs.Load())
538-
})
539-
540523
s.Run("SequentialAdvances", func() {
541524
// Advance is serialized by advanceMutex — concurrent advance on the
542525
// same machine never happens by design. This test verifies that two
@@ -1475,8 +1458,6 @@ type MockRollupsMachine struct {
14751458
HashReturn machine.Hash
14761459
HashError error
14771460

1478-
CheckpointHashError error
1479-
14801461
AdvanceAcceptedReturn bool
14811462
AdvanceOutputsReturn []machine.Output
14821463
AdvanceReportsReturn []machine.Report
@@ -1516,10 +1497,6 @@ func (m *MockRollupsMachine) OutputsHashProof(_ context.Context) ([]machine.Hash
15161497
return m.OutputsHashProofReturn, m.OutputsHashProofError
15171498
}
15181499

1519-
func (m *MockRollupsMachine) WriteCheckpointHash(_ context.Context, _ machine.Hash) error {
1520-
return m.CheckpointHashError
1521-
}
1522-
15231500
func (m *MockRollupsMachine) Advance(_ context.Context, _ []byte, _ bool) (*machine.AdvanceResponse, error) {
15241501
return &machine.AdvanceResponse{
15251502
Accepted: m.AdvanceAcceptedReturn,

pkg/emulator/emulator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package emulator
88

99
// #cgo LDFLAGS: -lcartesi -lcartesi_jsonrpc
1010
// #include <stdlib.h>
11-
// #include "cartesi-machine/jsonrpc-machine-c-api.h"
11+
// #include "cartesi-machine/cm-jsonrpc.h"
1212
import "C"
1313

1414
import (

pkg/emulator/machine.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package emulator
88

99
// #include <stdlib.h>
1010
// #include <string.h>
11-
// #include "cartesi-machine/machine-c-api.h"
11+
// #include "cartesi-machine/cm.h"
1212
import "C"
1313

1414
import (
@@ -383,16 +383,22 @@ func (m *Machine) CollectMCycleRootHashes(mcycleEnd, mcyclePeriod, mcyclePhase u
383383
}
384384

385385
// collect_uarch_cycle_root_hashes
386-
func (m *Machine) CollectUarchCycleRootHashes(mcycleEnd uint64, log2BundleMcycleCount int32) ([]byte, error) {
386+
func (m *Machine) CollectUarchCycleRootHashes(mcycleEnd uint64, log2BundleUarchCycleCount int32, revertUarchTail string) ([]byte, error) {
387387
var err error
388388
var result []byte
389389

390390
m.callCAPI(func() {
391391
var cResult *C.char
392+
var revertUarchTailC *C.char
393+
if revertUarchTail != "" {
394+
revertUarchTailC = C.CString(revertUarchTail)
395+
defer C.free(unsafe.Pointer(revertUarchTailC))
396+
}
392397
err = newError(C.cm_collect_uarch_cycle_root_hashes(
393398
m.ptr,
394399
C.uint64_t(mcycleEnd),
395-
C.int32_t(log2BundleMcycleCount),
400+
C.int32_t(log2BundleUarchCycleCount),
401+
revertUarchTailC,
396402
&cResult))
397403
result = []byte(C.GoString(cResult))
398404
})
@@ -404,7 +410,7 @@ func (m *Machine) CollectUarchCycleRootHashes(mcycleEnd uint64, log2BundleMcycle
404410
}
405411

406412
// send_cmio_response
407-
func (m *Machine) SendCmioResponse(reason uint16, data []byte) error {
413+
func (m *Machine) SendCmioResponse(revertRootHash Hash, reason uint16, data []byte) error {
408414
var err error
409415

410416
m.callCAPI(func() {
@@ -413,9 +419,10 @@ func (m *Machine) SendCmioResponse(reason uint16, data []byte) error {
413419
if sizeData > 0 {
414420
ptrData = (*C.uint8_t)(unsafe.Pointer(&data[0]))
415421
}
416-
422+
//var cHash C.cm_hash = revertRootHash
417423
err = newError(C.cm_send_cmio_response(
418424
m.ptr,
425+
(*[32]C.uint8_t)(unsafe.Pointer(&revertRootHash)),
419426
C.uint16_t(reason),
420427
ptrData,
421428
sizeData,

pkg/emulator/remote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
package emulator
88

99
// #include <stdlib.h>
10-
// #include "cartesi-machine/jsonrpc-machine-c-api.h"
10+
// #include "cartesi-machine/cm-jsonrpc.h"
1111
import "C"
1212

1313
import (

0 commit comments

Comments
 (0)