Browse Source

Check feeAmount overflow in API

feature/sql-semaphore1
ToniRamirezM 3 years ago
parent
commit
f90f14d0c1
2 changed files with 16 additions and 2 deletions
  1. +5
    -0
      api/txspool.go
  2. +11
    -2
      api/txspool_test.go

+ 5
- 0
api/txspool.go

@ -163,6 +163,11 @@ func verifyPoolL2TxWrite(txw *l2db.PoolL2TxWrite) error {
if err != nil {
return err
}
// Validate feeAmount
_, err = common.CalcFeeAmount(poolTx.Amount, poolTx.Fee)
if err != nil {
return err
}
// Check signature
if !poolTx.VerifySignature(account.PublicKey) {
return errors.New("wrong signature")

+ 11
- 2
api/txspool_test.go

@ -205,14 +205,23 @@ func TestPoolTxs(t *testing.T) {
assert.Equal(t, tx.TxID, fetchedTxID)
}
// 400
// Wrong signature
// Wrong fee
badTx := tc.poolTxsToSend[0]
badTx.FromIdx = "hez:foo:1000"
badTx.Amount = "99999999999999999999999"
badTx.Fee = 255
jsonTxBytes, err := json.Marshal(badTx)
assert.NoError(t, err)
jsonTxReader := bytes.NewReader(jsonTxBytes)
err = doBadReq("POST", endpoint, jsonTxReader, 400)
assert.NoError(t, err)
// Wrong signature
badTx = tc.poolTxsToSend[0]
badTx.FromIdx = "hez:foo:1000"
jsonTxBytes, err = json.Marshal(badTx)
assert.NoError(t, err)
jsonTxReader = bytes.NewReader(jsonTxBytes)
err = doBadReq("POST", endpoint, jsonTxReader, 400)
assert.NoError(t, err)
// Wrong to
badTx = tc.poolTxsToSend[0]
ethAddr := "hez:0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"

Loading…
Cancel
Save