Skip to content

Commit

Permalink
Merge branch 'master' into add-addr-guards
Browse files Browse the repository at this point in the history
  • Loading branch information
prasannavl authored Jul 27, 2023
2 parents 844e613 + 5f00e62 commit 7f8abbe
Show file tree
Hide file tree
Showing 52 changed files with 1,127 additions and 873 deletions.
45 changes: 38 additions & 7 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1371,21 +1371,30 @@ AC_SUBST(HAVE_O_CLOEXEC)
AC_SUBST(HAVE_BUILTIN_PREFETCH)
AC_SUBST(HAVE_MM_PREFETCH)
AC_SUBST(HAVE_STRONG_GETAUXVAL)

AC_SUBST(BUILD_CC)
AC_SUBST(BUILD_CXX)
AC_SUBST(BUILD_AR)
AC_SUBST(BUILD_NM)
AC_SUBST(BUILD_RANLIB)

AC_SUBST(PROTOC)
AC_SUBST(PROTOC_INCLUDE_DIR)
AC_SUBST(SOLC_PATH)

dnl If the host and build triplets are the same, we keep this empty
RUST_HOST=`$ac_abs_confdir/make.sh get_rust_triplet "$build"`
if test $? != 0; then
AC_MSG_ERROR("unsupported build system")
if test "x$?" != "x0"; then
AC_MSG_ERROR("unsupported build system")
fi

dnl If the host and build triplets are the same, we keep this empty
RUST_TARGET=`$ac_abs_confdir/make.sh get_rust_triplet "$host"`
if test $? != 0; then
AC_MSG_ERROR("unsupported host target")
if test "x$?" != "x0"; then
AC_MSG_ERROR("unsupported target system")
fi

if test x$RUST_HOST = x$RUST_TARGET; then
if test "x$RUST_HOST" = "x$RUST_TARGET"; then
RUST_TARGET=
RUST_HOST=
fi
Expand Down Expand Up @@ -1455,7 +1464,8 @@ case ${OS} in
esac

echo
echo "Options used to compile and link:"
echo " === options === "
echo
echo " with wallet = $enable_wallet"
echo " with zmq = $use_zmq"
echo " with test = $use_tests"
Expand All @@ -1474,15 +1484,36 @@ echo
echo " target os = $TARGET_OS"
echo " build os = $BUILD_OS"
echo
echo " === target os toolchain ==== "
echo
echo " CC = $CC"
echo " CFLAGS = $CFLAGS"
echo " CPPFLAGS = $DEBUG_CPPFLAGS $HARDENED_CPPFLAGS $CPPFLAGS"
echo " CXX = $CXX"
echo " CXXFLAGS = $DEBUG_CXXFLAGS $HARDENED_CXXFLAGS $WARN_CXXFLAGS $NOWARN_CXXFLAGS $ERROR_CXXFLAGS $GPROF_CXXFLAGS $CXXFLAGS"
echo " LDFLAGS = $PTHREAD_CFLAGS $HARDENED_LDFLAGS $GPROF_LDFLAGS $LDFLAGS"
echo " AR = $AR"
echo " ARFLAGS = $ARFLAGS"
echo " NM = $NM"
echo " RANLIB = $RANLIB"
echo
echo " === build os toolchain ==== "
echo
echo " CC = $BUILD_CC"
echo " CXX = $BUILD_CXX"
echo " AR = $BUILD_AR"
echo " NM = $BUILD_NM"
echo " RANLIB = $BUILD_RANLIB"
echo
echo " === mixed toolchain ==="
echo
echo " CARGO = $CARGO"
echo " RUST_HOST = $RUST_HOST"
echo " RUST_TARGET = $RUST_TARGET"
echo " ENABLE_DEBUG = $ENABLE_DEBUG"
echo
echo " PROTOC = $PROTOC"
echo " PROTOC_INCLUDE_DIR = $PROTOC_INCLUDE_DIR"
echo " SOLC_PATH = $SOLC_PATH"
echo
echo " ==="
echo
5 changes: 5 additions & 0 deletions depends/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ $(host_prefix)/.stamp_$(final_build_id): $(native_packages) $(packages)
$(host_prefix)/share/config.site : config.site.in $(host_prefix)/.stamp_$(final_build_id)
$(AT)@mkdir -p $(@D)
$(AT)sed -e 's|@HOST@|$(host)|' \
-e 's|@BUILD_CC@|$(build_CC)|' \
-e 's|@BUILD_CXX@|$(build_CXX)|' \
-e 's|@BUILD_AR@|$(build_AR)|' \
-e 's|@BUILD_RANLIB@|$(build_RANLIB)|' \
-e 's|@BUILD_NM@|$(build_NM)|' \
-e 's|@CC@|$(toolchain_path)$(host_CC)|' \
-e 's|@CXX@|$(toolchain_path)$(host_CXX)|' \
-e 's|@AR@|$(toolchain_path)$(host_AR)|' \
Expand Down
16 changes: 14 additions & 2 deletions depends/config.site.in
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,17 @@ if test -n "@LDFLAGS@"; then
LDFLAGS="@LDFLAGS@ $LDFLAGS"
fi

