arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
Merge pull request #260 from hermeznetwork/feature/api-fee-check

Check feeAmount overflow in API
laisolizq 37299818+laisolizq@users.noreply.github.com
Thu, 05 Nov 2020 14:03:20 +0100
commit

651572cbf3f0c287f02c7ce744c753be660b52a7

parent

9ab50135d78cfaa7dff1739acddd65c5dd728929

2 files changed, 16 insertions(+), 2 deletions(-)

jump to
M api/txspool.go → api/txspool.go

@@ -163,6 +163,11 @@ account, err := s.GetAccount(poolTx.FromIdx)

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")
M api/txspool_test.go → api/txspool_test.go

@@ -205,12 +205,21 @@ )

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