Skip to content

Commit 8ea4593

Browse files
authored
Merge commit from fork
Check for overflowing scheduled releases
2 parents be924a2 + 9457d3f commit 8ea4593

5 files changed

Lines changed: 39 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased changes
44

5+
# 10.0.8
6+
7+
- Treat scheduled transfers where the total transferred amount overflows as invalid.
8+
59
# 10.0.7
610

711
- Enhance node performance by limiting outbound queue saturation to peers that are slow in processing messages.

concordium-consensus/src/Concordium/Scheduler.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,12 @@ handleTransferWithSchedule wtc twsTo twsSchedule maybeMemo = withDeposit wtc c k
517517
(_, transferAmount) <-
518518
foldM
519519
( \(prev, acc) (i, v) ->
520-
if prev >= i
521-
then rejectTransaction NonIncreasingSchedule
522-
else
523-
if v == 0
524-
then rejectTransaction ZeroScheduledAmount
525-
else return (i, acc + v)
520+
if
521+
| prev >= i -> rejectTransaction NonIncreasingSchedule
522+
| v == 0 -> rejectTransaction ZeroScheduledAmount
523+
| acc > maxBound - v ->
524+
rejectTransaction (AmountTooLarge (AddressAccount senderAddress) v)
525+
| otherwise -> return (i, acc + v)
526526
)
527527
firstRelease
528528
restOfReleases

concordium-consensus/src/Concordium/TransactionVerification.hs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE BangPatterns #-}
12
{-# LANGUAGE ScopedTypeVariables #-}
23
{-# LANGUAGE TypeApplications #-}
34

@@ -13,6 +14,7 @@ import qualified Concordium.ID.AnonymityRevoker as AR
1314
import qualified Concordium.ID.IdentityProvider as IP
1415
import qualified Concordium.ID.Types as ID
1516
import qualified Concordium.Types as Types
17+
import Concordium.Types.Execution (Payload (..), decodePayload)
1618
import Concordium.Types.HashableTo (getHash)
1719
import Concordium.Types.Option
1820
import qualified Concordium.Types.Parameters as Params
@@ -315,6 +317,25 @@ verifyChainUpdate ui@Updates.UpdateInstruction{..} =
315317
return $ Ok $ ChainUpdateSuccess (getHash keys) nonce
316318
)
317319

320+
-- | Check if a transaction payload includes a schedule with a total amount that exceeds the
321+
-- maximum representable amount.
322+
canScheduleOverflow ::
323+
forall pv msg.
324+
(Tx.TransactionData msg) =>
325+
Types.SProtocolVersion pv -> msg -> Bool
326+
canScheduleOverflow spv meta =
327+
case decodePayload spv (Tx.transactionPayload meta) of
328+
Left _ -> False
329+
Right TransferWithSchedule{..} -> checkSchedule twsSchedule
330+
Right TransferWithScheduleAndMemo{..} -> checkSchedule twswmSchedule
331+
Right _ -> False
332+
where
333+
checkSchedule = doCheckSchedule 0
334+
doCheckSchedule _ [] = False
335+
doCheckSchedule !acc ((_, amt) : rest)
336+
| acc > maxBound - amt = True
337+
| otherwise = doCheckSchedule (acc + amt) rest
338+
318339
-- | Verifies a 'NormalTransaction' transaction.
319340
-- This function verifies the following:
320341
-- * Checks that enough energy is supplied for the transaction.
@@ -366,6 +387,8 @@ verifyNormalTransaction meta =
366387
keys <- lift (getAccountVerificationKeys acc)
367388
let sigCheck = Tx.verifyTransaction keys meta
368389
unless sigCheck $ throwError $ MaybeOk NormalTransactionInvalidSignatures
390+
let scheduleOverflow = canScheduleOverflow (Types.protocolVersion @(Types.MPV m)) meta
391+
when scheduleOverflow $ throwError $ MaybeOk NormalTransactionInsufficientFunds
369392
return $ Ok $ NormalTransactionSuccess (getHash keys) nonce
370393
)
371394

@@ -439,7 +462,7 @@ verifyExtendedTransaction meta =
439462
unless (depositedAmount <= amnt) $ throwError $ MaybeOk NormalTransactionInsufficientFunds
440463
-- Check the sender and sponsor signatures
441464
senderKeys <- lift (getAccountVerificationKeys senderAcc)
442-
case mbSponsorAcc of
465+
sigResult <- case mbSponsorAcc of
443466
Nothing -> do
444467
let sigCheck = Tx.verifyTransaction senderKeys meta
445468
unless sigCheck $ throwError $ MaybeOk NormalTransactionInvalidSignatures
@@ -449,6 +472,9 @@ verifyExtendedTransaction meta =
449472
let sigCheck = Tx.verifySponsoredTransaction senderKeys sponsorKeys meta
450473
unless sigCheck $ throwError $ MaybeOk NormalTransactionInvalidSignatures
451474
return $ Ok $ ExtendedTransactionSuccess (getHash senderKeys) (Present $ getHash sponsorKeys) nonce
475+
let scheduleOverflow = canScheduleOverflow (Types.protocolVersion @(Types.MPV m)) meta
476+
when scheduleOverflow $ throwError $ MaybeOk NormalTransactionInsufficientFunds
477+
return sigResult
452478
)
453479

454480
-- | Wrapper types for pairing a transaction with its verification result (if it has one).

concordium-node/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

concordium-node/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "concordium_node"
3-
version = "10.0.7" # must be kept in sync with 'is_compatible_version' in 'src/configuration.rs'
3+
version = "10.0.8" # must be kept in sync with 'is_compatible_version' in 'src/configuration.rs'
44
description = "Concordium Node"
55
authors = ["Concordium <developers@concordium.com>"]
66
exclude = [".gitignore", ".gitlab-ci.yml", "test/**/*","**/**/.gitignore","**/**/.gitlab-ci.yml"]

0 commit comments

Comments
 (0)