Skip to content

Commit

Permalink
Make the consensus enclave aware of the master minters (#1684)
Browse files Browse the repository at this point in the history
* Add master minters configuration to TokensConfig (#1504)

* minting configuration wip

* fmt

* fix indent

* fix test

* add test, be more aggressive about validation

* use serde(with=...)

* one line

* Minting data types and initial LedgerDb support (#1537)

* initial mint data structures

* basic mint config in ledger

* basic get/set test

* another test

* update total minted api+tests

* add migration code

* enforce limit

* lock and lint

* fmt

* update comment and remove pub

* update lock files

* misc pr review fixes

* add a test for setting an active configuration with no configs

* small fixes

* use PEM encoding for signers

* fix tag

* ensure total minted amount cannot decrease

* use inconsistent_digit_grouping to make version numbers more readable

* fmt

* MintTx/Config protobuf conversions (#1558)

* add external.proto minting messages and api conversion traits

* tests

* mint tx conversions

* lint

* fix module name

* Store mint-related transations in LedgerDb (#1587)

* wip

* remove BlockContents::new to make adding new fields less tedious

* fix typos/lints

* add todo

* fix typos

* more defaults

* tests

* iterate

* more tests

* remove unneeded public api

* more tests

* more tests

* stricter validation

* reorganize code

* lint

* add mint migration code

* mint_tx_store test no. 1

* dont allow overwriting existing blocks, iterate on test

* pr fixes

* lint

* more tests

* add test

* remove unneeded type declaration

* Update ledger/db/src/mint_config_store.rs

Co-authored-by: sugargoat <sugargoat@mobilecoin.com>

* rename test to better explain what its testing

* be more strict about having outputs when MintTxs are present

Co-authored-by: sugargoat <sugargoat@mobilecoin.com>

* Expose LedgerDb API for looking up txs by nonce (#1602)

* wip

* remove BlockContents::new to make adding new fields less tedious

* fix typos/lints

* add todo

* fix typos

* more defaults

* tests

* iterate

* more tests

* remove unneeded public api

* more tests

* more tests

* stricter validation

* reorganize code

* lint

* add mint migration code

* mint_tx_store test no. 1

* dont allow overwriting existing blocks, iterate on test

* pr fixes

* lint

* more tests

* add test

* remove unneeded type declaration

* add public ledger api for looking up mint txs by nonce, change to return block index since that is more useful

* missing mock changes

* fix fmt

* Update ledger/db/src/mint_config_store.rs

Co-authored-by: Remoun Metyas <remoun@mobilecoin.com>

* fix typo

* Update ledger/db/src/mint_config_store.rs

Co-authored-by: sugargoat <sugargoat@mobilecoin.com>

* rename test to better explain what its testing

* be more strict about having outputs when MintTxs are present

* add public ledger api for looking up mint txs by nonce, change to return block index since that is more useful

Co-authored-by: Remoun Metyas <remoun@mobilecoin.com>
Co-authored-by: sugargoat <sugargoat@mobilecoin.com>

* Minting transaction validation (#1593)

* wip

* remove BlockContents::new to make adding new fields less tedious

* fix typos/lints

* add todo

* fix typos

* more defaults

* tests

* iterate

* more tests

* remove unneeded public api

* more tests

* more tests

* stricter validation

* reorganize code

* lint

* add mint migration code

* mint_tx_store test no. 1

* dont allow overwriting existing blocks, iterate on test

* pr fixes

* lint

* more tests

* add test

* remove unneeded type declaration

* add public ledger api for looking up mint txs by nonce, change to return block index since that is more useful

* missing mock changes

* fix fmt

* Update ledger/db/src/mint_config_store.rs

Co-authored-by: Remoun Metyas <remoun@mobilecoin.com>

* fix typo

* Update ledger/db/src/mint_config_store.rs

Co-authored-by: sugargoat <sugargoat@mobilecoin.com>

* rename test to better explain what its testing

* be more strict about having outputs when MintTxs are present

* add public ledger api for looking up mint txs by nonce, change to return block index since that is more useful

* initial work on validation

* SetMintConfigTx validation + tests

* reorganize

* MintTx validation and tests

* lint

* add comments

* update comments

* Update transaction/core/src/mint/validation/common.rs

Co-authored-by: Remoun Metyas <remoun@mobilecoin.com>

* Update transaction/core/src/mint/validation/config.rs

Co-authored-by: Remoun Metyas <remoun@mobilecoin.com>

* address pr review comment

* make nonce constant length

Co-authored-by: Remoun Metyas <remoun@mobilecoin.com>
Co-authored-by: sugargoat <sugargoat@mobilecoin.com>

* SetMintConfigTx -> MintConfigTx (#1607)

* SetMintConfigTx -> MintConfigTx

* more renames

* Small fixes following the confidential-token-id merging (#1609)

* post rebase fixes

* fix tests

* Eran/merge master 2022 03 14 (#1629)

* Update grpcio to 0.10 (#1592)

* Bump pretty_assertions from 1.1.0 to 1.2.0 (#1610)

Bumps [pretty_assertions](https://github.com/colin-kiegel/rust-pretty-assertions) from 1.1.0 to 1.2.0.
- [Release notes](https://github.com/colin-kiegel/rust-pretty-assertions/releases)
- [Changelog](https://github.com/colin-kiegel/rust-pretty-assertions/blob/main/CHANGELOG.md)
- [Commits](https://github.com/colin-kiegel/rust-pretty-assertions/commits)

---
updated-dependencies:
- dependency-name: pretty_assertions
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* delete slam, fixes #1574 (#1611)

slam is no longer needed because fog-distro, which began life
as a fork of it, has superceded it and slam is no longer used in
CD

* introduce FormBlockInputs and break out some code from form_block into its own method (#1625)

* introduce FormBlockInputs and break out some code from form_block into its own method

* add some missing code

* add missing import

* remove the Copy trait from ConsensusValue  (#1628)

* remove the Copy and Display traits from ConsensusValue since they make it hard to add transaction types that cant implement them

* add back display

* fmt

Co-authored-by: Remoun Metyas <remoun@mobilecoin.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Chris Beck <beck.ct@gmail.com>

* Support reaching consensus on MintConfigTxs (#1630)

* initial work on stubbing out SetMintConfigTx

* MintTxManager replaces stubs

* grpc api

* fmt

* mint client and misc improvements

* interate towards tx working

* actual validation taking place

* iterate

* append block from client works

* wip

* rename and lint

* fix nonce length

* comine, cleanups, validate that nonce is not already in ledger

* cleanups

* lint

* make test code reusable

* add tests

* structopt -> clap

* rebase fixes

* fix test

* Update consensus/mint-client/src/config.rs

Co-authored-by: Remoun Metyas <remoun@mobilecoin.com>

* address review comments

* Update transaction/core/test-utils/src/mint.rs

Co-authored-by: Remoun Metyas <remoun@mobilecoin.com>

* use dedup_by+truncate

* renames

* undo incorrect change

* typo

Co-authored-by: Remoun Metyas <remoun@mobilecoin.com>

* Support for reaching consensus on MintTx, mint client improvements (#1641)

* stub out ProposeMintTx

* expose get_active_mint_config_for_mint_tx, more plumbing

* undo wrong change

* MintTxManager impls for MintTx

* mint client support subcommands

* basic MintTx flow works, getting NoOutputs

* mobilecoind api filtering for token_id

* minting is working :)

* client improvements, local network script defaults to having two mintable tokens

* tests

* more tests yay

* testsssssssss

* test fixes and linting

* try without block version

* back to block v3

* Update consensus/service/src/api/client_api_service.rs

Co-authored-by: Remoun Metyas <remoun@mobilecoin.com>

* new line

Co-authored-by: Remoun Metyas <remoun@mobilecoin.com>

* Update ledger/db/src/mint_tx_store.rs

Co-authored-by: Remoun Metyas <remoun@mobilecoin.com>

* pr comments

* improve comment

* use const

* Update ledger/db/src/mint_tx_store.rs

Co-authored-by: Remoun Metyas <remoun@mobilecoin.com>

* lint

* add MasterMintersMap

* pass MasterMintersMap around

* enclave validates MintConfigTxs

* fix typo

* lint

* more lint

* fix block index

* try less concurrency

* Revert "try less concurrency"

This reverts commit 0e4209f.

Co-authored-by: sugargoat <sugargoat@mobilecoin.com>
Co-authored-by: Remoun Metyas <remoun@mobilecoin.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Chris Beck <beck.ct@gmail.com>
  • Loading branch information
5 people authored Mar 22, 2022
1 parent 5cfd2be commit acbf108
Show file tree
Hide file tree
Showing 13 changed files with 398 additions and 72 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions consensus/enclave/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mc-common = { path = "../../../common", default-features = false }
mc-crypto-digestible = { path = "../../../crypto/digestible", features = ["derive"] }
mc-crypto-keys = { path = "../../../crypto/keys", default-features = false }
mc-crypto-message-cipher = { path = "../../../crypto/message-cipher" }
mc-crypto-multisig = { path = "../../../crypto/multisig" }
mc-sgx-compat = { path = "../../../sgx/compat" }
mc-sgx-report-cache-api = { path = "../../../sgx/report-cache/api" }
mc-transaction-core = { path = "../../../transaction/core" }
Expand Down
70 changes: 66 additions & 4 deletions consensus/enclave/api/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::FeeMap;
use crate::{FeeMap, MasterMintersMap};
use alloc::{format, string::String};
use mc_common::ResponderId;
use mc_crypto_digestible::{Digestible, MerlinTranscript};
Expand All @@ -12,17 +12,22 @@ use serde::{Deserialize, Serialize};
/// signing key)
#[derive(Clone, Deserialize, Debug, Digestible, Eq, Hash, PartialEq, Serialize)]
pub struct BlockchainConfig {
/// The map from tokens to their minimum fees
/// The map from tokens to their minimum fees.
pub fee_map: FeeMap,

/// The map from tokens to master minters.
pub master_minters_map: MasterMintersMap,

/// The block version that this enclave will be applying rules for and
/// publishing
/// publishing.
pub block_version: BlockVersion,
}

impl Default for BlockchainConfig {
fn default() -> Self {
Self {
fee_map: FeeMap::default(),
master_minters_map: MasterMintersMap::default(),
block_version: BlockVersion::MAX,
}
}
Expand Down Expand Up @@ -76,7 +81,9 @@ impl BlockchainConfigWithDigest {
#[cfg(test)]
mod test {
use super::*;
use alloc::string::ToString;
use alloc::{string::ToString, vec};
use mc_crypto_keys::Ed25519Public;
use mc_crypto_multisig::SignerSet;
use mc_transaction_core::{tokens::Mob, Token, TokenId};

/// Different block_version/fee maps/responder ids should result in
Expand All @@ -85,16 +92,19 @@ mod test {
fn different_fee_maps_result_in_different_responder_ids() {
let config1: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::try_from_iter([(Mob::ID, 100), (TokenId::from(2), 2000)]).unwrap(),
master_minters_map: MasterMintersMap::default(),
block_version: BlockVersion::ONE,
}
.into();
let config2: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::try_from_iter([(Mob::ID, 100), (TokenId::from(2), 300)]).unwrap(),
master_minters_map: MasterMintersMap::default(),
block_version: BlockVersion::ONE,
}
.into();
let config3: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::try_from_iter([(Mob::ID, 100), (TokenId::from(30), 300)]).unwrap(),
master_minters_map: MasterMintersMap::default(),
block_version: BlockVersion::ONE,
}
.into();
Expand Down Expand Up @@ -129,6 +139,7 @@ mod test {

let config4: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::try_from_iter([(Mob::ID, 100), (TokenId::from(30), 300)]).unwrap(),
master_minters_map: MasterMintersMap::default(),
block_version: BlockVersion::TWO,
}
.into();
Expand All @@ -143,4 +154,55 @@ mod test {
config4.responder_id(&responder_id2)
);
}

// Different master minter maps result in differnet responder ids.
#[test]
fn different_master_minter_maps_result_in_different_responder_ids() {
let config1: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::default(),
master_minters_map: MasterMintersMap::try_from_iter([(
TokenId::from(1),
SignerSet::new(vec![Ed25519Public::default()], 1),
)])
.unwrap(),
block_version: BlockVersion::ONE,
}
.into();
let config2: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::default(),
master_minters_map: MasterMintersMap::try_from_iter([(
TokenId::from(2),
SignerSet::new(vec![Ed25519Public::default()], 1),
)])
.unwrap(),
block_version: BlockVersion::ONE,
}
.into();
let config3: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::default(),
master_minters_map: MasterMintersMap::try_from_iter([(
TokenId::from(2),
SignerSet::new(vec![Ed25519Public::default(), Ed25519Public::default()], 1),
)])
.unwrap(),
block_version: BlockVersion::ONE,
}
.into();

let responder_id1 = ResponderId("1.2.3.4:5".to_string());
assert_ne!(
config1.responder_id(&responder_id1),
config2.responder_id(&responder_id1)
);

assert_ne!(
config1.responder_id(&responder_id1),
config3.responder_id(&responder_id1)
);

assert_ne!(
config2.responder_id(&responder_id1),
config3.responder_id(&responder_id1)
);
}
}
11 changes: 10 additions & 1 deletion consensus/enclave/api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use mc_attest_enclave_api::Error as AttestEnclaveError;
use mc_crypto_keys::SignatureError;
use mc_crypto_message_cipher::CipherError as MessageCipherError;
use mc_sgx_compat::sync::PoisonError;
use mc_transaction_core::validation::TransactionValidationError;
use mc_transaction_core::{mint::MintValidationError, validation::TransactionValidationError};
use mc_util_serial::{
decode::Error as RmpDecodeError, encode::Error as RmpEncodeError,
DecodeError as ProstDecodeError, EncodeError as ProstEncodeError,
Expand Down Expand Up @@ -38,6 +38,9 @@ pub enum Error {
/// Malformed transaction: {0}
MalformedTx(TransactionValidationError),

/// Malformed minting transaction: {0}
MalformedMintingTx(MintValidationError),

/// Invalid membership proof provided by local system
InvalidLocalMembershipProof,

Expand Down Expand Up @@ -126,6 +129,12 @@ impl From<TransactionValidationError> for Error {
}
}

impl From<MintValidationError> for Error {
fn from(src: MintValidationError) -> Error {
Error::MalformedMintingTx(src)
}
}

impl From<AttestEnclaveError> for Error {
fn from(src: AttestEnclaveError) -> Error {
Error::Attest(src)
Expand Down
2 changes: 1 addition & 1 deletion consensus/enclave/api/src/fee_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use mc_crypto_digestible::Digestible;
use mc_transaction_core::{tokens::Mob, Token, TokenId};
use serde::{Deserialize, Serialize};

/// A thread-safe object that contains a map of fee value by token id.
/// A map of fee value by token id.
#[derive(Clone, Debug, Deserialize, Digestible, Eq, Hash, PartialEq, Serialize)]
pub struct FeeMap {
/// The actual map of token_id to fee.
Expand Down
2 changes: 2 additions & 0 deletions consensus/enclave/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ extern crate alloc;
mod config;
mod error;
mod fee_map;
mod master_minters_map;
mod messages;

pub use crate::{
config::{BlockchainConfig, BlockchainConfigWithDigest},
error::Error,
fee_map::{Error as FeeMapError, FeeMap},
master_minters_map::{Error as MasterMintersMapError, MasterMintersMap},
messages::EnclaveCall,
};

Expand Down
Loading

0 comments on commit acbf108

Please sign in to comment.