export PROTOC=${depends_prefix}/bin/protoc
export PROTOC_INCLUDE_DIR=${depends_prefix}/include
# Build system compilers
# Everything that's overwritten above, we make sure to preserve
# the native items so it can be used for the rest of the workflow
BUILD_CC="@BUILD_CC@"
BUILD_CXX="@BUILD_CXX@"
BUILD_AR="@BUILD_AR@"
BUILD_RANLIB="@BUILD_RANLIB@"
BUILD_NM="@BUILD_NM@"

# External deps
SOLC_PATH=${depends_prefix}/bin/solc
PROTOC=${depends_prefix}/bin/protoc
PROTOC_INCLUDE_DIR=${depends_prefix}/include

8 changes: 3 additions & 5 deletions depends/hosts/darwin.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ DARWIN_SHAREDCC_FLAGS=-target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --

# There are some blockers to cleanly using just the flags and not
# overriding the CC/CXX with flags above, due to how depends system
# has been built on Bitoin. For now, we follow the BTC way
# until we can resolve the specific blockers, however we also
# add them to the flags, so downstream nested compilations can
# use them properly.
# has been built on Bitcoin. For now, we follow the BTC way
# until we can resolve the specific blockers
darwin_CC=clang $(DARWIN_SHAREDCC_FLAGS)
darwin_CXX=clang++ -stdlib=libc++ -std=c++17 $(DARWIN_SHAREDCC_FLAGS)

darwin_CFLAGS=-pipe $(DARWIN_SHAREDCC_FLAGS)
darwin_CFLAGS=-pipe
darwin_CXXFLAGS=$(darwin_CFLAGS) -stdlib=libc++ -std=c++17

darwin_release_CFLAGS=-O2
Expand Down
2 changes: 1 addition & 1 deletion depends/packages/packages.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
packages := boost libevent protobuf
packages := boost libevent protobuf solc

rapidcheck_packages = rapidcheck
wallet_packages = bdb
Expand Down
40 changes: 40 additions & 0 deletions depends/packages/solc.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package=solc
$(package)_version=0.8.20
$(package)_download_path=https://github.com/ethereum/solidity/releases/download/v$($(package)_version)/

# NOTE: solc gets invoked on the BUILD OS during compile. So, we don't
# care about HOST OS, unlike all other dependencies.
# That is: solc is run on the BUILD OS, not targeted to run on the
# HOST OS.

ifeq ($(build_os)-$(build_arch),linux-x86_64)
$(package)_file_name=solc-static-linux
$(package)_sha256_hash=0479d44fdf9c501c25337fdc540419f1593b884a87b47f023da4f1c700fda782
endif

# Note: solc only provides binaries for darwin amd64, however since rosetta is
# expected to be present, this should work through emulation without additional config.
ifeq ($(build_os),darwin)
$(package)_file_name=solc-macos
$(package)_sha256_hash=fc329945e0068e4e955d0a7b583776dc8d25e72ab657a044618a7ce7dd0519aa
endif

ifeq ($($(package)_file_name),)
$(error Unsupported build platform: $(BUILD))
endif

define $(package)_extract_cmds
mkdir -p $$($(package)_extract_dir) && \
echo "$$($(package)_sha256_hash) $$($(package)_source)" > $$($(package)_extract_dir)/.$$($(package)_file_name).hash && \
$(build_SHA256SUM) -c $$($(package)_extract_dir)/.$$($(package)_file_name).hash
endef

define $(package)_set_vars
$(package)_ROOT="$($(package)_staging_dir)/$(host_prefix)/bin"
endef

