Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/main' into merkle-proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
td202 committed Jan 8, 2024
2 parents 5ae1ef3 + c7a7f37 commit 98508e6
Show file tree
Hide file tree
Showing 28 changed files with 3,566 additions and 2,035 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

## Unreleased changes

- Fix a bug where `GetBlockPendingUpdates` fails to report pending updates to the finalization
committee parameters.

## 6.2.3

- Fix an bug that caused the node to crash on Windows when processing a protocol update.
- Fix a bug that caused the node to crash on Windows when processing a protocol update.

## 6.2.2

Expand Down
2 changes: 1 addition & 1 deletion concordium-base
Submodule concordium-base updated 84 files
+7 −0 haskell-src/Concordium/Types.hs
+32 −4 haskell-src/Concordium/Types/ProtocolVersion.hs
+4 −0 mobile_wallet/CHANGELOG.md
+19 −18 mobile_wallet/Cargo.lock
+2 −2 mobile_wallet/Cargo.toml
+4 −0 rust-bins/CHANGELOG.md
+3 −2 rust-bins/Cargo.lock
+2 −2 rust-bins/Cargo.toml
+8 −4 rust-bins/src/bin/client.rs
+20 −25 rust-bins/src/bin/user_cli.rs
+18 −3 rust-src/Cargo.lock
+4 −2 rust-src/Cargo.toml
+10 −0 rust-src/concordium_base/CHANGELOG.md
+15 −13 rust-src/concordium_base/benches/bulletproofs.rs
+78 −60 rust-src/concordium_base/benches/encrypted_transfers_benchmarks.rs
+64 −7 rust-src/concordium_base/benches/multiexp_bench.rs
+1 −2 rust-src/concordium_base/src/aggregate_sig/mod.rs
+10 −2 rust-src/concordium_base/src/base.rs
+1 −2 rust-src/concordium_base/src/bulletproofs/inner_product_proof.rs
+5 −7 rust-src/concordium_base/src/bulletproofs/range_proof.rs
+4 −6 rust-src/concordium_base/src/bulletproofs/set_membership_proof.rs
+4 −6 rust-src/concordium_base/src/bulletproofs/set_non_membership_proof.rs
+4 −2 rust-src/concordium_base/src/bulletproofs/utils.rs
+4 −1 rust-src/concordium_base/src/common/mod.rs
+0 −1 rust-src/concordium_base/src/common/serialize.rs
+85 −19 rust-src/concordium_base/src/curve_arithmetic/bls12_381_instance.rs
+378 −0 rust-src/concordium_base/src/curve_arithmetic/ed25519_instance.rs
+245 −126 rust-src/concordium_base/src/curve_arithmetic/mod.rs
+1 −2 rust-src/concordium_base/src/curve_arithmetic/secret_value.rs
+32 −3 rust-src/concordium_base/src/dodis_yampolskiy_prf/secret.rs
+4 −7 rust-src/concordium_base/src/elgamal/mod.rs
+3 −4 rust-src/concordium_base/src/elgamal/secret.rs
+3 −3 rust-src/concordium_base/src/id/account_holder.rs
+1 −2 rust-src/concordium_base/src/id/id_verifier.rs
+1 −2 rust-src/concordium_base/src/id/identity_provider.rs
+5 −2 rust-src/concordium_base/src/id/secret_sharing.rs
+0 −1 rust-src/concordium_base/src/id/types.rs
+9 −10 rust-src/concordium_base/src/id/utils.rs
+0 −2 rust-src/concordium_base/src/pedersen_commitment/randomness.rs
+0 −2 rust-src/concordium_base/src/ps_sig/secret.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/aggregate_dlog.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/com_enc_eq.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/com_eq.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/com_eq_different_groups.rs
+0 −1 rust-src/concordium_base/src/sigma_protocols/com_eq_sig.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/com_ineq.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/com_lin.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/com_mult.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/dlog.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/dlogaggequal.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/enc_trans.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/vcom_eq.rs
+33 −2 rust-src/concordium_base/src/smart_contracts.rs
+13 −0 rust-src/key_derivation/CHANGELOG.md
+2 −1 rust-src/key_derivation/Cargo.toml
+307 −16 rust-src/key_derivation/src/lib.rs
+7 −0 rust-src/wallet_library/CHANGELOG.md
+28 −0 rust-src/wallet_library/Cargo.toml
+32 −0 rust-src/wallet_library/resources/ars_infos.json
+8 −0 rust-src/wallet_library/resources/global.json
+57 −0 rust-src/wallet_library/resources/identity-object.json
+13 −0 rust-src/wallet_library/resources/ip_info.json
+315 −0 rust-src/wallet_library/src/credential.rs
+356 −0 rust-src/wallet_library/src/identity.rs
+6 −0 rust-src/wallet_library/src/lib.rs
+52 −0 rust-src/wallet_library/src/test_helpers.rs
+338 −0 rust-src/wallet_library/src/wallet.rs
+2 −0 smart-contracts/contracts-common/Cargo.toml
+3 −0 smart-contracts/contracts-common/concordium-contracts-common/CHANGELOG.md
+29 −2 smart-contracts/contracts-common/concordium-contracts-common/src/types.rs
+3 −0 smart-contracts/wasm-chain-integration/CHANGELOG.md
+8 −6 smart-contracts/wasm-chain-integration/benches/v1-host-functions.rs
+5 −14 smart-contracts/wasm-chain-integration/benches/wasm.rs
+81 −40 smart-contracts/wasm-chain-integration/src/lib.rs
+72 −30 smart-contracts/wasm-chain-integration/src/utils.rs
+4 −4 smart-contracts/wasm-chain-integration/src/v1/crypto_primitives_tests.rs
+1 −0 smart-contracts/wasm-chain-integration/src/v1/ffi.rs
+401 −65 smart-contracts/wasm-chain-integration/src/v1/mod.rs
+10 −24 smart-contracts/wasm-chain-integration/src/v1/tests.rs
+11 −0 smart-contracts/wasm-chain-integration/src/v1/trie/api.rs
+23 −1 smart-contracts/wasm-chain-integration/src/v1/trie/low_level.rs
+1 −1 smart-contracts/wasm-chain-integration/src/v1/trie/types.rs
+122 −21 smart-contracts/wasm-chain-integration/src/v1/types.rs
+4 −0 smart-contracts/wasm-chain-integration/src/validation_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ class (ContractStateOperations m, AccountOperations m, ModuleQuery m) => BlockSt
-- | Get the transactionOutcomesHash of a given block.
getTransactionOutcomesHash :: BlockState m -> m TransactionOutcomesHash

