|
@@ -16,7 +16,6 @@
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-<<<<<<< HEAD
|
|
|
|
|
use darkfi_money_contract::{
|
|
use darkfi_money_contract::{
|
|
|
model::{ConsensusStakeUpdateV1, ConsensusUnstakeUpdateV1},
|
|
model::{ConsensusStakeUpdateV1, ConsensusUnstakeUpdateV1},
|
|
|
CONSENSUS_CONTRACT_COINS_TREE, CONSENSUS_CONTRACT_COIN_MERKLE_TREE,
|
|
CONSENSUS_CONTRACT_COINS_TREE, CONSENSUS_CONTRACT_COIN_MERKLE_TREE,
|
|
@@ -27,24 +26,13 @@ use darkfi_money_contract::{
|
|
|
};
|
|
};
|
|
|
use darkfi_sdk::{
|
|
use darkfi_sdk::{
|
|
|
crypto::{ContractId, MerkleTree},
|
|
crypto::{ContractId, MerkleTree},
|
|
|
- db::{db_init, db_lookup, db_set, set_return_data, SMART_CONTRACT_ZKAS_DB_NAME},
|
|
|
|
|
|
|
+ db::{db_init, db_lookup, db_set, set_return_data, zkas_db_set},
|
|
|
error::{ContractError, ContractResult},
|
|
error::{ContractError, ContractResult},
|
|
|
msg, ContractCall,
|
|
msg, ContractCall,
|
|
|
};
|
|
};
|
|
|
use darkfi_serial::{deserialize, serialize, Encodable, WriteExt};
|
|
use darkfi_serial::{deserialize, serialize, Encodable, WriteExt};
|
|
|
|
|
|
|
|
use crate::{model::ConsensusRewardUpdateV1, ConsensusFunction};
|
|
use crate::{model::ConsensusRewardUpdateV1, ConsensusFunction};
|
|
|
-=======
|
|
|
|
|
-use darkfi_sdk::{
|
|
|
|
|
- crypto::ContractId,
|
|
|
|
|
- db::{db_init, db_lookup, set_return_data, SMART_CONTRACT_ZKAS_DB_NAME},
|
|
|
|
|
- error::{ContractError, ContractResult},
|
|
|
|
|
- msg, ContractCall,
|
|
|
|
|
-};
|
|
|
|
|
-use darkfi_serial::deserialize;
|
|
|
|
|
-
|
|
|
|
|
-use crate::{model::ConsensusStakeUpdateV1, ConsensusFunction};
|
|
|
|
|
->>>>>>> 2b38600b8a (contract/consensus: laid foundation)
|
|
|
|
|
|
|
|
|
|
/// `Consensus::Stake` functions
|
|
/// `Consensus::Stake` functions
|
|
|
mod stake_v1;
|
|
mod stake_v1;
|
|
@@ -53,7 +41,6 @@ use stake_v1::{
|
|
|
consensus_stake_process_update_v1,
|
|
consensus_stake_process_update_v1,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-<<<<<<< HEAD
|
|
|
|
|
/// `Consensus::ProposalBurn` functions
|
|
/// `Consensus::ProposalBurn` functions
|
|
|
mod proposal_burn_v1;
|
|
mod proposal_burn_v1;
|
|
|
use proposal_burn_v1::{
|
|
use proposal_burn_v1::{
|
|
@@ -82,8 +69,6 @@ use unstake_v1::{
|
|
|
consensus_unstake_process_update_v1,
|
|
consensus_unstake_process_update_v1,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-=======
|
|
|
|
|
->>>>>>> 2b38600b8a (contract/consensus: laid foundation)
|
|
|
|
|
darkfi_sdk::define_contract!(
|
|
darkfi_sdk::define_contract!(
|
|
|
init: init_contract,
|
|
init: init_contract,
|
|
|
exec: process_instruction,
|
|
exec: process_instruction,
|
|
@@ -96,27 +81,18 @@ darkfi_sdk::define_contract!(
|
|
|
/// with initial data if necessary. This is also the place where we bundle the zkas
|
|
/// with initial data if necessary. This is also the place where we bundle the zkas
|
|
|
/// circuits that are to be used with functions provided by the contract.
|
|
/// circuits that are to be used with functions provided by the contract.
|
|
|
fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
|
|
fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
|
|
|
- // The zkas circuit can simply be embedded in the wasm and set up by
|
|
|
|
|
- // the initialization. Note that the tree should then be called "zkas".
|
|
|
|
|
- // The lookups can be done by `contract_id+_zkas+namespace`.
|
|
|
|
|
- // TODO: For the zkas tree, external host checks should be done to ensure
|
|
|
|
|
- // that the bincode is actually valid and not arbitrary.
|
|
|
|
|
-<<<<<<< HEAD
|
|
|
|
|
- let zkas_db = match db_lookup(cid, SMART_CONTRACT_ZKAS_DB_NAME) {
|
|
|
|
|
-=======
|
|
|
|
|
- let _zkas_db = match db_lookup(cid, SMART_CONTRACT_ZKAS_DB_NAME) {
|
|
|
|
|
->>>>>>> 2b38600b8a (contract/consensus: laid foundation)
|
|
|
|
|
- Ok(v) => v,
|
|
|
|
|
- Err(_) => db_init(cid, SMART_CONTRACT_ZKAS_DB_NAME)?,
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
-<<<<<<< HEAD
|
|
|
|
|
|
|
+ // zkas circuits can simply be embedded in the wasm and set up by using
|
|
|
|
|
+ // respective db functions. The special `zkas db` operations exist in
|
|
|
|
|
+ // order to be able to verify the circuits being bundled and enforcing
|
|
|
|
|
+ // a specific tree inside sled, and also creation of VerifyingKey.
|
|
|
let money_mint_v1_bincode = include_bytes!("../../money/proof/mint_v1.zk.bin");
|
|
let money_mint_v1_bincode = include_bytes!("../../money/proof/mint_v1.zk.bin");
|
|
|
let money_burn_v1_bincode = include_bytes!("../../money/proof/burn_v1.zk.bin");
|
|
let money_burn_v1_bincode = include_bytes!("../../money/proof/burn_v1.zk.bin");
|
|
|
let reward_v1_bincode = include_bytes!("../proof/reward_v1.zk.bin");
|
|
let reward_v1_bincode = include_bytes!("../proof/reward_v1.zk.bin");
|
|
|
- db_set(zkas_db, &serialize(&MONEY_CONTRACT_ZKAS_MINT_NS_V1), &money_mint_v1_bincode[..])?;
|
|
|
|
|
- db_set(zkas_db, &serialize(&MONEY_CONTRACT_ZKAS_BURN_NS_V1), &money_burn_v1_bincode[..])?;
|
|
|
|
|
- db_set(zkas_db, &serialize(&CONSENSUS_CONTRACT_ZKAS_REWARD_NS_V1), &reward_v1_bincode[..])?;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // For that, we use `zkas_db_set` and pass in the bincode.
|
|
|
|
|
+ zkas_db_set(&money_mint_v1_bincode[..])?;
|
|
|
|
|
+ zkas_db_set(&money_burn_v1_bincode[..])?;
|
|
|
|
|
+ zkas_db_set(&reward_v1_bincode[..])?;
|
|
|
|
|
|
|
|
// Set up a database tree to hold Merkle roots of all coins
|
|
// Set up a database tree to hold Merkle roots of all coins
|
|
|
// k=MerkleNode, v=[]
|
|
// k=MerkleNode, v=[]
|
|
@@ -160,9 +136,6 @@ fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
|
|
|
&serialize(&CONSENSUS_CONTRACT_DB_VERSION),
|
|
&serialize(&CONSENSUS_CONTRACT_DB_VERSION),
|
|
|
&serialize(&env!("CARGO_PKG_VERSION")),
|
|
&serialize(&env!("CARGO_PKG_VERSION")),
|
|
|
)?;
|
|
)?;
|
|
|
-=======
|
|
|
|
|
- // TODO: implement
|
|
|
|
|
->>>>>>> 2b38600b8a (contract/consensus: laid foundation)
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
Ok(())
|
|
|
}
|
|
}
|
|
@@ -186,7 +159,6 @@ fn get_metadata(cid: ContractId, ix: &[u8]) -> ContractResult {
|
|
|
let metadata = consensus_stake_get_metadata_v1(cid, call_idx, calls)?;
|
|
let metadata = consensus_stake_get_metadata_v1(cid, call_idx, calls)?;
|
|
|
Ok(set_return_data(&metadata)?)
|
|
Ok(set_return_data(&metadata)?)
|
|
|
}
|
|
}
|
|
|
-<<<<<<< HEAD
|
|
|
|
|
ConsensusFunction::ProposalBurnV1 => {
|
|
ConsensusFunction::ProposalBurnV1 => {
|
|
|
let metadata = consensus_proposal_burn_get_metadata_v1(cid, call_idx, calls)?;
|
|
let metadata = consensus_proposal_burn_get_metadata_v1(cid, call_idx, calls)?;
|
|
|
Ok(set_return_data(&metadata)?)
|
|
Ok(set_return_data(&metadata)?)
|
|
@@ -203,8 +175,6 @@ fn get_metadata(cid: ContractId, ix: &[u8]) -> ContractResult {
|
|
|
let metadata = consensus_unstake_get_metadata_v1(cid, call_idx, calls)?;
|
|
let metadata = consensus_unstake_get_metadata_v1(cid, call_idx, calls)?;
|
|
|
Ok(set_return_data(&metadata)?)
|
|
Ok(set_return_data(&metadata)?)
|
|
|
}
|
|
}
|
|
|
-=======
|
|
|
|
|
->>>>>>> 2b38600b8a (contract/consensus: laid foundation)
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -228,7 +198,6 @@ fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
|
|
|
let update_data = consensus_stake_process_instruction_v1(cid, call_idx, calls)?;
|
|
let update_data = consensus_stake_process_instruction_v1(cid, call_idx, calls)?;
|
|
|
Ok(set_return_data(&update_data)?)
|
|
Ok(set_return_data(&update_data)?)
|
|
|
}
|
|
}
|
|
|
-<<<<<<< HEAD
|
|
|
|
|
ConsensusFunction::ProposalBurnV1 => {
|
|
ConsensusFunction::ProposalBurnV1 => {
|
|
|
let update_data = consensus_proposal_burn_process_instruction_v1(cid, call_idx, calls)?;
|
|
let update_data = consensus_proposal_burn_process_instruction_v1(cid, call_idx, calls)?;
|
|
|
Ok(set_return_data(&update_data)?)
|
|
Ok(set_return_data(&update_data)?)
|
|
@@ -246,8 +215,6 @@ fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
|
|
|
let update_data = consensus_unstake_process_instruction_v1(cid, call_idx, calls)?;
|
|
let update_data = consensus_unstake_process_instruction_v1(cid, call_idx, calls)?;
|
|
|
Ok(set_return_data(&update_data)?)
|
|
Ok(set_return_data(&update_data)?)
|
|
|
}
|
|
}
|
|
|
-=======
|
|
|
|
|
->>>>>>> 2b38600b8a (contract/consensus: laid foundation)
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -261,7 +228,6 @@ fn process_update(cid: ContractId, update_data: &[u8]) -> ContractResult {
|
|
|
let update: ConsensusStakeUpdateV1 = deserialize(&update_data[1..])?;
|
|
let update: ConsensusStakeUpdateV1 = deserialize(&update_data[1..])?;
|
|
|
Ok(consensus_stake_process_update_v1(cid, update)?)
|
|
Ok(consensus_stake_process_update_v1(cid, update)?)
|
|
|
}
|
|
}
|
|
|
-<<<<<<< HEAD
|
|
|
|
|
ConsensusFunction::ProposalBurnV1 => {
|
|
ConsensusFunction::ProposalBurnV1 => {
|
|
|
let update: ConsensusUnstakeUpdateV1 = deserialize(&update_data[1..])?;
|
|
let update: ConsensusUnstakeUpdateV1 = deserialize(&update_data[1..])?;
|
|
|
Ok(consensus_proposal_burn_process_update_v1(cid, update)?)
|
|
Ok(consensus_proposal_burn_process_update_v1(cid, update)?)
|
|
@@ -278,7 +244,5 @@ fn process_update(cid: ContractId, update_data: &[u8]) -> ContractResult {
|
|
|
let update: ConsensusUnstakeUpdateV1 = deserialize(&update_data[1..])?;
|
|
let update: ConsensusUnstakeUpdateV1 = deserialize(&update_data[1..])?;
|
|
|
Ok(consensus_unstake_process_update_v1(cid, update)?)
|
|
Ok(consensus_unstake_process_update_v1(cid, update)?)
|
|
|
}
|
|
}
|
|
|
-=======
|
|
|
|
|
->>>>>>> 2b38600b8a (contract/consensus: laid foundation)
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|