diff --git a/contracts/host/src/lib.rs b/contracts/host/src/lib.rs index 07fdefc9..dd85f6e9 100644 --- a/contracts/host/src/lib.rs +++ b/contracts/host/src/lib.rs @@ -45,12 +45,6 @@ impl Hoster { false => String::from("PROOF IS INVALID"), } } - - /// Call 'get_counter' function available from the host, and return the - /// result - pub fn host_get_counter(&self) -> i64 { - uplink::host_query("get_counter", ()) - } } /// Expose `Hoster::host_hash()` to the host @@ -66,9 +60,3 @@ unsafe fn host_verify(arg_len: u32) -> u32 { STATE.host_verify(proof, public_inputs) }) } - -/// Expose `Hoster::host_counter()` to the host -#[no_mangle] -unsafe fn host_get_counter(arg_len: u32) -> u32 { - uplink::wrap_call(arg_len, |()| STATE.host_get_counter()) -} diff --git a/piecrust/CHANGELOG.md b/piecrust/CHANGELOG.md index ec1586de..99666317 100644 --- a/piecrust/CHANGELOG.md +++ b/piecrust/CHANGELOG.md @@ -17,7 +17,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- Allow for a `HostQuery` to take a `&mut Session` [#327] - Change to have one instance per contract function call [#325] - Upgrade `dusk-wasmtime` to version `17` @@ -364,7 +363,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#234]: https://github.com/dusk-network/piecrust/pull/234 -[#327]: https://github.com/dusk-network/piecrust/issues/327 [#325]: https://github.com/dusk-network/piecrust/issues/325 [#324]: https://github.com/dusk-network/piecrust/issues/324 [#301]: https://github.com/dusk-network/piecrust/issues/313 diff --git a/piecrust/src/session.rs b/piecrust/src/session.rs index 429f799a..fd3cf14f 100644 --- a/piecrust/src/session.rs +++ b/piecrust/src/session.rs @@ -554,10 +554,7 @@ impl Session { buf: &mut [u8], arg_len: u32, ) -> Option { - let mut session = self.clone(); - self.inner - .host_queries - .call(&mut session, name, buf, arg_len) + self.inner.host_queries.call(name, buf, arg_len) } pub(crate) fn nth_from_top(&self, n: usize) -> Option { diff --git a/piecrust/src/vm.rs b/piecrust/src/vm.rs index 65901134..58e6e8f8 100644 --- a/piecrust/src/vm.rs +++ b/piecrust/src/vm.rs @@ -236,16 +236,8 @@ impl HostQueries { self.map.insert(name.into(), Arc::new(query)); } - pub fn call( - &self, - session: &mut Session, - name: &str, - buf: &mut [u8], - len: u32, - ) -> Option { - self.map - .get(name) - .map(|host_query| host_query(session, buf, len)) + pub fn call(&self, name: &str, buf: &mut [u8], len: u32) -> Option { + self.map.get(name).map(|host_query| host_query(buf, len)) } } @@ -256,18 +248,5 @@ impl HostQueries { /// function, and should be processed first. Once this is done, the implementor /// should emplace the return of the query in the same buffer, and return the /// length written. -/// -/// The host query will have access to the underlying session, and can use it to -/// perform calls to other contracts. -/// -/// # Panics -/// If any error occurs during the execution, the implementer is encouraged to -/// signal this error by panicking. -pub trait HostQuery: - Send + Sync + Fn(&mut Session, &mut [u8], u32) -> u32 -{ -} -impl HostQuery for F where - F: Send + Sync + Fn(&mut Session, &mut [u8], u32) -> u32 -{ -} +pub trait HostQuery: Send + Sync + Fn(&mut [u8], u32) -> u32 {} +impl HostQuery for F where F: Send + Sync + Fn(&mut [u8], u32) -> u32 {} diff --git a/piecrust/tests/host.rs b/piecrust/tests/host.rs index 7a31e4cf..6c847a62 100644 --- a/piecrust/tests/host.rs +++ b/piecrust/tests/host.rs @@ -6,10 +6,7 @@ use dusk_plonk::prelude::*; use once_cell::sync::Lazy; -use piecrust::{ - contract_bytecode, ContractData, Error, Session, SessionData, VM, -}; -use piecrust_uplink::ContractId; +use piecrust::{contract_bytecode, ContractData, Error, SessionData, VM}; use rand::rngs::OsRng; use rkyv::Deserialize; @@ -33,7 +30,7 @@ fn get_prover_verifier() -> &'static (Prover, Verifier) { &PROVER_VERIFIER } -fn hash(_: &mut Session, buf: &mut [u8], len: u32) -> u32 { +fn hash(buf: &mut [u8], len: u32) -> u32 { let a = unsafe { rkyv::archived_root::>(&buf[..len as usize]) }; let v: Vec = a.deserialize(&mut rkyv::Infallible).unwrap(); @@ -43,7 +40,7 @@ fn hash(_: &mut Session, buf: &mut [u8], len: u32) -> u32 { 32 } -fn verify_proof(_: &mut Session, buf: &mut [u8], len: u32) -> u32 { +fn verify_proof(buf: &mut [u8], len: u32) -> u32 { let a = unsafe { rkyv::archived_root::<(Proof, Vec)>(&buf[..len as usize]) }; @@ -61,24 +58,10 @@ fn verify_proof(_: &mut Session, buf: &mut [u8], len: u32) -> u32 { valid_bytes.len() as u32 } -pub const COUNTER_ID: ContractId = ContractId::from_bytes([1; 32]); - -fn get_counter(session: &mut Session, buf: &mut [u8], _: u32) -> u32 { - let receipt = session - .call_raw(COUNTER_ID, "read_value", &*buf, u64::MAX) - .expect("calling the counter contract should succeed"); - - let data = receipt.data; - buf[..data.len()].copy_from_slice(&data); - - data.len() as u32 -} - fn new_ephemeral_vm() -> Result { let mut vm = VM::ephemeral()?; vm.register_host_query("hash", hash); vm.register_host_query("verify_proof", verify_proof); - vm.register_host_query("get_counter", get_counter); Ok(vm) } @@ -104,35 +87,6 @@ pub fn host_hash() -> Result<(), Error> { Ok(()) } -/// Queries a contract for the value held in the counter contract through the -/// host, using a host query. -#[test] -fn host_counter() -> Result<(), Error> { - let vm = new_ephemeral_vm()?; - - let mut session = vm.session(SessionData::builder())?; - - session.deploy( - contract_bytecode!("counter"), - ContractData::builder(OWNER).contract_id(COUNTER_ID), - LIMIT, - )?; - - let id = session.deploy( - contract_bytecode!("host"), - ContractData::builder(OWNER), - LIMIT, - )?; - - let counter = session - .call::<_, i64>(id, "host_get_counter", &(), LIMIT)? - .data; - - assert_eq!(counter, 0xfc); - - Ok(()) -} - /// Proves that we know a number `c` such that `a + b = c`. #[derive(Default)] struct TestCircuit {