diff --git a/op-supervisor/supervisor/types/types_test.go b/op-supervisor/supervisor/types/types_test.go index bc01fa63efa5f..1ec5cf9c1243e 100644 --- a/op-supervisor/supervisor/types/types_test.go +++ b/op-supervisor/supervisor/types/types_test.go @@ -1,7 +1,9 @@ package types import ( + "encoding/binary" "encoding/json" + "github.com/ethereum/go-ethereum/crypto" "math/big" "testing" @@ -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) +}