chore(API): enforce from address when checking pol tx (#52)

This commit is contained in:
Cal Bera 2025-08-08 10:30:06 -07:00 committed by GitHub
parent 2e040fc486
commit 497e1a4e42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 8 deletions

View file

@ -160,10 +160,10 @@ func getDistributeForData(pubkey *common.Pubkey) ([]byte, error) {
}
// IsPoLDistribution returns true if the transaction is a PoL distribution.
func IsPoLDistribution(to *common.Address, data []byte, distributorAddress common.Address) bool {
func IsPoLDistribution(from common.Address, to *common.Address, data []byte, distributorAddress common.Address) bool {
// Txs that call the `distributeFor(bytes pubkey)` method on the PoL Distributor
// contract are also consideredPoL txs.
return to != nil && *to == distributorAddress && isDistributeForCall(data)
return from == params.SystemAddress && to != nil && *to == distributorAddress && isDistributeForCall(data)
}
// isDistributeForCall returns true if the provided calldata corresponds to a

View file

@ -92,26 +92,31 @@ func TestIsPoLDistribution(t *testing.T) {
}
// Positive case.
if !IsPoLDistribution(&distributor, tx.Data(), distributor) {
if !IsPoLDistribution(params.SystemAddress, &distributor, tx.Data(), distributor) {
t.Fatalf("expected IsPoLDistribution to return true for valid PoL call")
}
// Wrong address.
otherAddr := common.HexToAddress("0x0200000000000000000000000000000000000002")
if IsPoLDistribution(&otherAddr, tx.Data(), distributor) {
if IsPoLDistribution(params.SystemAddress, &otherAddr, tx.Data(), distributor) {
t.Fatalf("expected false when distributor address mismatches")
}
// Too-short data.
shortData := []byte{0x01, 0x02, 0x03}
if IsPoLDistribution(&distributor, shortData, distributor) {
if IsPoLDistribution(params.SystemAddress, &distributor, shortData, distributor) {
t.Fatalf("expected false for data shorter than selector")
}
// Nil address.
if IsPoLDistribution(nil, tx.Data(), distributor) {
if IsPoLDistribution(params.SystemAddress, nil, tx.Data(), distributor) {
t.Fatalf("expected false when to==nil")
}
// Wrong from address.
if IsPoLDistribution(distributor, &distributor, tx.Data(), distributor) {
t.Fatalf("expected false when from address mismatches")
}
}
// TestPoLTx_RawSignatureValues confirms that PoLTx reports no signature.

View file

@ -463,7 +463,7 @@ func (args *TransactionArgs) ToMessage(baseFee *big.Int, skipNonceCheck, skipEoA
SetCodeAuthorizations: args.AuthorizationList,
SkipNonceChecks: skipNonceCheck,
SkipFromEOACheck: skipEoACheck,
IsPoLTx: isPrague1 && types.IsPoLDistribution(args.To, args.data(), distributorAddress),
IsPoLTx: isPrague1 && types.IsPoLDistribution(args.from(), args.To, args.data(), distributorAddress),
}
}
@ -472,7 +472,7 @@ func (args *TransactionArgs) ToMessage(baseFee *big.Int, skipNonceCheck, skipEoA
func (args *TransactionArgs) ToTransaction(defaultType int, isPrague1 bool, distributorAddress common.Address) *types.Transaction {
usedType := types.LegacyTxType
switch {
case isPrague1 && types.IsPoLDistribution(args.To, args.data(), distributorAddress):
case isPrague1 && types.IsPoLDistribution(args.from(), args.To, args.data(), distributorAddress):
usedType = types.PoLTxType
case args.AuthorizationList != nil || defaultType == types.SetCodeTxType:
usedType = types.SetCodeTxType