Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

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

ARG EMULATOR_VERSION=0.19.0
ARG EMULATOR_VERSION=0.20.0

# Build directories.
ARG GO_BUILD_PATH=/build/cartesi/go

FROM debian:bookworm-20250407 AS common-env
FROM debian:trixie-20250811 AS common-env

USER root

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

FROM debian:bookworm-20250407 AS rollups-node
FROM debian:trixie-20250811 AS rollups-node

ARG NODE_RUNTIME_DIR=/var/lib/cartesi-rollups-node
ARG GO_BUILD_PATH
Expand All @@ -164,8 +164,8 @@ COPY --from=debian-packager \
ARG DEBIAN_FRONTEND=noninteractive
RUN <<EOF
set -e
addgroup --system --gid 102 cartesi
adduser --system --uid 102 --ingroup cartesi --disabled-login --no-create-home --home /nonexistent --gecos "cartesi user" --shell /bin/false cartesi
groupadd --system --gid 102 cartesi
useradd --system --uid 102 --gid cartesi --shell /usr/sbin/nologin --no-create-home cartesi
apt-get update
apt-get install -y --no-install-recommends \
ca-certificates \
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ env:
@echo export CARTESI_BLOCKCHAIN_HTTP_ENDPOINT="http://localhost:8545"
@echo export CARTESI_BLOCKCHAIN_WS_ENDPOINT="ws://localhost:8545"
@echo export CARTESI_BLOCKCHAIN_ID="31337"
@echo export CARTESI_CONTRACTS_INPUT_BOX_ADDRESS="0x1b51e2992A2755Ba4D6F7094032DF91991a0Cfac"
@echo export CARTESI_CONTRACTS_INPUT_BOX_ADDRESS="0x606c3Ab81a862BEA826Fb3C9395F328f0E465294"
@echo export CARTESI_CONTRACTS_AUTHORITY_FACTORY_ADDRESS="0x5E96408CFE423b01dADeD3bc867E6013135990cc"
@echo export CARTESI_CONTRACTS_APPLICATION_FACTORY_ADDRESS="0x26E758238CB6eC5aB70ce0dd52aF2d7b82e1972E"
@echo export CARTESI_CONTRACTS_SELF_HOSTED_APPLICATION_FACTORY_ADDRESS="0x010D3CbB4223F5bCc7b7B03cEE59f3aAea8eDb8A"
@echo export CARTESI_CONTRACTS_DAVE_APP_FACTORY_ADDRESS="0xfC2DBC639b5FB9AfE66A8696eC14EaD9FbFBC404"
@echo export CARTESI_CONTRACTS_DAVE_APP_FACTORY_ADDRESS="0xbE70ae667546d5C0C57a0c96018C327bCb0fe796"
@echo export CARTESI_AUTH_MNEMONIC=\"test test test test test test test test test test test junk\"
@echo export CARTESI_DATABASE_CONNECTION="postgres://postgres:password@localhost:5432/rollupsdb?sslmode=disable"
@echo export CARTESI_SNAPSHOTS_DIR="snapshots"
Expand Down
5 changes: 2 additions & 3 deletions cmd/cartesi-rollups-cli/root/app/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"os"
"strings"