define $(package)_build_cmds
mkdir -p $($(package)_ROOT) && \
cp $($(package)_source) $($(package)_ROOT)/$(package) && \
chmod +x $($(package)_ROOT)/$(package)
endef
27 changes: 16 additions & 11 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,29 @@ BUILD_ARTIFACTS_DIR = $(CARGO_TARGET_DIR)/$(TARGET)/$(if $(DEBUG),debug,release)
CARGO_MANIFEST_ARG = --manifest-path "$(CARGO_MANIFEST_PATH)"
CARGO_BUILD_TYPE_ARG = $(if $(DEBUG),,--release)

# If $build == $host, we add --all-targets otherwise we skip
# since compiling with `--test` fails on cross compilation

# We add --all-targets only on native build, i.e $build == $host
# otherwise things like `--test` cannot run
CARGO_EXTRA_ARGS ?= $(if $(subst $(build),,$(host)),,--all-targets)

# Export compiler flags
export CC CXX CFLAGS CXXFLAGS CPPFLAGS LDFLAGS AR NM RANLIB
# Set the native compilers
# Export toolchain flags
export CC CXX AR NM RANLIB CFLAGS CXXFLAGS
# Not exported as these will break nested assumptions
# CPPFLAGS LDFLAGS ARFLAGS

# Set the native toolchain flags
if HAVE_RUST_HOST
export CC_$(RUST_HOST)=gcc
export CXX_$(RUST_HOST)=g++
export CFLAGS_$(RUST_HOST)=
export CXXFLAGS_$(RUST_HOST)=
export CC_$(RUST_HOST)=$(BUILD_CC)
export CXX_$(RUST_HOST)=$(BUILD_CXX)
export AR_$(RUST_HOST)=$(BUILD_AR)
export NM_$(RUST_HOST)=$(BUILD_NM)
export RANLIB_$(RUST_HOST)=$(BUILD_RANLIB)
endif

# Export compiler support
export PKG_CONFIG_PATH PKGCONFIG_LIBDIR PYTHONPATH
# Export protoc vars
export PROTOC PROTOC_INCLUDE_DIR
# Export other dep vars
export PROTOC PROTOC_INCLUDE_DIR SOLC_PATH

