Skip to content

Commit

Permalink
piecrust-uplink: support bytecheck integrity check of arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed Feb 13, 2024
1 parent a3a669f commit 2619a2e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions piecrust-uplink/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Change `wrap_call` function to support `bytecheck`-based integrity check of arguments [#324]

## [0.10.0] - 2024-01-24

### Added
Expand Down Expand Up @@ -152,6 +156,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- First `piecrust-uplink` release

<!-- ISSUES -->
[#324]: https://github.com/dusk-network/piecrust/issues/324
[#301]: https://github.com/dusk-network/piecrust/issues/301
[#271]: https://github.com/dusk-network/piecrust/issues/271
[#268]: https://github.com/dusk-network/piecrust/issues/268
Expand Down
2 changes: 1 addition & 1 deletion piecrust-uplink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2021"
license = "MPL-2.0"

[dependencies]
rkyv = { version = "0.7", default-features = false, features = ["size_32", "alloc"] }
rkyv = { version = "0.7", default-features = false, features = ["size_32", "alloc", "validation"] }
bytecheck = { version = "0.6", default-features = false }
dlmalloc = { version = "0.2", optional = true, features = ["global"] }

Expand Down
9 changes: 6 additions & 3 deletions piecrust-uplink/src/abi/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use rkyv::ser::serializers::{
BufferScratch, BufferSerializer, CompositeSerializer,
};
use rkyv::ser::Serializer;
use rkyv::{archived_root, Archive, Deserialize, Infallible, Serialize};
use rkyv::validation::validators::DefaultValidator;
use rkyv::{check_archived_root, Archive, Deserialize, Infallible, Serialize};

use crate::types::StandardBufSerializer;

Expand All @@ -21,14 +22,16 @@ use crate::types::StandardBufSerializer;
pub fn wrap_call<A, R, F>(arg_len: u32, f: F) -> u32
where
A: Archive,
A::Archived: Deserialize<A, Infallible>,
A::Archived: Deserialize<A, Infallible>
+ for<'b> bytecheck::CheckBytes<DefaultValidator<'b>>,
R: for<'a> Serialize<StandardBufSerializer<'a>>,
F: Fn(A) -> R,
{
with_arg_buf(|buf| {
let slice = &buf[..arg_len as usize];

let aa: &A::Archived = unsafe { archived_root::<A>(slice) };
let aa: &A::Archived = check_archived_root::<A>(slice)
.expect("Argument should correctly deserialize");
let a: A = aa.deserialize(&mut Infallible).unwrap();

let ret = f(a);
Expand Down

0 comments on commit 2619a2e

Please sign in to comment.