-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prototype minting circuits for token contracts
- Loading branch information
Showing
3 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use super::*; | ||
|
||
pub fn mint<K: KvStore>( | ||
chain: &mut KvStoreChain<K>, | ||
contract_id: &ContractId, | ||
contract: &zk::ZkContract, | ||
function_id: &u32, | ||
amount: &Amount, | ||
executor_fees: &mut Vec<Money>, | ||
) -> Result<(zk::ZkVerifierKey, zk::ZkCompressedState), BlockchainError> { | ||
if let Some(token) = &contract.token { | ||
/*let mut bal = chain.get_contract_balance(contract_id.clone(), *token_id)?; | ||
if bal + *amount < bal || token.token.supply + *amount < token.token.supply { | ||
return Err(BlockchainError::TokenSupplyOverflow); | ||
} | ||
bal += *amount; | ||
token.supply += *amount; | ||
chain | ||
.database | ||
.update(&[WriteOp::Put(keys::token(token_id), (&token).into())])?; | ||
chain.database.update(&[WriteOp::Put( | ||
keys::account_balance(&tx_src, *token_id), | ||
bal.into(), | ||
)])?;*/ | ||
|
||
let func = token | ||
.mint_functions | ||
.get(*function_id as usize) | ||
.ok_or(BlockchainError::ContractFunctionNotFound)?; | ||
let circuit = &func.verifier_key; | ||
let mut state_builder = zk::ZkStateBuilder::<CoreZkHasher>::new(zk::ZkStateModel::Scalar); | ||
state_builder.batch_set(&zk::ZkDeltaPairs( | ||
[(zk::ZkDataLocator(vec![]), Some((*amount).into()))].into(), | ||
))?; | ||
let aux_data = state_builder.compress()?; | ||
Ok((circuit.clone(), aux_data)) | ||
} else { | ||
Err(BlockchainError::ContractNotToken) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters