Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use bincode2 #74

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions 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 enclave-modules/host-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"

[dependencies]
sgx_types = { rev = "v1.1.6", git = "https://github.com/apache/incubator-teaclave-sgx-sdk" }
bincode = { git = "https://github.com/bluele/bincode-sgx", branch = "serde" }
bincode = { version = "2.0.0-rc.3", default-features = false, features = ["serde", "alloc"] }
flex-error = { version = "0.4.4", default-features = false }
ocall-commands = { path = "../../modules/ocall-commands", default-features = false }
store = { path = "../../modules/store", default-features = false }
10 changes: 7 additions & 3 deletions enclave-modules/host-api/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use ocall_commands::{Command, CommandResult};
use sgx_types::*;

pub fn execute_command(cmd: Command) -> Result<CommandResult, Error> {
let cmd_vec = bincode::serialize(&cmd).map_err(Error::bincode)?;
let cmd_vec = bincode::serde::encode_to_vec(&cmd, bincode::config::standard())
.map_err(Error::bincode_encode)?;
let mut ret: sgx_status_t = sgx_status_t::SGX_ERROR_UNEXPECTED;
let mut output_len = 0;
let output_maxlen = 65536;
Expand All @@ -29,8 +30,11 @@ pub fn execute_command(cmd: Command) -> Result<CommandResult, Error> {
unsafe {
output_buf.set_len(output_len as usize);
}
let res =
bincode::deserialize(&output_buf[..output_len as usize]).map_err(Error::bincode)?;
let res = bincode::serde::decode_borrowed_from_slice(
&output_buf[..output_len as usize],
bincode::config::standard(),
)
.map_err(Error::bincode_decode)?;
if ret == sgx_status_t::SGX_SUCCESS {
Ok(res)
} else if let CommandResult::CommandError(descr) = res {
Expand Down
9 changes: 6 additions & 3 deletions enclave-modules/host-api/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ define_error! {
|e| {
format_args!("Command error: status={:?} description={}", e.status, e.descr)
},
Bincode
[TraceError<bincode::Error>]
|_| { "bincode error" }
BincodeEncode
[TraceError<bincode::error::EncodeError>]
|_| { "bincode encode error" },
BincodeDecode
[TraceError<bincode::error::DecodeError>]
|_| { "bincode decode error" }
}
}
2 changes: 1 addition & 1 deletion enclave-modules/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
sgx_types = { rev = "v1.1.6", git = "https://github.com/apache/incubator-teaclave-sgx-sdk" }
sgx_tstd = { rev = "v1.1.6", git = "https://github.com/apache/incubator-teaclave-sgx-sdk" }
log = { version = "0.4.8", default-features = false }
bincode = { git = "https://github.com/bluele/bincode-sgx", branch = "serde" }
bincode = { version = "2.0.0-rc.3", default-features = false, features = ["serde", "alloc"] }
flex-error = { version = "0.4.4", default-features = false }
once_cell = { version = "1.15.0", default-features = false, features = ["alloc"] }

Expand Down
9 changes: 5 additions & 4 deletions enclave-modules/runtime/src/ecalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ pub fn ecall_execute_command(
sgx_status_t::SGX_ERROR_UNEXPECTED
);

let cmd: ECallCommand = match bincode::deserialize(unsafe {
alloc::slice::from_raw_parts(command, command_len as usize)
}) {
let cmd: ECallCommand = match bincode::serde::decode_borrowed_from_slice(
unsafe { alloc::slice::from_raw_parts(command, command_len as usize) },
bincode::config::standard(),
) {
Ok(cmd) => cmd,
Err(e) => {
error!("failed to bincode::deserialize: {:?}", e);
Expand All @@ -59,7 +60,7 @@ pub fn ecall_execute_command(
),
};

let res = match bincode::serialize(&result) {
let res = match bincode::serde::encode_to_vec(&result, bincode::config::standard()) {
Ok(res) => {
if res.len() > output_buf_maxlen as usize {
error!(
Expand Down
32 changes: 7 additions & 25 deletions enclave/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 modules/enclave-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
[dependencies]
sgx_types = { rev = "v1.1.6", git = "https://github.com/apache/incubator-teaclave-sgx-sdk" }
sgx_urts = { rev = "v1.1.6", git = "https://github.com/apache/incubator-teaclave-sgx-sdk" }
bincode = "1.3"
bincode = { version = "2.0.0-rc.3", default-features = false, features = ["serde", "alloc"] }
log = "0.4.8"
flex-error = { version = "0.4.4" }

Expand Down
10 changes: 7 additions & 3 deletions modules/enclave-api/src/api/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ fn raw_execute_command(eid: sgx_enclave_id_t, cmd: ECallCommand) -> Result<Comma
let output_ptr = output_buf.as_mut_ptr();
let mut ret = sgx_status_t::SGX_SUCCESS;

let command_bytes = bincode::serialize(&cmd).map_err(Error::bincode)?;
let command_bytes = bincode::serde::encode_to_vec(&cmd, bincode::config::standard())
.map_err(Error::bincode_encode)?;
let result = unsafe {
ffi::ecall_execute_command(
eid,
Expand All @@ -54,8 +55,11 @@ fn raw_execute_command(eid: sgx_enclave_id_t, cmd: ECallCommand) -> Result<Comma
unsafe {
output_buf.set_len(output_len as usize);
}
let res =
bincode::deserialize(&output_buf[..output_len as usize]).map_err(Error::bincode)?;
let res = bincode::serde::decode_borrowed_from_slice(
&output_buf[..output_len as usize],
bincode::config::standard(),
)
.map_err(Error::bincode_decode)?;

if ret == sgx_status_t::SGX_SUCCESS {
Ok(res)
Expand Down
10 changes: 7 additions & 3 deletions modules/enclave-api/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ define_error! {
format_args!("SGX error: {:?}", e.status)
},

Bincode
[TraceError<bincode::Error>]
|_| { "Bincode error" },
BincodeEncode
[TraceError<bincode::error::EncodeError>]
|_| { "bincode encode error" },

BincodeDecode
[TraceError<bincode::error::DecodeError>]
|_| { "bincode decode error" },

Command {
status: sgx_status_t,
Expand Down
2 changes: 1 addition & 1 deletion modules/host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sgx_urts = { rev = "v1.1.6", git = "https://github.com/apache/incubator-teaclave
sgx_types = { rev = "v1.1.6", git = "https://github.com/apache/incubator-teaclave-sgx-sdk" }
log = "0.4.8"
once_cell = "1.15.0"
bincode = "1.3"
bincode = { version = "2.0.0-rc.3", default-features = false, features = ["serde", "alloc"] }

ocall-commands = { path = "../ocall-commands" }
ocall-handler = { path = "../ocall-handler" }
Expand Down
21 changes: 11 additions & 10 deletions modules/host/src/ocalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ pub extern "C" fn ocall_execute_command(
return e;
}

let cmd: OCallCommand =
match bincode::deserialize(unsafe { slice::from_raw_parts(command, command_len as usize) })
{
Ok(cmd) => cmd,
Err(e) => {
error!("failed to bincode::deserialize: {:?}", e);
return sgx_status_t::SGX_ERROR_UNEXPECTED;
}
};
let cmd: OCallCommand = match bincode::serde::decode_borrowed_from_slice(
unsafe { slice::from_raw_parts(command, command_len as usize) },
bincode::config::standard(),
) {
Ok(cmd) => cmd,
Err(e) => {
error!("failed to bincode::deserialize: {:?}", e);
return sgx_status_t::SGX_ERROR_UNEXPECTED;
}
};

let (status, result) = match ocall_handler::dispatch(
HOST_ENVIRONMENT
Expand All @@ -60,7 +61,7 @@ pub extern "C" fn ocall_execute_command(
),
};

let res = match bincode::serialize(&result) {
let res = match bincode::serde::encode_to_vec(&result, bincode::config::standard()) {
Ok(res) => {
if res.len() > output_buf_maxlen as usize {
error!(
Expand Down
2 changes: 1 addition & 1 deletion modules/light-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
flex-error = { version = "0.4.4", default-features = false }
serde = { version = "1.0", default-features = false, features = ["alloc"] }
derive_more = { version = "0.99.0", default-features = false }
bincode = { version = "2.0.0-rc.2", default-features = false, features = ["serde", "alloc"] }
bincode = { version = "2.0.0-rc.3", default-features = false, features = ["serde", "alloc"] }
ibc = { version = "0.29.0", default-features = false, features = ["serde"], optional = true }
ibc-proto = { version = "0.26.0", default-features = false, features = ["parity-scale-codec", "borsh"], optional = true }

Expand Down
Loading