wasm: add metadata() functionality

This commit is contained in:
x
2022-11-05 15:08:07 +00:00
parent a9036f4f7c
commit 3aba630188
5 changed files with 58 additions and 5 deletions

View File

@@ -6,8 +6,9 @@ use darkfi_sdk::{
msg,
tx::FuncCall,
util::set_return_data,
pasta::pallas
};
use darkfi_serial::{deserialize, serialize, SerialDecodable, SerialEncodable};
use darkfi_serial::{deserialize, serialize, SerialDecodable, SerialEncodable, Encodable};
/// Available functions for this contract.
/// We identify them with the first byte passed in through the payload.
@@ -85,6 +86,42 @@ fn get_metadata(_cid: ContractId, ix: &[u8]) -> ContractResult {
let _call_data: FooCallData =
deserialize(&func_calls[func_call_index as usize].call_data)?;
let zk_public_values = vec![
(
"DaoProposeInput".to_string(),
vec![
pallas::Base::from(110),
pallas::Base::from(4)
]
),
(
"DaoProposeInput".to_string(),
vec![
pallas::Base::from(7),
pallas::Base::from(4)
]
),
(
"DaoProposeMain".to_string(),
vec![
pallas::Base::from(1),
pallas::Base::from(3),
pallas::Base::from(5),
pallas::Base::from(7)
]
)
];
let signature_public_keys: Vec<pallas::Point> = vec![
//pallas::Point::identity()
];
let mut metadata = Vec::new();
zk_public_values.encode(&mut metadata)?;
signature_public_keys.encode(&mut metadata)?;
set_return_data(&metadata)?;
msg!("metadata returned!");
// Convert call_data to halo2 public inputs
// Pass this to the env
}

View File

@@ -16,6 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use std::io::Cursor;
use darkfi::{
blockchain::Blockchain,
consensus::{TESTNET_GENESIS_HASH_BYTES, TESTNET_GENESIS_TIMESTAMP},
@@ -23,7 +24,7 @@ use darkfi::{
Result,
};
use darkfi_sdk::{crypto::ContractId, pasta::pallas, tx::FuncCall};
use darkfi_serial::{serialize, Encodable, WriteExt};
use darkfi_serial::{serialize, Decodable, Encodable, WriteExt};
use smart_contract::{FooCallData, Function};
@@ -84,5 +85,13 @@ fn run_contract() -> Result<()> {
// =====================================================
runtime.apply(&update)?;
// =====================================================
// Verify ZK proofs and signatures
// =====================================================
let metadata = runtime.metadata(&payload)?;
let mut decoder = Cursor::new(&metadata);
let zk_public_values: Vec<(String, Vec<pallas::Base>)> = Decodable::decode(&mut decoder)?;
let signature_public_keys: Vec<pallas::Point> = Decodable::decode(decoder)?;
Ok(())
}