Skip to content
Closed
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
41 changes: 41 additions & 0 deletions op-supervisor/supervisor/types/types_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package types

import (
"encoding/binary"
"encoding/json"
"github.com/ethereum/go-ethereum/crypto"
"math/big"
"testing"

Expand Down Expand Up @@ -38,3 +40,42 @@ func FuzzRoundtripIdentifierJSONMarshal(f *testing.F) {
require.Equal(t, id.ChainID, dec.ChainID)
})
}

func TestHashing(t *testing.T) {
keccak256 := func(name string, parts ...[]byte) (h common.Hash) {
t.Logf("%s = H(", name)
for _, p := range parts {
t.Logf(" %x,", p)
}
t.Logf(")")
h = crypto.Keccak256Hash(parts...)
t.Logf("%s = %s", name, h)
return h
}
id := Identifier{
Origin: common.Address{},
BlockNumber: 0xa1a2_a3a4_a5a6_a7a8,
LogIndex: 0xb1b2_b3b4,
Timestamp: 0xc1c2_c3c4_c5c6_c7c8,
ChainID: eth.ChainIDFromUInt64(0xd1d2_d3d4_d5d6_d7d8),
}
payloadHash := keccak256("payloadHash", []byte("example payload")) // aka msgHash
logHash := keccak256("logHash", id.Origin[:], payloadHash[:])
x := PayloadHashToLogHash(payloadHash, id.Origin)
require.Equal(t, logHash, x, "check op-supervisor version of log-hashing matches intermediate value")

var idPacked []byte
idPacked = append(idPacked, make([]byte, 12)...)
idPacked = binary.BigEndian.AppendUint64(idPacked, id.BlockNumber)
idPacked = binary.BigEndian.AppendUint64(idPacked, id.Timestamp)
idPacked = binary.BigEndian.AppendUint32(idPacked, id.LogIndex)
t.Logf("idPacked: %x", idPacked)

idLogHash := keccak256("idLogHash", logHash[:], idPacked)
chainID := id.ChainID.Bytes32()
bareChecksum := keccak256("bareChecksum", idLogHash[:], chainID[:])

checksum := bareChecksum
checksum[0] = 0x03
t.Logf("Checksum: %s", checksum)
}