Skip to content

Commit 0ebf43d

Browse files
committed
antimev: ensure decrypted tx hash matches Envelope's data
Otherwise decrypted transaction is invalid and must not be accepted. Signed-off-by: Anna Shaleva <[email protected]>
1 parent 8495221 commit 0ebf43d

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

antimev/envelope.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,10 @@ func IsEnvelope(tx *types.Transaction) bool {
5151

5252
return true
5353
}
54+
55+
// GetEncryptedHash returns the hash of inner encrypted transaction specified in an
56+
// unencrypted part of Envelope data. Passing non-Envelope as an argument is a no-op.
57+
func GetEncryptedHash(envelope *types.Transaction) common.Hash {
58+
hashOffset := EncryptedDataPrefixLen + EncryptedDataRoundLen
59+
return common.Hash(envelope.Data()[hashOffset : hashOffset+EncryptedDataHashLen])
60+
}

consensus/dbft/dbft.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,12 @@ func (c *DBFT) validateDecryptedTx(head *types.Header, decryptedTx *types.Transa
12571257
return fmt.Errorf("decryptedTx from mismatch: decryptedFrom %v, envelopeFrom %v", decryptedFrom, envelopeFrom)
12581258
}
12591259

1260+
// Ensure decrypted hash matches the one specified in an unencrypted part of Envelope data.
1261+
expectedH := antimev.GetEncryptedHash(envelope)
1262+
if decryptedTx.Hash().Cmp(expectedH) != 0 {
1263+
return fmt.Errorf("decryptedTx hash mismatch: expected %s, got %s", expectedH, decryptedTx.Hash())
1264+
}
1265+
12601266
return nil
12611267
}
12621268

internal/ethapi/api.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,8 +1893,7 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
18931893

18941894
// If the transaction is an antimev envelope, then return the declared transaction hash instead of its own.
18951895
if antimev.IsEnvelope(tx) {
1896-
hashOffSet := antimev.EncryptedDataPrefixLen + antimev.EncryptedDataRoundLen
1897-
return common.Hash(tx.Data()[hashOffSet : hashOffSet+antimev.EncryptedDataHashLen]), nil
1896+
return antimev.GetEncryptedHash(tx), nil
18981897
} else {
18991898
return tx.Hash(), nil
19001899
}

0 commit comments

Comments
 (0)