forked from OffchainLabs/nitro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassertion.go
93 lines (80 loc) · 2.35 KB
/
assertion.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE
package staker
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/offchainlabs/nitro/solgen/go/rollupgen"
"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/validator"
)
func NewAssertionFromSolidity(assertion rollupgen.Assertion) *Assertion {
return &Assertion{
BeforeState: validator.NewExecutionStateFromSolidity(assertion.BeforeState),
AfterState: validator.NewExecutionStateFromSolidity(assertion.AfterState),
NumBlocks: assertion.NumBlocks,
}
}
func (a *Assertion) AsSolidityStruct() rollupgen.Assertion {
return rollupgen.Assertion{
BeforeState: a.BeforeState.AsSolidityStruct(),
AfterState: a.AfterState.AsSolidityStruct(),
NumBlocks: a.NumBlocks,
}
}
func HashChallengeState(
segmentStart uint64,
segmentLength uint64,
hashes []common.Hash,
) common.Hash {
var hashesBytes []byte
for _, h := range hashes {
hashesBytes = append(hashesBytes, h[:]...)
}
return crypto.Keccak256Hash(
arbmath.Uint64ToU256Bytes(segmentStart),
arbmath.Uint64ToU256Bytes(segmentLength),
hashesBytes,
)
}
func (a *Assertion) ExecutionHash() common.Hash {
return HashChallengeState(
0,
a.NumBlocks,
[]common.Hash{
a.BeforeState.BlockStateHash(),
a.AfterState.BlockStateHash(),
},
)
}
type Assertion struct {
BeforeState *validator.ExecutionState
AfterState *validator.ExecutionState
NumBlocks uint64
}
type NodeInfo struct {
NodeNum uint64
L1BlockProposed uint64
ParentChainBlockProposed uint64
Assertion *Assertion
InboxMaxCount *big.Int
AfterInboxBatchAcc common.Hash
NodeHash common.Hash
WasmModuleRoot common.Hash
}
func (n *NodeInfo) AfterState() *validator.ExecutionState {
return n.Assertion.AfterState
}
func (n *NodeInfo) MachineStatuses() [2]uint8 {
return [2]uint8{
uint8(n.Assertion.BeforeState.MachineStatus),
uint8(n.Assertion.AfterState.MachineStatus),
}
}
func (n *NodeInfo) GlobalStates() [2]rollupgen.GlobalState {
return [2]rollupgen.GlobalState{
rollupgen.GlobalState(n.Assertion.BeforeState.GlobalState.AsSolidityStruct()),
rollupgen.GlobalState(n.Assertion.AfterState.GlobalState.AsSolidityStruct()),
}
}