# Ensure nested autotools calls by cargo don't end up in unexpected places
unexport DESTDIR
Expand Down
1 change: 1 addition & 0 deletions lib/ain-cpp-imports/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod ffi {
fn pastChangiIntermediateHeight2() -> bool;
fn pastChangiIntermediateHeight3() -> bool;
fn pastChangiIntermediateHeight4() -> bool;
fn pastChangiIntermediateHeight5() -> bool;
fn CppLogPrintf(message: String);
}
}
7 changes: 7 additions & 0 deletions lib/ain-cpp-imports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ mod ffi {
pub fn pastChangiIntermediateHeight4() -> bool {
unimplemented!("{}", UNIMPL_MSG)
}
pub fn pastChangiIntermediateHeight5() -> bool {
unimplemented!("{}", UNIMPL_MSG)
}

pub fn CppLogPrintf(_message: String) {
// Intentionally left empty, so it can be used from everywhere.
Expand Down Expand Up @@ -156,6 +159,10 @@ pub fn past_changi_intermediate_height_4_height() -> bool {
ffi::pastChangiIntermediateHeight4()
}

pub fn past_changi_intermediate_height_5_height() -> bool {
ffi::pastChangiIntermediateHeight5()
}

pub fn log_print(message: &str) {
// TODO: Switch to u8 to avoid intermediate string conversions
ffi::CppLogPrintf(message.to_owned());
Expand Down
17 changes: 11 additions & 6 deletions lib/ain-evm/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,14 @@ impl EVMCoreService {
return Err(anyhow!("insufficient balance to pay fees").into());
}

// Validate tx gas limit with intrinsic gas
check_tx_intrinsic_gas(&signed_tx)?;
} else if balance < MIN_GAS_PER_TX.into() || balance < prepay_fee {
if ain_cpp_imports::past_changi_intermediate_height_5_height() {
// Validate tx gas limit with intrinsic gas
check_tx_intrinsic_gas(&signed_tx)?;
} else if gas_limit < MIN_GAS_PER_TX {
debug!("[validate_raw_tx] gas limit is below the minimum gas per tx");
return Err(anyhow!("gas limit is below the minimum gas per tx").into());
}
} else if balance < MIN_GAS_PER_TX || balance < prepay_fee {
debug!("[validate_raw_tx] insufficient balance to pay fees");
return Err(anyhow!("insufficient balance to pay fees").into());
}
Expand Down Expand Up @@ -259,7 +264,7 @@ impl EVMCoreService {
.get_total_gas_used(queue_id)
.unwrap_or_default();

if U256::from(total_current_gas_used + used_gas) > MAX_GAS_PER_BLOCK {
if total_current_gas_used + U256::from(used_gas) > MAX_GAS_PER_BLOCK {
return Err(anyhow!("Block size limit is more than MAX_GAS_PER_BLOCK").into());
}
}
Expand Down Expand Up @@ -292,7 +297,7 @@ impl EVMCoreService {
) -> Result<(), EVMError> {
let queue_tx = QueueTx::BridgeTx(BridgeTx::EvmIn(BalanceUpdate { address, amount }));
self.tx_queues
.queue_tx(queue_id, queue_tx, hash, 0u64, U256::zero())?;
.queue_tx(queue_id, queue_tx, hash, U256::zero(), U256::zero())?;
Ok(())
}

Expand All @@ -318,7 +323,7 @@ impl EVMCoreService {
} else {
let queue_tx = QueueTx::BridgeTx(BridgeTx::EvmOut(BalanceUpdate { address, amount }));
self.tx_queues
.queue_tx(queue_id, queue_tx, hash, 0u64, U256::zero())?;
.queue_tx(queue_id, queue_tx, hash, U256::zero(), U256::zero())?;
Ok(())
}
}
Expand Down
26 changes: 14 additions & 12 deletions lib/ain-evm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,20 @@ impl EVMServices {
total_priority_fees
);

match self.core.tx_queues.get_total_fees(queue_id) {
Some(total_fees) => {
if (total_burnt_fees + total_priority_fees) != U256::from(total_fees) {
return Err(anyhow!("EVM block rejected because block total fees != (burnt fees + priority fees). Burnt fees: {}, priority fees: {}, total fees: {}", total_burnt_fees, total_priority_fees, total_fees).into());
if ain_cpp_imports::past_changi_intermediate_height_5_height() {
match self.core.tx_queues.get_total_fees(queue_id) {
Some(total_fees) => {
if (total_burnt_fees + total_priority_fees) != total_fees {
return Err(anyhow!("EVM block rejected because block total fees != (burnt fees + priority fees). Burnt fees: {}, priority fees: {}, total fees: {}", total_burnt_fees, total_priority_fees, total_fees).into());
}
}
None => {
return Err(anyhow!(
"EVM block rejected because failed to get total fees from queue_id: {}",
queue_id
)
.into())
}
}
None => {
return Err(anyhow!(
"EVM block rejected because failed to get total fees from queue_id: {}",
queue_id
)
.into())
}
}

Expand Down Expand Up @@ -335,7 +337,7 @@ impl EVMServices {
queue_id: u64,
tx: QueueTx,
hash: NativeTxHash,
gas_used: u64,
gas_used: U256,
) -> Result<(), EVMError> {
let parent_data = self.block.get_latest_block_hash_and_number();
let parent_hash = match parent_data {
Expand Down
3 changes: 2 additions & 1 deletion lib/ain-evm/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use evm::{
};

use anyhow::anyhow;
use ethereum_types::U256;
use log::debug;
use std::error::Error;

// Changi intermediate constant
pub const MIN_GAS_PER_TX: u64 = 21_000;
pub const MIN_GAS_PER_TX: U256 = U256([21_000, 0, 0, 0]);

fn get_tx_cost(signed_tx: &SignedTx) -> TransactionCost {
let access_list = signed_tx
Expand Down
4 changes: 2 additions & 2 deletions lib/ain-evm/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ impl SignedTx {

pub fn max_fee_per_gas(&self) -> Option<U256> {
match &self.transaction {
TransactionV2::Legacy(tx) => Some(tx.gas_price),
TransactionV2::EIP2930(tx) => Some(tx.gas_price),
TransactionV2::Legacy(_) => None,
TransactionV2::EIP2930(_) => None,
TransactionV2::EIP1559(tx) => Some(tx.max_fee_per_gas),
}
}
Expand Down
Loading

0 comments on commit 7f8abbe

Please sign in to comment.