-- | Get the stateHash of a given block.
-- | Get the StateHash of a given block.
getStateHash :: BlockState m -> m StateHash

-- | Get all transaction outcomes for this block.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ blobBSFileLength BlobStoreAccess{..} = mask $ \restore -> do
readBlobBS :: BlobStoreAccess -> BlobRef a -> IO BS.ByteString
readBlobBS bs@BlobStoreAccess{..} br@(BlobRef offset) = do
let ioffset = fromIntegral offset
when (ioffset < 0) $ throwIO $ userError "Attempted to read an invalid BlobRef"
let dataOffset = ioffset + 8
mmap0 <- readIORef blobStoreMMap
mmap <-
Expand Down
9 changes: 6 additions & 3 deletions concordium-consensus/src/Concordium/KonsensusV1/Consensus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,17 @@ computeFinalizationCommittee FullBakers{..} FinalizationCommitteeParameters{..}
committeeFinalizers = Vec.fromList $ zipWith mkFinalizer [FinalizerIndex 0 ..] sortedFinalizers
committeeTotalWeight = sum $ finalizerWeight <$> committeeFinalizers

-- | Compute the finalization committee given the bakers and the finalization committee parameters,
-- returning a 'BakersAndFinalizers'.
-- | Compute the finalization committee and finalization committee hash given the bakers and the
-- finalization committee parameters, returning a 'BakersAndFinalizers'.
computeBakersAndFinalizers :: FullBakers -> FinalizationCommitteeParameters -> BakersAndFinalizers
computeBakersAndFinalizers bakers fcp =
BakersAndFinalizers
{ _bfBakers = bakers,
_bfFinalizers = computeFinalizationCommittee bakers fcp
_bfFinalizers = finalizers,
_bfFinalizerHash = computeFinalizationCommitteeHash finalizers
}
where
finalizers = computeFinalizationCommittee bakers fcp

