Skip to content

Commit

Permalink
Prepare for rkyv::access (#1753)
Browse files Browse the repository at this point in the history
We want to move from `rkyv::access_unchecked` to checked `rkyv::access`.

We are trying to make that work in
#1737, but it turns out to be
non-trivial.

Here's some prep work: introduce byte-check and derive Debug for a few
of our sdk types.
  • Loading branch information
matthiasgoergens authored May 30, 2024
1 parent f586e49 commit b3fe424
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 1 deletion.
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions sdk/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version = "0.2.0"
array-concat = { git = "https://github.com/Daniel-Aaron-Bloom/array-concat.git" }
array-util = "1.0.2"
once_cell = { version = "1.19", default-features = false, features = ["race"] }
rkyv = { version = "=0.8.0-alpha.1", default-features = false, features = ["pointer_width_32", "alloc"] }
rkyv = { version = "=0.8.0-alpha.1", default-features = false, features = ["pointer_width_32", "alloc", "bytecheck"] }
rkyv_derive = "=0.8.0-alpha.1"
vec-entries = "1.0"

Expand Down
2 changes: 2 additions & 0 deletions sdk/src/common/types/cross_program_call.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#[derive(
Default, Clone, Hash, PartialEq, PartialOrd, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize,
)]
#[archive(check_bytes)]
#[cfg_attr(
not(target_os = "mozakvm"),
derive(Debug, serde::Serialize, serde::Deserialize)
)]
#[archive_attr(derive(Debug))]
#[allow(clippy::pub_underscore_fields)]
pub struct CrossProgramCall {
pub caller: super::ProgramIdentifier,
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/common/types/poseidon2hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ use crate::core::constants::DIGEST_BYTES;
rkyv::Deserialize,
rkyv::Serialize,
)]
#[archive(check_bytes)]
#[cfg_attr(
not(target_os = "mozakvm"),
derive(serde::Serialize, serde::Deserialize)
)]
#[archive_attr(derive(Debug))]
pub struct Poseidon2Hash(
#[cfg_attr(not(target_os = "mozakvm"), serde(with = "SerHex::<StrictPfx>"))]
pub [u8; DIGEST_BYTES],
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/common/types/program_identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ use crate::core::constants::DIGEST_BYTES;
rkyv::Deserialize,
rkyv::Serialize,
)]
#[archive(check_bytes)]
#[cfg_attr(
not(target_os = "mozakvm"),
derive(serde::Serialize, serde::Deserialize)
)]
#[archive_attr(derive(Debug))]
pub struct ProgramIdentifier(pub super::Poseidon2Hash);

impl ProgramIdentifier {
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/common/types/raw_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ use serde_hex::{SerHexSeq, StrictPfx};
#[derive(
Default, Clone, Hash, PartialEq, PartialOrd, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize,
)]
#[archive(check_bytes)]
#[cfg_attr(
not(target_os = "mozakvm"),
derive(serde::Serialize, serde::Deserialize)
)]
#[archive_attr(derive(Debug))]
pub struct RawMessage(
#[cfg_attr(not(target_os = "mozakvm"), serde(with = "SerHexSeq::<StrictPfx>"))] pub Vec<u8>,
);
Expand Down

0 comments on commit b3fe424

Please sign in to comment.