Skip to content

Commit e4c1780

Browse files
committed
antimev: internal\ethapi: return declared transaction hash for antimev envelopes
1 parent 4dc35d3 commit e4c1780

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

antimev/envelope.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"crypto/aes"
66

7+
"github.com/ethereum/go-ethereum/common"
78
"github.com/ethereum/go-ethereum/core/systemcontracts"
89
"github.com/ethereum/go-ethereum/core/types"
910
"github.com/ethereum/go-ethereum/crypto/tpke"
@@ -23,13 +24,17 @@ var (
2324
// encryption takes in the Envelope's data byte slice (the size of Uint64).
2425
EncryptedDataRoundLen = 4
2526

27+
// EncryptedDataHashLen is the amount of bytes that represents the hash of an
28+
// encrypted transaction.
29+
EncryptedDataHashLen = common.HashLength
30+
2631
// minEncryptedDataSize is the minimum size of encrypted data stored in the
2732
// Envelope transaction. It consists of the constant-length prefix,
2833
// constant-length CipherText and variable-length encrypted message. The size of
2934
// a simple gas transfer with 1 gwei (105 bytes) is taken as a reference point
3035
// for evaluation of variable-length part; it is padded to be even to the AES
3136
// block size as required by AES encryption rules.
32-
minEncryptedDataSize = EncryptedDataPrefixLen + EncryptedDataRoundLen + tpke.CipherTextSize + 105 + (aes.BlockSize - 105%aes.BlockSize)
37+
minEncryptedDataSize = EncryptedDataPrefixLen + EncryptedDataRoundLen + EncryptedDataHashLen + tpke.CipherTextSize + 105 + (aes.BlockSize - 105%aes.BlockSize)
3338
)
3439

3540
// isEnvelope checks whether a transaction is an Envelope transaction. The criteria

consensus/dbft/amev.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type envelopeData struct {
3131
func decodeEnvelopeData(buf []byte) (envelopeData, error) {
3232
var (
3333
key = new(tpke.CipherText)
34-
keyOffset = antimev.EncryptedDataPrefixLen + antimev.EncryptedDataRoundLen
34+
keyOffset = antimev.EncryptedDataPrefixLen + antimev.EncryptedDataRoundLen + antimev.EncryptedDataHashLen
3535
cipherTextOffset = keyOffset + tpke.CipherTextSize
3636
)
3737
// It's guaranteed by Envelope definition that buf has a proper length.

internal/ethapi/api.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/ethereum/go-ethereum/accounts"
3131
"github.com/ethereum/go-ethereum/accounts/keystore"
3232
"github.com/ethereum/go-ethereum/accounts/scwallet"
33+
"github.com/ethereum/go-ethereum/antimev"
3334
"github.com/ethereum/go-ethereum/common"
3435
"github.com/ethereum/go-ethereum/common/hexutil"
3536
"github.com/ethereum/go-ethereum/common/lru"
@@ -1889,7 +1890,14 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
18891890
} else {
18901891
log.Info("Submitted transaction", "hash", tx.Hash().Hex(), "from", from, "nonce", tx.Nonce(), "recipient", tx.To(), "value", tx.Value())
18911892
}
1892-
return tx.Hash(), nil
1893+
1894+
// If the transaction is an antimev envelope, then return the declared transaction hash instead of its own.
1895+
if antimev.IsEnvelope(tx) {
1896+
hashOffSet := antimev.EncryptedDataPrefixLen + antimev.EncryptedDataRoundLen
1897+
return common.Hash(tx.Data()[hashOffSet : hashOffSet+antimev.EncryptedDataHashLen]), nil
1898+
} else {
1899+
return tx.Hash(), nil
1900+
}
18931901
}
18941902

18951903
// SendTransaction creates a transaction for the given argument, sign it and submit it to the

0 commit comments

Comments
 (0)