-- | Get the baker identity and finalizer info if we are a finalizer in the specified epoch.
-- This checks that the signing key and aggregate signing key match those for the finalizer,
Expand Down
174 changes: 136 additions & 38 deletions concordium-consensus/src/Concordium/KonsensusV1/Consensus/Blocks.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

Expand All @@ -23,7 +24,10 @@ import Concordium.Logger
import Concordium.TimeMonad
import Concordium.Types
import Concordium.Types.Accounts
import Concordium.Types.BakerIdentity
import Concordium.Types.Block (localToAbsoluteBlockHeight)
import Concordium.Types.HashableTo
import Concordium.Types.Option
import Concordium.Types.Parameters hiding (getChainParameters)
import Concordium.Types.SeedState
import Concordium.Utils
Expand Down Expand Up @@ -51,8 +55,6 @@ import Concordium.KonsensusV1.TreeState.Types
import Concordium.KonsensusV1.Types
import Concordium.Scheduler (FilteredTransactions (..))
import Concordium.TimerMonad
import Concordium.Types.BakerIdentity
import Concordium.Types.Option

-- | A block that has passed initial verification, but must still be executed, added to the state,
-- and (potentially) signed as a finalizer.
Expand All @@ -76,7 +78,6 @@ instance BlockData (VerifiedBlock pv) where
blockBakedData = blockBakedData . vbBlock
blockTransactions = blockTransactions . vbBlock
blockTransactionCount = blockTransactionCount . vbBlock
blockStateHash = blockStateHash . vbBlock

-- * Receiving blocks

