Skip to content

Commit 693cea8

Browse files
committed
fixup! feat(emulator): bump emulator (v0.21.0) and rootfs (v0.18.0). make it build
1 parent 6c1659b commit 693cea8

3 files changed

Lines changed: 45 additions & 7 deletions

File tree

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

Lines changed: 27 additions & 0 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"
@@ -19,6 +20,7 @@ import (
1920
"github.com/cartesi/rollups-node/internal/model"
2021
"github.com/cartesi/rollups-node/internal/repository"
2122
"github.com/cartesi/rollups-node/internal/repository/factory"
23+
//"github.com/davecgh/go-spew/spew"
2224
"github.com/ethereum/go-ethereum/common"
2325
"github.com/ethereum/go-ethereum/common/hexutil"
2426
"github.com/spf13/cobra"
@@ -392,6 +394,23 @@ func generateMachineProof(
392394
if err := json.Unmarshal(raw, &proof); err != nil {
393395
return nil, fmt.Errorf("parse machine proof: %w", err)
394396
}
397+
398+
// convert the file hashes from base64 to hex
399+
proof.RootHash, err = base64ToHex(proof.RootHash)
400+
if err != nil {
401+
return nil, err
402+
}
403+
proof.TargetHash, err = base64ToHex(proof.TargetHash)
404+
if err != nil {
405+
return nil, err
406+
}
407+
for i := range proof.SiblingHashes {
408+
proof.SiblingHashes[i], err = base64ToHex(proof.SiblingHashes[i])
409+
if err != nil {
410+
return nil, err
411+
}
412+
}
413+
395414
return &proof, nil
396415
}
397416

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

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

test/integration/withdrawal_lifecycle_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"bytes"
1010
"context"
1111
"encoding/json"
12+
"encoding/base64"
1213
"errors"
1314
"fmt"
1415
"math/big"
@@ -28,6 +29,7 @@ import (
2829
"github.com/cartesi/rollups-node/pkg/contracts/ierc20metadata"
2930
"github.com/cartesi/rollups-node/pkg/contracts/iquorum"
3031
"github.com/cartesi/rollups-node/pkg/ethutil"
32+
"github.com/davecgh/go-spew/spew"
3133
"github.com/ethereum/go-ethereum/accounts/abi"
3234
"github.com/ethereum/go-ethereum/accounts/abi/bind"
3335
"github.com/ethereum/go-ethereum/common"
@@ -580,7 +582,9 @@ func (s *WithdrawalLifecycleSuite) generateWithdrawalProofs(
580582
var replaySummary struct {
581583
MachineRoot string `json:"machine_root"`
582584
}
585+
fmt.Print("1.", string(replayOut))
583586
r.NoError(json.Unmarshal([]byte(replayOut), &replaySummary), "parse machine replay summary")
587+
spew.Dump(replaySummary)
584588
r.Equal(strings.ToLower(finalEpoch.MachineHash.Hex()), strings.ToLower(replaySummary.MachineRoot),
585589
"replayed machine root must match finalized epoch machine hash")
586590

@@ -600,7 +604,9 @@ func (s *WithdrawalLifecycleSuite) generateWithdrawalProofs(
600604
AccountIndex string `json:"account_index"`
601605
MachineRoot string `json:"machine_root"`
602606
}
607+
fmt.Print("2.", string(proveOut))
603608
r.NoError(json.Unmarshal([]byte(proveOut), &proveSummary), "parse accounts-drive proof summary")
609+
spew.Dump(proveSummary)
604610
r.Equal(strings.ToLower(finalEpoch.MachineHash.Hex()), strings.ToLower(proveSummary.MachineRoot),
605611
"proof machine root must match finalized epoch machine hash")
606612
r.NotEmpty(proveSummary.AccountIndex, "proof summary must include account index")
@@ -827,3 +833,11 @@ func listWithdrawals(
827833
}
828834
return rpcResp.Result, nil
829835
}
836+
837+
func base64ToHex(s string) (string, error) {
838+
raw, err := base64.StdEncoding.DecodeString(s)
839+
if err != nil {
840+
return "", fmt.Errorf("expected %s to be a hash in base64. %w", s, err)
841+
}
842+
return common.Hash(raw).Hex(), nil
843+
}

0 commit comments

Comments
 (0)