Skip to content

Commit

Permalink
Release 3.0.0 (#828)
Browse files Browse the repository at this point in the history
### Fixes

- Updated sputnikvm dependency with bugfix in the `returndatacopy`
implementation and a performance improvement in accessing EVM memory.
(#826)

### Changes

- BREAKING: `engine-standalone-storage` no longer automatically writes
to the DB when `consume_message` is called. It is up to downstream users
of the library to commit the diff (after doing any validation for
correctness). (#825)

### Additions

- New crate for the so-called "hashchain" implementation. It will enable
verification of Aurora blocks by light clients in the future. (#816)

---------

Co-authored-by: Oleksandr Anyshchenko <oleksandr.anyshchenko@aurora.dev>
  • Loading branch information
birchmd and aleksuss authored Aug 25, 2023
1 parent 17b6d69 commit 1a2e7c6
Show file tree
Hide file tree
Showing 19 changed files with 1,191 additions and 41 deletions.
19 changes: 19 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.0.0] 2023-08-28

### Fixes

- Updated sputnikvm dependency with bugfix in the `returndatacopy` implementation and a performance improvement in accessing EVM memory. [@birchmd] ([#826])

### Changes

- BREAKING: `engine-standalone-storage` no loonger automatically writes to the DB when `consume_message` is called. It is up to downstream users of the library to commit the diff (after doing any validation for correctness). [@birchmd] ([#825])

### Additions

- New crate for the so-called "hashchain" implementation. It will enable verification of Aurora blocks by light clients in the future. [@birchmd] ([#816])

[#816]: https://github.com/aurora-is-near/aurora-engine/pull/816
[#825]: https://github.com/aurora-is-near/aurora-engine/pull/825
[#826]: https://github.com/aurora-is-near/aurora-engine/pull/826

## [2.10.2] 2023-08-10

### Changes
Expand Down Expand Up @@ -465,6 +483,7 @@ struct SubmitResult {
## [1.0.0] - 2021-05-12

[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/2.10.2...develop
[3.0.0]: https://github.com/aurora-is-near/aurora-engine/compare/2.10.2...3.0.0
[2.10.2]: https://github.com/aurora-is-near/aurora-engine/compare/2.10.1...2.10.2
[2.10.1]: https://github.com/aurora-is-near/aurora-engine/compare/2.10.0...2.10.1
[2.10.0]: https://github.com/aurora-is-near/aurora-engine/compare/2.9.3...2.10.0
Expand Down
18 changes: 14 additions & 4 deletions Cargo.lock

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

11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ byte-slice-cast = { version = "1", default-features = false }
criterion = "0.5"
digest = "0.10"
ethabi = { version = "18", default-features = false }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.38.0-aurora", default-features = false }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.38.0-aurora", default-features = false, features = ["std"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.38.0-aurora", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.38.0-aurora", default-features = false, features = ["std", "tracing"] }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.38.3-aurora", default-features = false }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.38.3-aurora", default-features = false, features = ["std"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.38.3-aurora", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.38.3-aurora", default-features = false, features = ["std", "tracing"] }
fixed-hash = { version = "0.8.0", default-features = false}
git2 = "0.17"
hex = { version = "0.4", default-features = false, features = ["alloc"] }
ibig = { version = "0.3", default-features = false, features = ["num-traits"] }
impl-serde = { version = "0.4.0", default-features = false}
lazy_static = "1"
libsecp256k1 = { version = "0.7", default-features = false }
near-crypto = "0.17"
Expand Down Expand Up @@ -71,6 +73,7 @@ workspaces = "0.7"
resolver = "2"
members = [
"engine",
"engine-hashchain",
"engine-test-doubles",
"engine-modexp",
"engine-precompiles",
Expand Down
2 changes: 1 addition & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ args = [
"--release",
"--features",
"${CARGO_FEATURES_TEST}",
"bench_modexp_standalone",
"bench_m",
"--",
"--ignored",
]
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.10.2
3.0.0
22 changes: 22 additions & 0 deletions engine-hashchain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "aurora-engine-hashchain"
version = "1.0.0"
authors.workspace = true
edition.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
license.workspace = true
publish.workspace = true
autobenches = false

[dependencies]
aurora-engine-types.workspace = true
aurora-engine-sdk.workspace = true
fixed-hash.workspace = true
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"]
85 changes: 85 additions & 0 deletions engine-hashchain/src/bloom.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//! Based on Parity Common Eth Bloom implementation
//! Link: <https://github.com/paritytech/parity-common/blob/master/ethbloom/src/lib.rs>
//!
//! Reimplemented here since there is a large mismatch in types and dependencies.
#![allow(clippy::expl_impl_clone_on_copy)]

use aurora_engine_sdk::keccak;
use aurora_engine_types::borsh::{self, BorshDeserialize, BorshSerialize};
use aurora_engine_types::parameters::engine::ResultLog;
use fixed_hash::construct_fixed_hash;
use impl_serde::impl_fixed_hash_serde;

const BLOOM_SIZE: usize = 256;
const BLOOM_BITS: u32 = 3;

construct_fixed_hash! {
/// Bloom hash type with 256 bytes (2048 bits) size.
#[derive(BorshSerialize, BorshDeserialize)]
pub struct Bloom(BLOOM_SIZE);
}

impl_fixed_hash_serde!(Bloom, BLOOM_SIZE);

/// Returns log2.
const fn log2(x: usize) -> u32 {
if x <= 1 {
return 0;
}

let n = x.leading_zeros();
usize::BITS - n
}

impl Bloom {
/// Add a new element to the bloom filter
#[allow(clippy::as_conversions)]
pub fn accrue(&mut self, input: &[u8]) {
let m = self.0.len();
let bloom_bits = m * 8;
let mask = bloom_bits - 1;
let bloom_bytes = (log2(bloom_bits) + 7) / 8;
let hash = keccak(input);
let mut ptr = 0;

for _ in 0..BLOOM_BITS {
let mut index = 0;
for _ in 0..bloom_bytes {
index = (index << 8) | hash[ptr] as usize;
ptr += 1;
}
index &= mask;
self.0[m - 1 - index / 8] |= 1 << (index % 8);
}
}

/// Merge two bloom filters
pub fn accrue_bloom(&mut self, bloom: &Self) {
for i in 0..BLOOM_SIZE {
self.0[i] |= bloom.0[i];
}
}
}

#[must_use]
pub fn get_logs_bloom(logs: &[ResultLog]) -> Bloom {
let mut logs_bloom = Bloom::default();

for log in logs {
logs_bloom.accrue_bloom(&get_log_bloom(log));
}

logs_bloom
}

#[must_use]
pub fn get_log_bloom(log: &ResultLog) -> Bloom {
let mut log_bloom = Bloom::default();

log_bloom.accrue(log.address.as_bytes());
for topic in &log.topics {
log_bloom.accrue(&topic[..]);
}

log_bloom
}
33 changes: 33 additions & 0 deletions engine-hashchain/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
pub const ERR_STATE_NOT_FOUND: &[u8; 19] = b"ERR_STATE_NOT_FOUND";
pub const ERR_STATE_SERIALIZATION_FAILED: &[u8; 26] = b"ERR_STATE_SERIALIZE_FAILED";
pub const ERR_STATE_CORRUPTED: &[u8; 19] = b"ERR_STATE_CORRUPTED";
pub const ERR_BLOCK_HEIGHT_INCORRECT: &[u8; 26] = b"ERR_BLOCK_HEIGHT_INCORRECT";
pub const ERR_REQUIRES_FEATURE_INTEGRATION_TEST: &[u8; 37] =
b"ERR_REQUIRES_FEATURE_INTEGRATION_TEST";

#[derive(Debug)]
/// Blockchain Hashchain Error
pub enum BlockchainHashchainError {
/// The state is missing from storage, need to initialize with contract `new` method.
NotFound,
/// The state serialized had failed.
SerializationFailed,
/// The state is corrupted, possibly due to failed state migration.
DeserializationFailed,
/// The block height is incorrect regarding the current block height.
BlockHeightIncorrect,
/// Some functionality requires integration-test feature.
RequiresFeatureIntegrationTest,
}

impl AsRef<[u8]> for BlockchainHashchainError {
fn as_ref(&self) -> &[u8] {
match self {
Self::NotFound => ERR_STATE_NOT_FOUND,
Self::SerializationFailed => ERR_STATE_SERIALIZATION_FAILED,
Self::DeserializationFailed => ERR_STATE_CORRUPTED,
Self::BlockHeightIncorrect => ERR_BLOCK_HEIGHT_INCORRECT,
Self::RequiresFeatureIntegrationTest => ERR_REQUIRES_FEATURE_INTEGRATION_TEST,
}
}
}
Loading

0 comments on commit 1a2e7c6

Please sign in to comment.