Skip to content

Commit

Permalink
Remove the global state for HotShot height (#210)
Browse files Browse the repository at this point in the history
* Remove the global state

* Update the submodule
  • Loading branch information
ImJeremyHe committed Aug 28, 2024
1 parent 06581bf commit ae84633
Show file tree
Hide file tree
Showing 21 changed files with 41 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/espresso-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true

Expand Down
5 changes: 2 additions & 3 deletions arbitrator/jit/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub struct WasmEnv {
/// Go's general runtime state
pub go_state: GoRuntimeState,
/// An ordered list of the 8-byte globals
pub small_globals: [u64; 3],
pub small_globals: [u64; 2],
/// An ordered list of the 32-byte globals
pub large_globals: [Bytes32; 2],
/// An oracle allowing the prover to reverse keccak256
Expand Down Expand Up @@ -288,7 +288,7 @@ impl WasmEnv {

let last_block_hash = parse_hex(&opts.last_block_hash, "--last-block-hash")?;
let last_send_root = parse_hex(&opts.last_send_root, "--last-send-root")?;
env.small_globals = [opts.inbox_position, opts.position_within_message, 0];
env.small_globals = [opts.inbox_position, opts.position_within_message];
env.large_globals = [last_block_hash, last_send_root];
Ok(env)
}
Expand Down Expand Up @@ -318,7 +318,6 @@ impl WasmEnv {
check!(socket::write_u8(writer, socket::SUCCESS));
check!(socket::write_u64(writer, self.small_globals[0]));
check!(socket::write_u64(writer, self.small_globals[1]));
check!(socket::write_u64(writer, self.small_globals[2]));
check!(socket::write_bytes32(writer, &self.large_globals[0]));
check!(socket::write_bytes32(writer, &self.large_globals[1]));
check!(socket::write_u64(writer, memory_used.bytes().0 as u64));
Expand Down
7 changes: 1 addition & 6 deletions arbitrator/jit/src/wavmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,11 @@ fn ready_hostio(env: &mut WasmEnv) -> MaybeEscape {
let position_within_message = socket::read_u64(stream)?;
let last_block_hash = socket::read_bytes32(stream)?;
let last_send_root = socket::read_bytes32(stream)?;
let validated_hotshot_height = socket::read_u64(stream)?;
let hotshot_comm = socket::read_bytes32(stream)?;
let block_height = socket::read_u64(stream)?;
let hotshot_liveness = socket::read_u8(stream)?;

env.small_globals = [
inbox_position,
position_within_message,
validated_hotshot_height,
];
env.small_globals = [inbox_position, position_within_message];
env.large_globals = [last_block_hash, last_send_root];
if hotshot_liveness > 0 {
// HotShot is up
Expand Down
2 changes: 1 addition & 1 deletion arbitrator/prover/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ impl From<Function> for FunctionSerdeAll {
// uint64 - position_within_message
// uint64 - espresso hotshot height
pub const GLOBAL_STATE_BYTES32_NUM: usize = 2;
pub const GLOBAL_STATE_U64_NUM: usize = 3;
pub const GLOBAL_STATE_U64_NUM: usize = 2;

#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[repr(C)]
Expand Down
8 changes: 1 addition & 7 deletions arbitrator/prover/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ struct Opts {
skip_until_host_io: bool,
#[structopt(long)]
max_steps: Option<u64>,
#[structopt(long, default_value = "0")]
hotshot_height: u64,
}

fn file_with_stub_header(path: &Path, headerlength: usize) -> Result<Vec<u8>> {
Expand Down Expand Up @@ -186,11 +184,7 @@ fn main() -> Result<()> {
let last_send_root = decode_hex_arg(&opts.last_send_root, "--last-send-root")?;

let global_state = GlobalState {
u64_vals: [
opts.inbox_position,
opts.position_within_message,
opts.hotshot_height,
],
u64_vals: [opts.inbox_position, opts.position_within_message],
bytes32_vals: [last_block_hash, last_send_root],
};

Expand Down
3 changes: 0 additions & 3 deletions arbos/block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ func FinalizeBlock(header *types.Header, txs types.Transactions, statedb *state.
var sendCount uint64
var nextL1BlockNumber uint64
var arbosVersion uint64
var hotShotHeight uint64

if header.Number.Uint64() == chainConfig.ArbitrumChainParams.GenesisBlockNum {
arbosVersion = chainConfig.ArbitrumChainParams.InitialArbOSVersion
Expand All @@ -572,14 +571,12 @@ func FinalizeBlock(header *types.Header, txs types.Transactions, statedb *state.
sendCount, _ = acc.Size()
nextL1BlockNumber, _ = state.Blockhashes().L1BlockNumber()
arbosVersion = state.ArbOSVersion()
hotShotHeight = binary.BigEndian.Uint64(header.MixDigest[24:32])
}
arbitrumHeader := types.HeaderInfo{
SendRoot: sendRoot,
SendCount: sendCount,
L1BlockNumber: nextL1BlockNumber,
ArbOSFormatVersion: arbosVersion,
HotShotHeight: hotShotHeight,
}
arbitrumHeader.UpdateHeaderWithInfo(header)
header.Root = statedb.IntermediateRoot(true)
Expand Down
4 changes: 2 additions & 2 deletions cmd/replay/espresso_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"

"github.com/offchainlabs/nitro/arbos"
"github.com/offchainlabs/nitro/arbos/arbostypes"
"github.com/offchainlabs/nitro/wavmio"
Expand All @@ -21,10 +22,9 @@ import (
func handleEspressoPreConditions(message *arbostypes.MessageWithMetadata, isEnabled bool) (bool, func()) {
// calculate and cache all values needed to determine if the preconditions are met to enter the Espresso STF logic
isNonEspressoMessage := arbos.IsL2NonEspressoMsg(message.Message)
hotshotHeight := wavmio.GetEspressoHeight()

validatingEspressoLivenessFailure := isNonEspressoMessage && isEnabled
validatingEspressoHeightFailure := isNonEspressoMessage && hotshotHeight != 0
validatingEspressoHeightFailure := isNonEspressoMessage && isEnabled
validatingAgainstEspresso := arbos.IsEspressoMsg(message.Message) && isEnabled

if validatingEspressoLivenessFailure {
Expand Down
13 changes: 0 additions & 13 deletions cmd/replay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,19 +300,6 @@ func main() {
hotshotHeader := jst.Header
height := hotshotHeader.Height

// Check the continuity of the hotshot block if we are not running the sovereign sequencer.
if !arbos.IsEspressoSovereignMsg(message.Message) {
validatedHeight := wavmio.GetEspressoHeight()
if validatedHeight == 0 {
// Validators can choose their own trusted starting point to start their validation.
// TODO: Check the starting point is greater than the first valid hotshot block number.
wavmio.SetEspressoHeight(height)
} else if validatedHeight+1 == height {
wavmio.SetEspressoHeight(height)
} else {
panic(fmt.Sprintf("invalid hotshot block height: %v, got: %v", height, validatedHeight+1))
}
}
if jst.BlockMerkleJustification == nil {
panic("block merkle justification missing")
}
Expand Down
5 changes: 2 additions & 3 deletions execution/gethexec/executionengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,9 +789,8 @@ func (s *ExecutionEngine) resultFromHeader(header *types.Header) (*execution.Mes
}
info := types.DeserializeHeaderExtraInformation(header)
return &execution.MessageResult{
BlockHash: header.Hash(),
SendRoot: info.SendRoot,
HotShotHeight: info.HotShotHeight,
BlockHash: header.Hash(),
SendRoot: info.SendRoot,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion go-ethereum
9 changes: 4 additions & 5 deletions staker/block_challenge_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,10 @@ func (b *BlockChallengeBackend) FindGlobalStateFromMessageCount(count arbutil.Me
}

return validator.GoGlobalState{
BlockHash: res.BlockHash,
SendRoot: res.SendRoot,
Batch: batch,
PosInBatch: uint64(count - prevBatchMsgCount),
HotShotHeight: res.HotShotHeight,
BlockHash: res.BlockHash,
SendRoot: res.SendRoot,
Batch: batch,
PosInBatch: uint64(count - prevBatchMsgCount),
}, nil
}

Expand Down
14 changes: 6 additions & 8 deletions staker/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,8 @@ func (v *BlockValidator) createNextValidationEntry(ctx context.Context) (bool, e
v.nextCreateBatchReread = false
}
endGS := validator.GoGlobalState{
BlockHash: endRes.BlockHash,
SendRoot: endRes.SendRoot,
HotShotHeight: endRes.HotShotHeight,
BlockHash: endRes.BlockHash,
SendRoot: endRes.SendRoot,
}
if pos+1 < v.nextCreateBatchMsgCount {
endGS.Batch = v.nextCreateStartGS.Batch
Expand Down Expand Up @@ -1187,11 +1186,10 @@ func (v *BlockValidator) checkLegacyValid() error {
return fmt.Errorf("legacy validated blockHash does not fit chain")
}
validGS := validator.GoGlobalState{
BlockHash: result.BlockHash,
SendRoot: result.SendRoot,
Batch: v.legacyValidInfo.AfterPosition.BatchNumber,
PosInBatch: v.legacyValidInfo.AfterPosition.PosInBatch,
HotShotHeight: result.HotShotHeight,
BlockHash: result.BlockHash,
SendRoot: result.SendRoot,
Batch: v.legacyValidInfo.AfterPosition.BatchNumber,
PosInBatch: v.legacyValidInfo.AfterPosition.PosInBatch,
}
err = v.writeLastValidated(validGS, nil)
if err == nil {
Expand Down
1 change: 0 additions & 1 deletion staker/l1_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ func (v *L1Validator) generateNodeAction(
log.Error("Found incorrect assertion: Machine status not finished", "node", nd.NodeNum, "machineStatus", nd.Assertion.AfterState.MachineStatus)
continue
}

caughtUp, nodeMsgCount, err := GlobalStateToMsgCount(v.inboxTracker, v.txStreamer, afterGS)
if errors.Is(err, ErrGlobalStateNotInChain) {
wrongNodesExist = true
Expand Down
9 changes: 4 additions & 5 deletions staker/stateless_block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,10 @@ func (v *StatelessBlockValidator) ValidationEntryRecord(ctx context.Context, e *

func buildGlobalState(res execution.MessageResult, pos GlobalStatePosition) validator.GoGlobalState {
return validator.GoGlobalState{
BlockHash: res.BlockHash,
SendRoot: res.SendRoot,
Batch: pos.BatchNumber,
PosInBatch: pos.PosInBatch,
HotShotHeight: res.HotShotHeight,
BlockHash: res.BlockHash,
SendRoot: res.SendRoot,
Batch: pos.BatchNumber,
PosInBatch: pos.PosInBatch,
}
}

Expand Down
4 changes: 2 additions & 2 deletions system_tests/full_challenge_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ func CreateChallenge(
[2]mocksgen.GlobalState{
{
Bytes32Vals: [2][32]byte{startGlobalState.BlockHash, startGlobalState.SendRoot},
U64Vals: [3]uint64{startGlobalState.Batch, startGlobalState.PosInBatch},
U64Vals: [2]uint64{startGlobalState.Batch, startGlobalState.PosInBatch},
},
{
Bytes32Vals: [2][32]byte{endGlobalState.BlockHash, endGlobalState.SendRoot},
U64Vals: [3]uint64{endGlobalState.Batch, endGlobalState.PosInBatch},
U64Vals: [2]uint64{endGlobalState.Batch, endGlobalState.PosInBatch},
},
},
numBlocks,
Expand Down
21 changes: 9 additions & 12 deletions validator/execution_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import (
)

type GoGlobalState struct {
BlockHash common.Hash
SendRoot common.Hash
Batch uint64
PosInBatch uint64
HotShotHeight uint64
BlockHash common.Hash
SendRoot common.Hash
Batch uint64
PosInBatch uint64
}

type MachineStatus uint8
Expand Down Expand Up @@ -45,14 +44,13 @@ func (s GoGlobalState) Hash() common.Hash {
data = append(data, s.SendRoot.Bytes()...)
data = append(data, u64ToBe(s.Batch)...)
data = append(data, u64ToBe(s.PosInBatch)...)
data = append(data, u64ToBe(s.HotShotHeight)...)
return crypto.Keccak256Hash(data)
}

func (s GoGlobalState) AsSolidityStruct() challengegen.GlobalState {
return challengegen.GlobalState{
Bytes32Vals: [2][32]byte{s.BlockHash, s.SendRoot},
U64Vals: [3]uint64{s.Batch, s.PosInBatch, s.HotShotHeight},
U64Vals: [2]uint64{s.Batch, s.PosInBatch},
}
}

Expand All @@ -65,11 +63,10 @@ func NewExecutionStateFromSolidity(eth rollupgen.ExecutionState) *ExecutionState

func GoGlobalStateFromSolidity(gs challengegen.GlobalState) GoGlobalState {
return GoGlobalState{
BlockHash: gs.Bytes32Vals[0],
SendRoot: gs.Bytes32Vals[1],
Batch: gs.U64Vals[0],
PosInBatch: gs.U64Vals[1],
HotShotHeight: gs.U64Vals[2],
BlockHash: gs.Bytes32Vals[0],
SendRoot: gs.Bytes32Vals[1],
Batch: gs.U64Vals[0],
PosInBatch: gs.U64Vals[1],
}
}

Expand Down
10 changes: 4 additions & 6 deletions validator/server_arb/prover_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func GlobalStateToC(gsIn validator.GoGlobalState) C.GlobalState {
gs := C.GlobalState{}
gs.u64_vals[0] = C.uint64_t(gsIn.Batch)
gs.u64_vals[1] = C.uint64_t(gsIn.PosInBatch)
gs.u64_vals[2] = C.uint64_t(gsIn.HotShotHeight)
for i, b := range gsIn.BlockHash {
gs.bytes32_vals[0].bytes[i] = C.uint8_t(b)
}
Expand All @@ -65,11 +64,10 @@ func GlobalStateFromC(gs C.GlobalState) validator.GoGlobalState {
sendRoot[i] = byte(gs.bytes32_vals[1].bytes[i])
}
return validator.GoGlobalState{
Batch: uint64(gs.u64_vals[0]),
PosInBatch: uint64(gs.u64_vals[1]),
BlockHash: blockHash,
SendRoot: sendRoot,
HotShotHeight: uint64(gs.u64_vals[2]),
Batch: uint64(gs.u64_vals[0]),
PosInBatch: uint64(gs.u64_vals[1]),
BlockHash: blockHash,
SendRoot: sendRoot,
}
}

Expand Down
6 changes: 0 additions & 6 deletions validator/server_jit/jit_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ func (machine *JitMachine) prove(
if err := writeExact(entry.StartState.SendRoot[:]); err != nil {
return state, err
}
if err := writeUint64(entry.StartState.HotShotHeight); err != nil {
return state, err
}
if err := writeExact(entry.HotShotCommitment[:]); err != nil {
return state, err
}
Expand Down Expand Up @@ -293,9 +290,6 @@ func (machine *JitMachine) prove(
if state.PosInBatch, err = readUint64(); err != nil {
return state, err
}
if state.HotShotHeight, err = readUint64(); err != nil {
return state, err
}
if state.BlockHash, err = readHash(); err != nil {
return state, err
}
Expand Down
9 changes: 0 additions & 9 deletions wavmio/higher.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const IDX_SEND_ROOT = 1
// u64
const IDX_INBOX_POSITION = 0
const IDX_POSITION_WITHIN_MESSAGE = 1
const IDX_ESPRESSO_HEIGHT = 2

func readBuffer(f func(uint32, unsafe.Pointer) uint32) []byte {
buf := make([]byte, 0, INITIAL_CAPACITY)
Expand Down Expand Up @@ -66,14 +65,6 @@ func IsHotShotLive(l1Height uint64) bool {
return isHotShotLive(l1Height) > 0
}

func GetEspressoHeight() uint64 {
return getGlobalStateU64(IDX_ESPRESSO_HEIGHT)
}

func SetEspressoHeight(h uint64) {
setGlobalStateU64(IDX_ESPRESSO_HEIGHT, h)
}

func ReadDelayedInboxMessage(seqNum uint64) []byte {
return readBuffer(func(offset uint32, buf unsafe.Pointer) uint32 {
return readDelayedInboxMessage(seqNum, offset, buf)
Expand Down
9 changes: 0 additions & 9 deletions wavmio/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ var (
hotShotCommitment [32]byte
preimages map[common.Hash][]byte
seqAdvanced uint64
espressoHeight uint64
)

func parsePreimageBytes(path string) {
Expand Down Expand Up @@ -128,14 +127,6 @@ func IsHotShotLive(l1Height uint64) bool {
return true
}

func GetEspressoHeight() uint64 {
return espressoHeight
}

func SetEspressoHeight(h uint64) {
espressoHeight = h
}

func ReadInboxMessage(msgNum uint64) []byte {
if msgNum != seqMsgPos {
panic(fmt.Sprintf("trying to read bad msg %d", msgNum))
Expand Down

0 comments on commit ae84633

Please sign in to comment.