"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/root/app/util"
"github.com/cartesi/rollups-node/internal/config"
"github.com/cartesi/rollups-node/internal/model"
"github.com/cartesi/rollups-node/internal/repository/factory"
"github.com/cartesi/rollups-node/pkg/contracts/dataavailability"
"github.com/cartesi/rollups-node/pkg/emulator"
"github.com/cartesi/rollups-node/pkg/ethutil"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -143,12 +143,11 @@ func run(cmd *cobra.Command, args []string) {
checkEnabled, err := config.GetFeatureMachineHashCheckEnabled()
cobra.CheckErr(err)
if checkEnabled {
templateHash, err := util.ReadHash(templatePath)
snapshotTemplateHash, err := emulator.ReadHash(templatePath)
if err != nil {
fmt.Fprintf(os.Stderr, "Read machine template hash failed: %v\n", err)
os.Exit(1)
}
snapshotTemplateHash := common.HexToHash(templateHash)
if parsedTemplateHash != snapshotTemplateHash {
fmt.Fprintf(os.Stderr, "Template hash mismatch: contract has %s but machine has %s\n",
parsedTemplateHash.Hex(), snapshotTemplateHash.Hex())
Expand Down
29 changes: 0 additions & 29 deletions cmd/cartesi-rollups-cli/root/app/util/machine.go

This file was deleted.

25 changes: 4 additions & 21 deletions cmd/cartesi-rollups-cli/root/deploy/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"encoding/json"
"fmt"
"os"
"path"
"strings"

"github.com/cartesi/rollups-node/internal/config"
"github.com/cartesi/rollups-node/internal/config/auth"
"github.com/cartesi/rollups-node/internal/model"
"github.com/cartesi/rollups-node/internal/repository/factory"
"github.com/cartesi/rollups-node/pkg/contracts/iconsensus"
"github.com/cartesi/rollups-node/pkg/emulator"
"github.com/cartesi/rollups-node/pkg/ethutil"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -360,7 +360,7 @@ func buildSelfhostedApplicationDeployment(

if !cmd.Flags().Changed("template-hash") {
if len(args) >= 2 { // args[1] is mandatory if `template-hash` was absent
request.TemplateHash, err = readHash(args[1])
request.TemplateHash, err = emulator.ReadHash(args[1])
} else {
err = fmt.Errorf("missing argument. One of `template-path` or `template-hash` is required")
}
Expand Down Expand Up @@ -435,7 +435,7 @@ func buildApplicationOnlyDeployment(

if !cmd.Flags().Changed("template-hash") {
if len(args) >= 2 { // args[1] is mandatory if `template-hash` was absent
request.TemplateHash, err = readHash(args[1])
request.TemplateHash, err = emulator.ReadHash(args[1])
} else {
err = fmt.Errorf("missing argument. One of `template-path` or `template-hash` is required")
}
Expand Down Expand Up @@ -515,7 +515,7 @@ func buildPrtApplicationDeployment(

if !cmd.Flags().Changed("template-hash") {
if len(args) >= 2 { // args[1] is mandatory if `template-hash` was absent
request.TemplateHash, err = readHash(args[1])
request.TemplateHash, err = emulator.ReadHash(args[1])
} else {
err = fmt.Errorf("missing argument. One of `template-path` or `template-hash` is required")
}
Expand All @@ -535,23 +535,6 @@ func buildPrtApplicationDeployment(
return request, nil
}

// read the hash value from the cartesi machine hash file
func readHash(machineDir string) (common.Hash, error) {
zero := common.Hash{}
path := path.Join(machineDir, "hash")
hash, err := os.ReadFile(path)
if err != nil {
return zero, fmt.Errorf("read hash: %w", err)
} else if len(hash) != common.HashLength {
return zero, fmt.Errorf(
"read hash: wrong size; expected %v bytes but read %v",
common.HashLength,
len(hash),
)
}
return common.BytesToHash(hash), nil
}

func parseHexHash(hash string) (common.Hash, error) {
out := common.Hash{}
return out, out.UnmarshalText([]byte(hash))
Expand Down
2 changes: 1 addition & 1 deletion control.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Homepage: https://docs.cartesi.io/cartesi-rollups/
Architecture: ARG_ARCH
Maintainer: Node Reference Unit <https://discord.com/channels/600597137524391947/1110564973115097179>
Provides: cartesi-rollups-node
Depends: cartesi-machine-emulator (>= 0.19.0), cartesi-machine-emulator (<< 0.20.0)
Depends: cartesi-machine-emulator (>= 0.20.0), cartesi-machine-emulator (<< 0.21.0)
Section: net
Priority: optional
Multi-Arch: no
Expand Down
2 changes: 1 addition & 1 deletion internal/advancer/advancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (s *Service) processInputs(ctx context.Context, app *Application, inputs []
"outputs", len(result.Outputs),
"reports", len(result.Reports),
"hashes", len(result.Hashes),
"remaining_cycles", result.RemainingMetaCycles,
"remaining_cycles", result.TotalMetaCycles,
)

// Store the result in the database
Expand Down
17 changes: 9 additions & 8 deletions internal/manager/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@ func (m *MachineInstanceImpl) Advance(ctx context.Context, input []byte, epochIn

// Create the result
result := &AdvanceResult{
EpochIndex: epochIndex,
InputIndex: index,
Status: status,
Outputs: advanceResp.Outputs,
Reports: advanceResp.Reports,
Hashes: advanceResp.Hashes,
RemainingMetaCycles: advanceResp.RemainingCycles,
IsDaveConsensus: computeHashes,
EpochIndex: epochIndex,
InputIndex: index,
Status: status,
Outputs: advanceResp.Outputs,
Reports: advanceResp.Reports,
Hashes: advanceResp.Hashes,
TotalMetaCycles: advanceResp.RemainingCycles,
IsDaveConsensus: computeHashes,
}

// If the input was accepted, update the machine state
Expand Down Expand Up @@ -354,6 +354,7 @@ func (m *MachineInstanceImpl) Advance(ctx context.Context, input []byte, epochIn
result.MachineHash = prevMachineHash
result.OutputsHash = prevOutputsHash
result.OutputsHashProof = prevOutputsHashProof
result.Hashes[len(result.Hashes)-1] = prevMachineHash

// Close the fork since we're not using it
if err := fork.Close(); err != nil {
Expand Down
16 changes: 8 additions & 8 deletions internal/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -1032,14 +1032,14 @@ type OutputsProof struct {

type AdvanceResult struct {
OutputsProof
EpochIndex uint64
InputIndex uint64
Status InputCompletionStatus
Outputs [][]byte
Reports [][]byte
Hashes [][32]byte
RemainingMetaCycles uint64
IsDaveConsensus bool
EpochIndex uint64
InputIndex uint64
Status InputCompletionStatus
Outputs [][]byte
Reports [][]byte
Hashes [][32]byte
TotalMetaCycles uint64
IsDaveConsensus bool
}

type InspectResult struct {
Expand Down
19 changes: 10 additions & 9 deletions internal/repository/postgres/bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,9 @@ func insertStateHashes(
epochIndex uint64,
inputIndex uint64,
hashes [][32]byte,
machineHash common.Hash,
remainingMetaCycles uint64,
totalMetaCycles uint64,
) error {

usedMetaCycles := uint64(0)
nextIndex, err := getStateHashNextIndex(ctx, tx, appID, epochIndex)
if err != nil {
return err
Expand All @@ -217,24 +216,26 @@ func insertStateHashes(
table.StateHashes.Repetitions,
)

for i, h := range hashes {
for i := range len(hashes) - 1 {
usedMetaCycles += 1
stmt = stmt.VALUES(
appID,
epochIndex,
inputIndex,
nextIndex+uint64(i),
h[:],
hashes[i][:],
1,
)
}

// the remaining meta cycles go to the fixed-point
stmt = stmt.VALUES(
appID,
epochIndex,
inputIndex,
nextIndex+uint64(len(hashes)),
machineHash[:],
remainingMetaCycles,
nextIndex+uint64(len(hashes)-1),
hashes[len(hashes)-1][:],
totalMetaCycles-usedMetaCycles,
)

sqlStr, args := stmt.Sql()
Expand Down Expand Up @@ -373,7 +374,7 @@ func (r *PostgresRepository) StoreAdvanceResult(
}

if res.IsDaveConsensus {
err = insertStateHashes(ctx, tx, appID, res.EpochIndex, res.InputIndex, res.Hashes, res.MachineHash, res.RemainingMetaCycles)
err = insertStateHashes(ctx, tx, appID, res.EpochIndex, res.InputIndex, res.Hashes, res.TotalMetaCycles)
if err != nil {
return err
}
Expand Down
28 changes: 14 additions & 14 deletions internal/repository/repotest/bulk_test_cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ func (s *BulkOperationsSuite) TestStoreAdvanceResult() {
hash3 := [32]byte(crypto.Keccak256Hash([]byte("state-3")))

result := &AdvanceResult{
EpochIndex: 0,
InputIndex: 0,
Status: InputCompletionStatus_Accepted,
Outputs: [][]byte{[]byte("dave-output")},
Hashes: [][32]byte{hash1, hash2, hash3},
RemainingMetaCycles: 42,
IsDaveConsensus: true,
EpochIndex: 0,
InputIndex: 0,
Status: InputCompletionStatus_Accepted,
Outputs: [][]byte{[]byte("dave-output")},
Hashes: [][32]byte{hash1, hash2, hash3},
TotalMetaCycles: 42,
IsDaveConsensus: true,
OutputsProof: OutputsProof{
OutputsHash: outputsHash,
MachineHash: machineHash,
Expand Down Expand Up @@ -318,13 +318,13 @@ func (s *BulkOperationsSuite) TestStoreAdvanceResultRollback() {
seed := Seed(s.Ctx, s.T(), s.Repo)

result := &AdvanceResult{
EpochIndex: 99, // non-existent epoch
InputIndex: 0,
Status: InputCompletionStatus_Accepted,
Outputs: [][]byte{[]byte("should-be-rolled-back")},
Hashes: [][32]byte{{1}, {2}},
RemainingMetaCycles: 10,
IsDaveConsensus: true,
EpochIndex: 99, // non-existent epoch
InputIndex: 0,
Status: InputCompletionStatus_Accepted,
Outputs: [][]byte{[]byte("should-be-rolled-back")},
Hashes: [][32]byte{{1}, {2}},
TotalMetaCycles: 10,
IsDaveConsensus: true,
OutputsProof: OutputsProof{
OutputsHash: UniqueHash(),
MachineHash: UniqueHash(),
Expand Down
12 changes: 6 additions & 6 deletions internal/repository/repotest/state_hash_test_cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func (s *StateHashSuite) TestListStateHashes() {
hash2 := [32]byte(crypto.Keccak256Hash([]byte("list-state-2")))

result := &AdvanceResult{
EpochIndex: 0,
InputIndex: 0,
Status: InputCompletionStatus_Accepted,
Hashes: [][32]byte{hash1, hash2},
RemainingMetaCycles: 10,
IsDaveConsensus: true,
EpochIndex: 0,
InputIndex: 0,
Status: InputCompletionStatus_Accepted,
Hashes: [][32]byte{hash1, hash2},
TotalMetaCycles: 10,
IsDaveConsensus: true,
OutputsProof: OutputsProof{
OutputsHash: outputsHash,
MachineHash: machineHash,
Expand Down
4 changes: 2 additions & 2 deletions pkg/emulator/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func SpawnServer(address string, timeout time.Duration) (*RemoteMachine, string,
return &RemoteMachine{Machine: Machine{ptr: cm}}, C.GoString(boundAddr), uint32(pid), nil
}

func CreateMachine(config, runtimeConfig string) (*Machine, error) {
func CreateMachine(config, runtimeConfig, dir string) (*Machine, error) {
machine := &Machine{}
err := machine.Create(config, runtimeConfig)
err := machine.Create(config, runtimeConfig, dir)
return machine, err
}
Loading
Loading