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

chore: bump borsh to 1.3.0 and remove borsh-compat feature #907

Merged
merged 3 commits into from
Feb 26, 2024
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
1,166 changes: 320 additions & 846 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 8 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ anyhow = "1"
base64 = { version = "0.21", default-features = false, features = ["alloc"] }
bitflags = { version = "1", default-features = false }
bn = { version = "0.5", package = "zeropool-bn", default-features = false }
borsh = { version = "0.10", default-features = false }
borsh-compat = { version = "0.9", package = "borsh", default-features = false }
borsh = { version = "1", default-features = false, features = ["derive"] }
bs58 = { version = "0.5", default-features = false, features = ["alloc", "sha2"] }
bstr = "1"
byte-slice-cast = { version = "1", default-features = false }
Expand All @@ -36,22 +35,22 @@ evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.39.1"
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.39.1", default-features = false, features = ["std"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.39.1", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.39.1", default-features = false, features = ["std", "tracing"] }
fixed-hash = { version = "0.8.0", default-features = false}
function_name = "0.3.0"
fixed-hash = { version = "0.8", default-features = false }
function_name = "0.3"
git2 = "0.18"
hex = { version = "0.4", default-features = false, features = ["alloc"] }
ibig = { version = "0.3", default-features = false, features = ["num-traits"] }
impl-serde = { version = "0.4", default-features = false}
impl-serde = { version = "0.4", default-features = false }
lazy_static = "1"
libsecp256k1 = { version = "0.7", default-features = false }
near-crypto = "0.20"
near-gas = "0.2"
near-parameters = "0.20"
near-primitives = "0.20"
near-primitives-core = "0.20"
near-sdk = "4"
near-vm-runner = { version = "0.20", features = [ "wasmtime_vm", "wasmer2_vm" ] }
near-workspaces = "0.9"
near-sdk = "5"
near-vm-runner = { version = "0.20", features = ["wasmtime_vm", "wasmer2_vm"] }
near-workspaces = "0.10"
num = { version = "0.4", default-features = false, features = ["alloc"] }
postgres = "0.19"
primitive-types = { version = "0.12", default-features = false, features = ["rlp", "serde_no_std"] }
Expand All @@ -64,16 +63,13 @@ serde = { version = "1", default-features = false, features = ["alloc", "derive"
serde_json = { version = "1", default-features = false, features = ["alloc"] }
sha2 = { version = "0.10", default-features = false }
sha3 = { version = "0.10", default-features = false }
strum = { version = "0.25", features = ["derive"] }
strum = { version = "0.26", features = ["derive"] }
tempfile = "3"
tokio = { version = "1", default-features = false, features = ["macros"] }
test-case = "3.1"
walrus = "0.20"
wee_alloc = { version = "0.4", default-features = false }

[patch.crates-io]
parity-secp256k1 = { git = 'https://github.com/paritytech/rust-secp256k1', rev = "d05fd8e" }

[workspace]
resolver = "2"
members = [
Expand Down
17 changes: 0 additions & 17 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,29 +135,12 @@ args = [
"clippy::as_conversions",
]

[tasks.clippy-borsh-compat]
extend = "clippy-base"
args = [
"clippy",
"-p",
"aurora-engine-types",
"--all-targets",
"--features",
"borsh-compat",
"--",
"-D",
"warnings",
"-D",
"clippy::as_conversions",
]

[tasks.clippy]
dependencies = [
"clippy-base",
"clippy-ext-connector",
"clippy-contract",
"clippy-contract-refund",
"clippy-borsh-compat",
]

[tasks.check-fmt]
Expand Down
1 change: 0 additions & 1 deletion engine-hashchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ impl-serde.workspace = true
[features]
default = ["std"]
std = ["aurora-engine-types/std", "aurora-engine-sdk/std", "fixed-hash/std", "impl-serde/std"]
borsh-compat = ["aurora-engine-types/borsh-compat", "aurora-engine-sdk/borsh-compat"]
3 changes: 2 additions & 1 deletion engine-hashchain/src/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![allow(clippy::expl_impl_clone_on_copy, clippy::non_canonical_clone_impl)]

use aurora_engine_sdk::keccak;
use aurora_engine_types::borsh::{self, BorshDeserialize, BorshSerialize};
use aurora_engine_types::borsh::{BorshDeserialize, BorshSerialize};
use aurora_engine_types::parameters::engine::ResultLog;
use fixed_hash::construct_fixed_hash;
use impl_serde::impl_fixed_hash_serde;
Expand All @@ -16,6 +16,7 @@ const BLOOM_BITS: u32 = 3;
construct_fixed_hash! {
/// Bloom hash type with 256 bytes (2048 bits) size.
#[derive(BorshSerialize, BorshDeserialize)]
#[borsh(crate = "aurora_engine_types::borsh")]
pub struct Bloom(BLOOM_SIZE);
}

Expand Down
6 changes: 4 additions & 2 deletions engine-hashchain/src/hashchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{bloom::Bloom, error::BlockchainHashchainError, merkle::StreamCompact
use aurora_engine_sdk::keccak;
use aurora_engine_types::{
account_id::AccountId,
borsh::{self, maybestd::io, BorshDeserialize, BorshSerialize},
borsh::{self, io, BorshDeserialize, BorshSerialize},
format,
types::RawH256,
Cow, Vec,
Expand Down Expand Up @@ -107,7 +107,7 @@ impl Hashchain {

pub fn try_serialize(&self) -> Result<Vec<u8>, io::Error> {
let serializable: BorshableHashchain = self.into();
serializable.try_to_vec()
borsh::to_vec(&serializable)
}

pub fn try_deserialize(bytes: &[u8]) -> Result<Self, io::Error> {
Expand Down Expand Up @@ -168,6 +168,7 @@ impl HashchainBuilder {
/// is not bogged down with details of serialization (for example this data type is an enum
/// to allow for easy changes to the serialized form in the future).
#[derive(Debug, BorshDeserialize, BorshSerialize)]
#[borsh(crate = "aurora_engine_types::borsh")]
enum BorshableHashchain<'a> {
V1 {
chain_id: Cow<'a, [u8; 32]>,
Expand Down Expand Up @@ -221,6 +222,7 @@ impl<'a> TryFrom<BorshableHashchain<'a>> for Hashchain {
/// 4. Clear the transactions of the current block.
/// 5. Go back to step 2 for the next block.
#[derive(BorshSerialize, BorshDeserialize, Debug, Clone, PartialEq, Eq)]
#[borsh(crate = "aurora_engine_types::borsh")]
struct BlockHashchainComputer {
pub txs_logs_bloom: Bloom,
pub txs_merkle_tree: StreamCompactMerkleTree,
Expand Down
4 changes: 3 additions & 1 deletion engine-hashchain/src/merkle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use aurora_engine_sdk::keccak;
use aurora_engine_types::{
borsh::{self, BorshDeserialize, BorshSerialize},
borsh::{BorshDeserialize, BorshSerialize},
types::RawH256,
Vec,
};
Expand All @@ -10,6 +10,7 @@ use aurora_engine_types::{
/// Internally, compacts full binary subtrees maintaining only the growing branch.
/// Space used is O(log n) where n is the number of leaf hashes added. It is usually less.
#[derive(BorshSerialize, BorshDeserialize, Debug, Clone, PartialEq, Eq)]
#[borsh(crate = "aurora_engine_types::borsh")]
pub struct StreamCompactMerkleTree {
/// Complete binary merkle subtrees.
/// Left subtrees are strictly higher (bigger).
Expand Down Expand Up @@ -121,6 +122,7 @@ impl Default for StreamCompactMerkleTree {
/// For leaves, this represents only the leaf node with height 1 and the hash of the leaf.
/// For bigger subtrees, this represents the entire balanced subtree with its height and merkle hash.
#[derive(BorshSerialize, BorshDeserialize, Debug, Clone, PartialEq, Eq)]
#[borsh(crate = "aurora_engine_types::borsh")]
struct CompactMerkleSubtree {
/// Height of the subtree.
pub height: u8,
Expand Down
1 change: 0 additions & 1 deletion engine-precompiles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ serde_json.workspace = true
[features]
default = ["std"]
std = ["aurora-engine-types/std", "aurora-engine-sdk/std", "bn/std", "evm/std", "libsecp256k1/std", "ripemd/std", "sha2/std", "sha3/std", "ethabi/std"]
borsh-compat = ["aurora-engine-types/borsh-compat", "aurora-engine-sdk/borsh-compat"]
contract = ["aurora-engine-sdk/contract"]
log = []
error_refund = []
Expand Down
22 changes: 11 additions & 11 deletions engine-precompiles/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::prelude::{
storage::{bytes_to_key, KeyPrefix},
str,
types::{Address, Yocto},
vec, BorshSerialize, Cow, ToString, Vec, U256,
vec, Cow, ToString, Vec, U256,
};
#[cfg(feature = "error_refund")]
use crate::prelude::{parameters::RefundCallArgs, types};
Expand All @@ -18,6 +18,7 @@ use aurora_engine_types::parameters::WithdrawCallArgs;
use aurora_engine_types::storage::EthConnectorStorageId;
use aurora_engine_types::{
account_id::AccountId,
borsh,
parameters::{
ExitToNearPrecompileCallbackCallArgs, PromiseWithCallbackArgs, TransferNearCallArgs,
},
Expand Down Expand Up @@ -494,7 +495,7 @@ impl<I: IO> Precompile for ExitToNear<I> {
callback: PromiseCreateArgs {
target_account_id: self.current_account_id.clone(),
method: "exit_to_near_precompile_callback".to_string(),
args: callback_args.try_to_vec().unwrap(),
args: borsh::to_vec(&callback_args).unwrap(),
attached_balance: Yocto::new(0),
attached_gas: costs::EXIT_TO_NEAR_CALLBACK_GAS,
},
Expand All @@ -503,7 +504,7 @@ impl<I: IO> Precompile for ExitToNear<I> {
let promise_log = Log {
address: exit_to_near::ADDRESS.raw(),
topics: Vec::new(),
data: promise.try_to_vec().unwrap(),
data: borsh::to_vec(&promise).unwrap(),
};
let exit_event_log = exit_event.encode();
let exit_event_log = Log {
Expand Down Expand Up @@ -690,7 +691,7 @@ impl<I: IO> Precompile for ExitToEthereum<I> {
attached_gas: costs::WITHDRAWAL_GAS,
};

let promise = PromiseArgs::Create(withdraw_promise).try_to_vec().unwrap();
let promise = borsh::to_vec(&PromiseArgs::Create(withdraw_promise)).unwrap();
let promise_log = Log {
address: exit_to_ethereum::ADDRESS.raw(),
topics: Vec::new(),
Expand Down Expand Up @@ -722,11 +723,10 @@ fn json_args(address: Address, amount: U256) -> Result<Vec<u8>, ExitError> {
}

fn borsh_args(address: Address, amount: U256) -> Result<Vec<u8>, ExitError> {
WithdrawCallArgs {
borsh::to_vec(&WithdrawCallArgs {
recipient_address: address,
amount: NEP141Wei::new(amount.as_u128()),
}
.try_to_vec()
})
.map_err(|_| ExitError::Other(Cow::from("ERR_BORSH_SERIALIZE")))
}

Expand Down Expand Up @@ -808,31 +808,31 @@ mod tests {
parse_recipient(b"test.near").unwrap(),
Recipient {
receiver_account_id: "test.near".parse().unwrap(),
message: None
message: None,
}
);

assert_eq!(
parse_recipient(b"test.near:unwrap").unwrap(),
Recipient {
receiver_account_id: "test.near".parse().unwrap(),
message: Some("unwrap")
message: Some("unwrap"),
}
);

assert_eq!(
parse_recipient(b"test.near:some_msg:with_extra_colon").unwrap(),
Recipient {
receiver_account_id: "test.near".parse().unwrap(),
message: Some("some_msg:with_extra_colon")
message: Some("some_msg:with_extra_colon"),
}
);

assert_eq!(
parse_recipient(b"test.near:").unwrap(),
Recipient {
receiver_account_id: "test.near".parse().unwrap(),
message: Some("")
message: Some(""),
}
);
}
Expand Down
1 change: 0 additions & 1 deletion engine-precompiles/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub use aurora_engine_sdk as sdk;
pub use aurora_engine_types::borsh::BorshSerialize;
pub use aurora_engine_types::parameters;
pub use aurora_engine_types::storage;
pub use aurora_engine_types::types;
Expand Down
5 changes: 2 additions & 3 deletions engine-precompiles/src/promise_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{EvmPrecompileResult, Precompile};
use crate::prelude::types::{make_address, Address, EthGas};
use crate::{utils, PrecompileOutput};
use aurora_engine_sdk::promise::ReadOnlyPromiseHandler;
use aurora_engine_types::{borsh::BorshSerialize, Cow, Vec};
use aurora_engine_types::{borsh, Cow, Vec};
use evm::{Context, ExitError};

/// `get_promise_results` precompile address
Expand Down Expand Up @@ -71,8 +71,7 @@ impl<H: ReadOnlyPromiseHandler> Precompile for PromiseResult<H> {
}
}

let bytes = results
.try_to_vec()
let bytes = borsh::to_vec(&results)
.map_err(|_| ExitError::Other(Cow::Borrowed("ERR_PROMISE_RESULT_SERIALIZATION")))?;
Ok(PrecompileOutput::without_logs(cost, bytes))
}
Expand Down
17 changes: 7 additions & 10 deletions engine-precompiles/src/xcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{utils, HandleBasedPrecompile, PrecompileOutput};
use aurora_engine_sdk::io::IO;
use aurora_engine_types::{
account_id::AccountId,
borsh::{BorshDeserialize, BorshSerialize},
borsh::{self, BorshDeserialize},
format,
parameters::{CrossContractCallArgs, PromiseCreateArgs},
types::{balance::ZERO_YOCTO, Address, EthGas, NearGas},
Expand Down Expand Up @@ -147,8 +147,7 @@ impl<I: IO> HandleBasedPrecompile for CrossContractCall<I> {
let promise = PromiseCreateArgs {
target_account_id,
method: consts::ROUTER_EXEC_NAME.into(),
args: call
.try_to_vec()
args: borsh::to_vec(&call)
.map_err(|_| ExitError::Other(Cow::from(consts::ERR_SERIALIZE)))?,
attached_balance: ZERO_YOCTO,
attached_gas: router_exec_cost.saturating_add(call_gas),
Expand All @@ -160,8 +159,7 @@ impl<I: IO> HandleBasedPrecompile for CrossContractCall<I> {
let promise = PromiseCreateArgs {
target_account_id,
method: consts::ROUTER_SCHEDULE_NAME.into(),
args: call
.try_to_vec()
args: borsh::to_vec(&call)
.map_err(|_| ExitError::Other(Cow::from(consts::ERR_SERIALIZE)))?,
attached_balance: ZERO_YOCTO,
// We don't need to add any gas to the amount need for the schedule call
Expand Down Expand Up @@ -205,13 +203,13 @@ impl<I: IO> HandleBasedPrecompile for CrossContractCall<I> {
return Err(PrecompileFailure::Revert {
exit_status: r,
output: return_value,
})
});
}
evm::ExitReason::Error(e) => {
return Err(PrecompileFailure::Error { exit_status: e })
return Err(PrecompileFailure::Error { exit_status: e });
}
evm::ExitReason::Fatal(f) => {
return Err(PrecompileFailure::Fatal { exit_status: f })
return Err(PrecompileFailure::Fatal { exit_status: f });
}
};
}
Expand All @@ -226,8 +224,7 @@ impl<I: IO> HandleBasedPrecompile for CrossContractCall<I> {
let promise_log = Log {
address: cross_contract_call::ADDRESS.raw(),
topics,
data: promise
.try_to_vec()
data: borsh::to_vec(&promise)
.map_err(|_| ExitError::Other(Cow::from(consts::ERR_SERIALIZE)))?,
};

Expand Down
3 changes: 1 addition & 2 deletions engine-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ sha2.workspace = true
sha3.workspace = true

[features]
std = ["aurora-engine-types/std", "sha3/std", "sha2/std", "base64/std" ]
borsh-compat = ["aurora-engine-types/borsh-compat"]
std = ["aurora-engine-types/std", "sha3/std", "sha2/std", "base64/std"]
contract = []
log = []
all-promise-actions = []
Expand Down
4 changes: 2 additions & 2 deletions engine-sdk/src/io.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::error;
use crate::prelude::{vec, Vec};
use aurora_engine_types::borsh::{BorshDeserialize, BorshSerialize};
use aurora_engine_types::U256;
use aurora_engine_types::{borsh, U256};

/// The purpose of this trait is to represent a reference to a value that
/// could be obtained by IO, but without eagerly loading it into memory.
Expand Down Expand Up @@ -161,7 +161,7 @@ pub trait IO {
key: &[u8],
value: &T,
) -> Option<Self::StorageValue> {
let bytes = value.try_to_vec().ok()?;
let bytes = borsh::to_vec(&value).ok()?;
self.write_storage(key, &bytes)
}
}
1 change: 0 additions & 1 deletion engine-standalone-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ strum.workspace = true

[features]
default = ["snappy", "lz4", "zstd", "zlib"]
borsh-compat = ["aurora-engine-types/borsh-compat", "aurora-engine-sdk/borsh-compat", "aurora-engine-precompiles/borsh-compat", "aurora-engine/borsh-compat"]
mainnet = []
testnet = []
ext-connector = ["aurora-engine/ext-connector", "aurora-engine-precompiles/ext-connector"]
Expand Down
Loading
Loading