Expand Down Expand Up @@ -330,7 +331,7 @@ receiveBlockUnknownParent ::
MonadState (SkovData (MPV m)) m,
MonadLogger m
) =>
PendingBlock pv ->
PendingBlock (MPV m) ->
m (BlockResult (MPV m))
receiveBlockUnknownParent pendingBlock = do
earlyThreshold <- rpEarlyBlockThreshold <$> use runtimeParameters
Expand Down Expand Up @@ -374,7 +375,8 @@ getMinBlockTime b = do
--
-- * The block must not already be a live block.
addBlock ::
(TimeMonad m, MonadState (SkovData (MPV m)) m, MonadConsensusEvent m, MonadLogger m) =>
forall m.
(TimeMonad m, MonadState (SkovData (MPV m)) m, MonadConsensusEvent m, MonadLogger m, IsProtocolVersion (MPV m)) =>
-- | Block to add
PendingBlock (MPV m) ->
-- | Block state
Expand All @@ -387,7 +389,7 @@ addBlock ::
addBlock pendingBlock blockState parent energyUsed = do
let height = blockHeight parent + 1
now <- currentTime
newBlock <- makeLiveBlock pendingBlock blockState height now energyUsed
newBlock <- makeLiveBlock @m pendingBlock blockState height now energyUsed
addToBranches newBlock
logEvent Konsensus LLInfo $
"Block "
Expand Down Expand Up @@ -426,6 +428,7 @@ addBlock pendingBlock blockState parent energyUsed = do
-- * The block is signed by a valid baker for its epoch.
-- * The baker is the leader for the round according to the parent block.
processBlock ::
forall m.
( IsConsensusV1 (MPV m),
BlockStateStorage m,
BlockState m ~ HashedPersistentBlockState (MPV m),
Expand Down Expand Up @@ -508,7 +511,7 @@ processBlock parent VerifiedBlock{vbBlock = pendingBlock, ..}
-- block.
-- This implies that the block is in the epoch after the last
-- finalized block.
newBlock <- addBlock pendingBlock blockState parent energyUsed
newBlock <- addBlock @m pendingBlock blockState parent energyUsed
let certifiedParent =
CertifiedBlock
{ cbQuorumCertificate = blockQuorumCertificate pendingBlock,
Expand Down Expand Up @@ -752,35 +755,63 @@ processBlock parent VerifiedBlock{vbBlock = pendingBlock, ..}
<> show failureReason
flag (BlockExecutionFailure sBlock)
rejectBlock
Right (newState, energyUsed) -> do
outcomesHash <- getTransactionOutcomesHash newState
if
| outcomesHash /= blockTransactionOutcomesHash pendingBlock -> do
-- Incorrect transaction outcomes
logEvent Konsensus LLTrace $
"Block "
<> show pbHash
<> " stated transaction outcome hash ("
<> show (blockTransactionOutcomesHash pendingBlock)
<> ") does not match computed value ("
<> show outcomesHash
<> ")."
flag $ BlockInvalidTransactionOutcomesHash sBlock (bpBlock parent)
rejectBlock
| getHash newState /= blockStateHash pendingBlock -> do
-- Incorrect state hash
logEvent Konsensus LLTrace $
"Block "
<> show pbHash
<> " stated state hash ("
<> show (blockStateHash pendingBlock)
<> ") does not match computed value ("
<> show (getHash newState :: StateHash)
<> ")."
flag $ BlockInvalidStateHash sBlock (bpBlock parent)
rejectBlock
| otherwise ->
continue newState energyUsed
Right (newState, energyUsed) ->
case blockDerivableHashes pendingBlock of
DerivableBlockHashesV0
{ dbhv0TransactionOutcomesHash = pendingBlockTxOutcomesHash,
dbhv0BlockStateHash = pendingBlockStateHash
} -> do
-- Prior to PV7 the transaction outcome was tracked separate from
-- the state hash, meaning both have to be checked here.
outcomesHash <- getTransactionOutcomesHash newState
if
| outcomesHash /= pendingBlockTxOutcomesHash -> do
-- Incorrect transaction outcomes
logEvent Konsensus LLTrace $
"Block "
<> show pbHash
<> " stated transaction outcome hash ("
<> show pendingBlockTxOutcomesHash
<> ") does not match computed value ("
<> show outcomesHash
<> ")."
flag $ BlockInvalidTransactionOutcomesHash sBlock (bpBlock parent)
rejectBlock
| getHash newState /= pendingBlockStateHash -> do
-- Incorrect state hash
logEvent Konsensus LLTrace $
"Block "
<> show pbHash
<> " stated state hash ("
<> show pendingBlockStateHash
<> ") does not match computed value ("
<> show (getHash newState :: StateHash)
<> ")."
flag $ BlockInvalidStateHash sBlock (bpBlock parent)
rejectBlock
| otherwise ->
continue newState energyUsed
DerivableBlockHashesV1{dbhv1BlockResultHash = pendingBlockResultHash} -> do
-- Starting from P7 the baked block only contains a block result hash
-- which is computed from transaction outcomes, the block state hash
-- and more.
let relativeBlockHeight = 1 + blockHeight parent
let pendingBlockEpoch = blockEpoch pendingBlock
computedResultHash <- computeBlockResultHash newState relativeBlockHeight pendingBlockEpoch
if computedResultHash /= pendingBlockResultHash
then do
-- Incorrect block result hash
logEvent Konsensus LLTrace $
"Block "
<> show pbHash
<> " stated result hash ("
<> show pendingBlockResultHash
<> ") does not match computed value ("
<> show computedResultHash
<> ")."
flag $ BlockInvalidResultHash sBlock (bpBlock parent)
rejectBlock
else continue newState energyUsed
getParentBakersAndFinalizers continue
| blockEpoch parent == blockEpoch pendingBlock = continue vbBakersAndFinalizers
| otherwise =
Expand Down Expand Up @@ -1145,6 +1176,7 @@ prepareBakeBlockInputs = runMaybeT $ do

-- | Construct a block given 'BakeBlockInputs'.
bakeBlock ::
forall m.
( MonadState (SkovData (MPV m)) m,
BlockStateStorage m,
BlockState m ~ HashedPersistentBlockState (MPV m),
Expand Down Expand Up @@ -1189,8 +1221,16 @@ bakeBlock BakeBlockInputs{..} = do
updateFocusBlockTo bbiParent
ptt <- use pendingTransactionTable
(filteredTransactions, newState, energyUsed) <- constructBlockState runtime tt ptt executionData
bbTransactionOutcomesHash <- getTransactionOutcomesHash newState
bbStateHash <- getStateHash newState
bbDerivableHashes <- case blockHashVersion @(BlockHashVersionFor (MPV m)) of
SBlockHashVersion0 -> do
dbhv0TransactionOutcomesHash <- getTransactionOutcomesHash newState
dbhv0BlockStateHash <- getStateHash newState
return $ DerivableBlockHashesV0{..}
SBlockHashVersion1 -> do
let relativeBlockHeight = 1 + blockHeight bbiParent
currentEpoch <- use (roundStatus . rsCurrentEpoch)
dbhv1BlockResultHash <- computeBlockResultHash newState relativeBlockHeight currentEpoch
return $ DerivableBlockHashesV1{..}
let bakedBlock =
BakedBlock
{ bbRound = bbiRound,
Expand Down Expand Up @@ -1229,6 +1269,64 @@ bakeBlock BakeBlockInputs{..} = do
pendingTransactionTable .=! newPTT
return signedBlock

-- | Extract information from SkovData and the block state to compute the result block hash.
computeBlockResultHash ::
forall m.
( MonadState (SkovData (MPV m)) m,
BlockStateStorage m,
BlockState m ~ HashedPersistentBlockState (MPV m),
IsConsensusV1 (MPV m)
) =>
-- | The block state right after executing the block.
HashedPersistentBlockState (MPV m) ->
-- | The relative block height for the block.
BlockHeight ->
-- | The epoch of the block.
Epoch ->
m BlockResultHash
computeBlockResultHash newState relativeBlockHeight currentEpoch = do
theBlockStateHash <- getStateHash newState
transactionOutcomesHash <- getTransactionOutcomesHash newState
currentFinalizationCommitteeHash <- do
-- Attempt to get the current finalization committee from SkovData otherwise compute it from the
-- information in the block state.
currentSkovBakersAndFinalizers <- gets (getBakersForEpoch currentEpoch)
case currentSkovBakersAndFinalizers of
Just bakersAndFinalizers -> return $ bakersAndFinalizers ^. bfFinalizerHash
Nothing -> do
currentFullBakers <- getCurrentEpochBakers newState
currentFinalizationParameters <- getCurrentEpochFinalizationCommitteeParameters newState
let nextFinalizationCommittee = computeFinalizationCommittee currentFullBakers currentFinalizationParameters
return $ computeFinalizationCommitteeHash nextFinalizationCommittee
nextFinalizationCommitteeHash <- do
-- Attempt to get the next finalization committee from SkovData otherwise compute it from the
-- information in the block state.
nextSkovBakersAndFinalizers <- gets (getBakersForEpoch (currentEpoch + 1))
case nextSkovBakersAndFinalizers of
Just bakersAndFinalizers -> return $ bakersAndFinalizers ^. bfFinalizerHash
Nothing -> do
nextFullBakers <- getNextEpochBakers newState
nextFinalizationParameters <- getNextEpochFinalizationCommitteeParameters newState
let nextFinalizationCommittee = computeFinalizationCommittee nextFullBakers nextFinalizationParameters
return $ computeFinalizationCommitteeHash nextFinalizationCommittee
blockHeightInfo <- do
genesisBlockHeightInfo <- use genesisBlockHeight
return
BlockHeightInfo
{ bhiAbsoluteBlockHeight = localToAbsoluteBlockHeight (gbhiAbsoluteHeight genesisBlockHeightInfo) relativeBlockHeight,
bhiGenesisIndex = gbhiGenesisIndex genesisBlockHeightInfo,
bhiRelativeBlockHeight = relativeBlockHeight
}
return $
makeBlockResultHash
BlockResultHashInput
{ shiBlockStateHash = theBlockStateHash,
shiTransationOutcomesHash = transactionOutcomesHash,
shiCurrentFinalizationCommitteeHash = currentFinalizationCommitteeHash,
shiNextFinalizationCommitteeHash = nextFinalizationCommitteeHash,
shiBlockHeightInfo = blockHeightInfo
}

-- | Try to make a block, distribute it on the network and sign it as a finalizer.
-- This function should be called after any operation that can advance the current round to
-- attempt block production. A block will only be produced if we have credentials, are the
Expand Down
3 changes: 3 additions & 0 deletions concordium-consensus/src/Concordium/KonsensusV1/Flag.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ data FlaggableOffense (pv :: ProtocolVersion)
| -- | Execution of the block resulted in an unexpected state.
-- Witnessed by the block received and the parent block.
BlockInvalidStateHash !(SignedBlock pv) !(Block pv)
| -- | Execution of the block resulted in an unexpected result.
-- Witnessed by the block received and the parent block.
BlockInvalidResultHash !(SignedBlock pv) !(Block pv)
| -- | An invalid block was signed by the 'QuorumMessage'.
-- Witnessed by the 'QuorumMessage' received.
SignedInvalidBlock !QuorumMessage
Expand Down
Loading

0 comments on commit 98508e6

Please sign in to comment.