Skip to content

Commit 0df34c6

Browse files
authored
Revert "Allow for a HostQuery to take &mut Session"
1 parent ad5071e commit 0df34c6

File tree

5 files changed

+8
-92
lines changed

5 files changed

+8
-92
lines changed

contracts/host/src/lib.rs

-12
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ impl Hoster {
4545
false => String::from("PROOF IS INVALID"),
4646
}
4747
}
48-
49-
/// Call 'get_counter' function available from the host, and return the
50-
/// result
51-
pub fn host_get_counter(&self) -> i64 {
52-
uplink::host_query("get_counter", ())
53-
}
5448
}
5549

5650
/// Expose `Hoster::host_hash()` to the host
@@ -66,9 +60,3 @@ unsafe fn host_verify(arg_len: u32) -> u32 {
6660
STATE.host_verify(proof, public_inputs)
6761
})
6862
}
69-
70-
/// Expose `Hoster::host_counter()` to the host
71-
#[no_mangle]
72-
unsafe fn host_get_counter(arg_len: u32) -> u32 {
73-
uplink::wrap_call(arg_len, |()| STATE.host_get_counter())
74-
}

piecrust/CHANGELOG.md

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
### Changed
1919

20-
- Allow for a `HostQuery` to take a `&mut Session` [#327]
2120
- Change to have one instance per contract function call [#325]
2221
- Upgrade `dusk-wasmtime` to version `17`
2322

@@ -364,7 +363,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
364363
[#234]: https://github.com/dusk-network/piecrust/pull/234
365364

366365
<!-- ISSUES -->
367-
[#327]: https://github.com/dusk-network/piecrust/issues/327
368366
[#325]: https://github.com/dusk-network/piecrust/issues/325
369367
[#324]: https://github.com/dusk-network/piecrust/issues/324
370368
[#301]: https://github.com/dusk-network/piecrust/issues/313

piecrust/src/session.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,7 @@ impl Session {
554554
buf: &mut [u8],
555555
arg_len: u32,
556556
) -> Option<u32> {
557-
let mut session = self.clone();
558-
self.inner
559-
.host_queries
560-
.call(&mut session, name, buf, arg_len)
557+
self.inner.host_queries.call(name, buf, arg_len)
561558
}
562559

563560
pub(crate) fn nth_from_top(&self, n: usize) -> Option<CallTreeElem> {

piecrust/src/vm.rs

+4-25
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,8 @@ impl HostQueries {
236236
self.map.insert(name.into(), Arc::new(query));
237237
}
238238

239-
pub fn call(
240-
&self,
241-
session: &mut Session,
242-
name: &str,
243-
buf: &mut [u8],
244-
len: u32,
245-
) -> Option<u32> {
246-
self.map
247-
.get(name)
248-
.map(|host_query| host_query(session, buf, len))
239+
pub fn call(&self, name: &str, buf: &mut [u8], len: u32) -> Option<u32> {
240+
self.map.get(name).map(|host_query| host_query(buf, len))
249241
}
250242
}
251243

@@ -256,18 +248,5 @@ impl HostQueries {
256248
/// function, and should be processed first. Once this is done, the implementor
257249
/// should emplace the return of the query in the same buffer, and return the
258250
/// length written.
259-
///
260-
/// The host query will have access to the underlying session, and can use it to
261-
/// perform calls to other contracts.
262-
///
263-
/// # Panics
264-
/// If any error occurs during the execution, the implementer is encouraged to
265-
/// signal this error by panicking.
266-
pub trait HostQuery:
267-
Send + Sync + Fn(&mut Session, &mut [u8], u32) -> u32
268-
{
269-
}
270-
impl<F> HostQuery for F where
271-
F: Send + Sync + Fn(&mut Session, &mut [u8], u32) -> u32
272-
{
273-
}
251+
pub trait HostQuery: Send + Sync + Fn(&mut [u8], u32) -> u32 {}
252+
impl<F> HostQuery for F where F: Send + Sync + Fn(&mut [u8], u32) -> u32 {}

piecrust/tests/host.rs

+3-49
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
use dusk_plonk::prelude::*;
88
use once_cell::sync::Lazy;
9-
use piecrust::{
10-
contract_bytecode, ContractData, Error, Session, SessionData, VM,
11-
};
12-
use piecrust_uplink::ContractId;
9+
use piecrust::{contract_bytecode, ContractData, Error, SessionData, VM};
1310
use rand::rngs::OsRng;
1411
use rkyv::Deserialize;
1512

@@ -33,7 +30,7 @@ fn get_prover_verifier() -> &'static (Prover, Verifier) {
3330
&PROVER_VERIFIER
3431
}
3532

36-
fn hash(_: &mut Session, buf: &mut [u8], len: u32) -> u32 {
33+
fn hash(buf: &mut [u8], len: u32) -> u32 {
3734
let a = unsafe { rkyv::archived_root::<Vec<u8>>(&buf[..len as usize]) };
3835
let v: Vec<u8> = a.deserialize(&mut rkyv::Infallible).unwrap();
3936

@@ -43,7 +40,7 @@ fn hash(_: &mut Session, buf: &mut [u8], len: u32) -> u32 {
4340
32
4441
}
4542

46-
fn verify_proof(_: &mut Session, buf: &mut [u8], len: u32) -> u32 {
43+
fn verify_proof(buf: &mut [u8], len: u32) -> u32 {
4744
let a = unsafe {
4845
rkyv::archived_root::<(Proof, Vec<BlsScalar>)>(&buf[..len as usize])
4946
};
@@ -61,24 +58,10 @@ fn verify_proof(_: &mut Session, buf: &mut [u8], len: u32) -> u32 {
6158
valid_bytes.len() as u32
6259
}
6360

64-
pub const COUNTER_ID: ContractId = ContractId::from_bytes([1; 32]);
65-
66-
fn get_counter(session: &mut Session, buf: &mut [u8], _: u32) -> u32 {
67-
let receipt = session
68-
.call_raw(COUNTER_ID, "read_value", &*buf, u64::MAX)
69-
.expect("calling the counter contract should succeed");
70-
71-
let data = receipt.data;
72-
buf[..data.len()].copy_from_slice(&data);
73-
74-
data.len() as u32
75-
}
76-
7761
fn new_ephemeral_vm() -> Result<VM, Error> {
7862
let mut vm = VM::ephemeral()?;
7963
vm.register_host_query("hash", hash);
8064
vm.register_host_query("verify_proof", verify_proof);
81-
vm.register_host_query("get_counter", get_counter);
8265
Ok(vm)
8366
}
8467

@@ -104,35 +87,6 @@ pub fn host_hash() -> Result<(), Error> {
10487
Ok(())
10588
}
10689

107-
/// Queries a contract for the value held in the counter contract through the
108-
/// host, using a host query.
109-
#[test]
110-
fn host_counter() -> Result<(), Error> {
111-
let vm = new_ephemeral_vm()?;
112-
113-
let mut session = vm.session(SessionData::builder())?;
114-
115-
session.deploy(
116-
contract_bytecode!("counter"),
117-
ContractData::builder(OWNER).contract_id(COUNTER_ID),
118-
LIMIT,
119-
)?;
120-
121-
let id = session.deploy(
122-
contract_bytecode!("host"),
123-
ContractData::builder(OWNER),
124-
LIMIT,
125-
)?;
126-
127-
let counter = session
128-
.call::<_, i64>(id, "host_get_counter", &(), LIMIT)?
129-
.data;
130-
131-
assert_eq!(counter, 0xfc);
132-
133-
Ok(())
134-
}
135-
13690
/// Proves that we know a number `c` such that `a + b = c`.
13791
#[derive(Default)]
13892
struct TestCircuit {

0 commit comments

Comments
 (0)