Commit 508fbf35 authored by clabby's avatar clabby

:broom:

parent b59b8710
...@@ -80,13 +80,12 @@ const ( ...@@ -80,13 +80,12 @@ const (
) )
func (sw StateWitness) StateHash() (common.Hash, error) { func (sw StateWitness) StateHash() (common.Hash, error) {
hash := crypto.Keccak256Hash(sw)
offset := 32*2 + 4*6
if len(sw) != 226 { if len(sw) != 226 {
return common.Hash{}, fmt.Errorf("Invalid witness length. Got %d, expected at least 88", len(sw)) return common.Hash{}, fmt.Errorf("Invalid witness length. Got %d, expected at least 88", len(sw))
} }
hash := crypto.Keccak256Hash(sw)
offset := 32*2 + 4*6
exitCode := sw[offset] exitCode := sw[offset]
exited := sw[offset+1] exited := sw[offset+1]
status := vmStatus(exited == 1, exitCode) status := vmStatus(exited == 1, exitCode)
......
...@@ -222,11 +222,6 @@ func (m *mockTraceProvider) AbsolutePreStateCommitment(ctx context.Context) (com ...@@ -222,11 +222,6 @@ func (m *mockTraceProvider) AbsolutePreStateCommitment(ctx context.Context) (com
return hash, nil return hash, nil
} }
// StateHash computes the state-hash of the given state, or returns an error if the state is invalid.
func (m *mockTraceProvider) StateHash(ctx context.Context, state []byte) (common.Hash, error) {
panic("not implemented")
}
type mockLoader struct { type mockLoader struct {
prestateError bool prestateError bool
prestate common.Hash prestate common.Hash
......
...@@ -77,10 +77,6 @@ func (ap *AlphabetTraceProvider) AbsolutePreStateCommitment(ctx context.Context) ...@@ -77,10 +77,6 @@ func (ap *AlphabetTraceProvider) AbsolutePreStateCommitment(ctx context.Context)
return hash, nil return hash, nil
} }
func (ap *AlphabetTraceProvider) StateHash(ctx context.Context, state []byte) (common.Hash, error) {
return alphabetStateHash(state), nil
}
// BuildAlphabetPreimage constructs the claim bytes for the index and state item. // BuildAlphabetPreimage constructs the claim bytes for the index and state item.
func BuildAlphabetPreimage(i uint64, letter string) []byte { func BuildAlphabetPreimage(i uint64, letter string) []byte {
return append(IndexToBytes(i), LetterToBytes(letter)...) return append(IndexToBytes(i), LetterToBytes(letter)...)
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func alphabetClaim(index uint64, letter string, provider *AlphabetTraceProvider) common.Hash { func alphabetClaim(index uint64, letter string) common.Hash {
return alphabetStateHash(BuildAlphabetPreimage(index, letter)) return alphabetStateHash(BuildAlphabetPreimage(index, letter))
} }
...@@ -25,15 +25,15 @@ func TestAlphabetProvider_Get_ClaimsByTraceIndex(t *testing.T) { ...@@ -25,15 +25,15 @@ func TestAlphabetProvider_Get_ClaimsByTraceIndex(t *testing.T) {
}{ }{
{ {
7, 7,
alphabetClaim(7, "h", canonicalProvider), alphabetClaim(7, "h"),
}, },
{ {
3, 3,
alphabetClaim(3, "d", canonicalProvider), alphabetClaim(3, "d"),
}, },
{ {
5, 5,
alphabetClaim(5, "f", canonicalProvider), alphabetClaim(5, "f"),
}, },
} }
...@@ -80,7 +80,7 @@ func TestGet_Succeeds(t *testing.T) { ...@@ -80,7 +80,7 @@ func TestGet_Succeeds(t *testing.T) {
ap := NewTraceProvider("abc", 2) ap := NewTraceProvider("abc", 2)
claim, err := ap.Get(context.Background(), 0) claim, err := ap.Get(context.Background(), 0)
require.NoError(t, err) require.NoError(t, err)
expected := alphabetClaim(0, "a", ap) expected := alphabetClaim(0, "a")
require.Equal(t, expected, claim) require.Equal(t, expected, claim)
} }
...@@ -98,6 +98,6 @@ func TestGet_Extends(t *testing.T) { ...@@ -98,6 +98,6 @@ func TestGet_Extends(t *testing.T) {
ap := NewTraceProvider("abc", 2) ap := NewTraceProvider("abc", 2)
claim, err := ap.Get(context.Background(), 3) claim, err := ap.Get(context.Background(), 3)
require.NoError(t, err) require.NoError(t, err)
expected := alphabetClaim(2, "c", ap) expected := alphabetClaim(2, "c")
require.Equal(t, expected, claim) require.Equal(t, expected, claim)
} }
...@@ -194,11 +194,3 @@ func (p *CannonTraceProvider) loadProof(ctx context.Context, i uint64) (*proofDa ...@@ -194,11 +194,3 @@ func (p *CannonTraceProvider) loadProof(ctx context.Context, i uint64) (*proofDa
} }
return &proof, nil return &proof, nil
} }
func (p *CannonTraceProvider) StateHash(ctx context.Context, state []byte) (common.Hash, error) {
hash, err := mipsevm.StateWitness(state).StateHash()
if err != nil {
return common.Hash{}, fmt.Errorf("cannot hash state: %w", err)
}
return hash, nil
}
...@@ -42,7 +42,7 @@ func TestGet(t *testing.T) { ...@@ -42,7 +42,7 @@ func TestGet(t *testing.T) {
value, err := provider.Get(context.Background(), 7000) value, err := provider.Get(context.Background(), 7000)
require.NoError(t, err) require.NoError(t, err)
require.Contains(t, generator.generated, 7000, "should have tried to generate the proof") require.Contains(t, generator.generated, 7000, "should have tried to generate the proof")
stateHash, err := provider.StateHash(context.Background(), generator.finalState.EncodeWitness()) stateHash, err := generator.finalState.EncodeWitness().StateHash()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, stateHash, value) require.Equal(t, stateHash, value)
}) })
......
...@@ -108,9 +108,6 @@ type TraceProvider interface { ...@@ -108,9 +108,6 @@ type TraceProvider interface {
// AbsolutePreStateCommitment is the commitment of the pre-image value of the trace that transitions to the trace value at index 0 // AbsolutePreStateCommitment is the commitment of the pre-image value of the trace that transitions to the trace value at index 0
AbsolutePreStateCommitment(ctx context.Context) (hash common.Hash, err error) AbsolutePreStateCommitment(ctx context.Context) (hash common.Hash, err error)
// StateHash computes the state-hash of the given state, or returns an error if the state is invalid.
StateHash(ctx context.Context, state []byte) (common.Hash, error)
} }
// ClaimData is the core of a claim. It must be unique inside a specific game. // ClaimData is the core of a claim. It must be unique inside a specific game.
......
...@@ -1560,17 +1560,15 @@ contract MIPS_Test is CommonTest { ...@@ -1560,17 +1560,15 @@ contract MIPS_Test is CommonTest {
/// 2. Exited with failure (Panic) /// 2. Exited with failure (Panic)
/// 3. Unfinished /// 3. Unfinished
function vmStatus(MIPS.State memory state) internal pure returns (VMStatus out_) { function vmStatus(MIPS.State memory state) internal pure returns (VMStatus out_) {
if (state.exited) { if (!state.exited) {
if (state.exitCode == 0) { return VMStatuses.UNFINISHED;
} else if (state.exitCode == 0) {
return VMStatuses.VALID; return VMStatuses.VALID;
} else if (state.exitCode == 1) { } else if (state.exitCode == 1) {
return VMStatuses.INVALID; return VMStatuses.INVALID;
} else { } else {
return VMStatuses.PANIC; return VMStatuses.PANIC;
} }
} else {
return VMStatuses.UNFINISHED;
}
} }
function outputState(MIPS.State memory state) internal pure returns (bytes32 out_) { function outputState(MIPS.State memory state) internal pure returns (bytes32 out_) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment