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

Bug fixes for endianness between boundaries #2329

Merged
merged 65 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
74ab208
Bug fixes to little endianness on dvm
sieniven Aug 15, 2023
34086b0
Revert changes on encoding decoding tx dest
sieniven Aug 15, 2023
0e2e97b
Fix lint
sieniven Aug 15, 2023
9afcdfb
Add more key checks
prasannavl Aug 15, 2023
bf08250
Cleanup hashing, add wallet tests
prasannavl Aug 15, 2023
2cf455a
Enable migration
prasannavl Aug 15, 2023
57fa031
Fix lints
prasannavl Aug 15, 2023
8f78944
Merge branch 'master' into evm/fix-endianness
prasannavl Aug 15, 2023
3645c9d
Fixes to feature_evm_rpc test
sieniven Aug 15, 2023
d3b4811
Fix lint
sieniven Aug 15, 2023
f103f65
Merge branch 'pvl/cleanups-enable-migration' of github.com:DeFiCh/ain…
sieniven Aug 15, 2023
5a0e095
Merge branch 'master' of github.com:DeFiCh/ain into evm/fix-endianness
sieniven Aug 15, 2023
5cdc71c
Merge branch 'master' of github.com:DeFiCh/ain into evm/fix-endianness
sieniven Aug 15, 2023
2f21b88
Fixes to cross boundary ffi endianness
sieniven Aug 15, 2023
615f4d4
Fix lint
sieniven Aug 15, 2023
f05ba92
Fix evmtx rpc and rust ffi to pass uint64
sieniven Aug 16, 2023
02fb437
Fix lint
sieniven Aug 16, 2023
120fd7d
Fix lint
sieniven Aug 16, 2023
5eba9e2
Merge branch 'master' of github.com:DeFiCh/ain into evm/fix-endianness
sieniven Aug 16, 2023
48b9cbc
Merge branch 'master' into evm/fix-endianness
Jouzo Aug 16, 2023
a2e8b64
Merge branch 'evm/fix-endianness' of github.com:DeFiCh/ain into evm/f…
sieniven Aug 16, 2023
57fd2f1
Changes to pass hash as string between boundaries
sieniven Aug 16, 2023
875d86b
Fix lint
sieniven Aug 16, 2023
63eda40
Revert rpc test
sieniven Aug 16, 2023
37d6627
Switch to BE for nonce conversion
sieniven Aug 16, 2023
d760926
Fix passing lossy string
sieniven Aug 16, 2023
ebea6a7
Fix lint
sieniven Aug 16, 2023
db692d6
Fix prefix for vmmap
sieniven Aug 16, 2023
77b9ce5
Merge branch 'master' of github.com:DeFiCh/ain into evm/fix-endianness
sieniven Aug 16, 2023
5a945dd
Resolve merge conflict error
sieniven Aug 16, 2023
c6422f1
Fix merge error
sieniven Aug 16, 2023
6272340
Fix lint
sieniven Aug 16, 2023
e372604
Fix lint
sieniven Aug 16, 2023
c45ff30
Fix string prefixes
prasannavl Aug 16, 2023
9d497de
Fix vmmapping to remove hex prefix
sieniven Aug 16, 2023
234e732
Fix lint
sieniven Aug 16, 2023
b5e9bfd
Merge branch 'evm/fix-endianness' of github.com:DeFiCh/ain into evm/f…
sieniven Aug 16, 2023
38d71b8
Fix vmmap test
sieniven Aug 16, 2023
05775ef
Fix lint
sieniven Aug 16, 2023
6df0259
Revert change in vmmap
sieniven Aug 16, 2023
f65a20d
Fix format
sieniven Aug 16, 2023
2f59bdd
Merge branch 'master' of github.com:DeFiCh/ain into evm/fix-endianness
sieniven Aug 16, 2023
fc58f9f
Fix lint
sieniven Aug 16, 2023
a348021
Merge branch 'master' into evm/fix-endianness
prasannavl Aug 16, 2023
37ec93f
Fixes to getEthPrivKey cpp ffi
sieniven Aug 17, 2023
cb48ebe
Fix failing unit test due to passing gwei instead of wei to ffi
sieniven Aug 17, 2023
45bf15d
Add RPC helper for metric clarity
sieniven Aug 17, 2023
eb5f03d
Fixes to block hash in xvm struct and feature_evm_contract_env_vars test
sieniven Aug 17, 2023
8a315cd
Merge branch 'master' into evm/fix-endianness
sieniven Aug 17, 2023
365f2bd
Merge branch 'master' of github.com:DeFiCh/ain into evm/fix-endianness
sieniven Aug 18, 2023
c4a1479
Merge branch 'master' into evm/fix-endianness
prasannavl Aug 18, 2023
c9a8b7f
Add early return
prasannavl Aug 18, 2023
fdc63fa
Alias x boundary hash strings
prasannavl Aug 18, 2023
44dfb54
Add <0 checks
prasannavl Aug 18, 2023
3652402
Add safety note
prasannavl Aug 18, 2023
2068ff1
Reuse EvmAddressData
prasannavl Aug 18, 2023
dc9ff16
Fix rust alias for xhash
sieniven Aug 18, 2023
ff25f49
Fix lint
sieniven Aug 18, 2023
1a9c2e2
Add rust logs to testing, WIP key tests
prasannavl Aug 18, 2023
7dd8877
Add test
prasannavl Aug 18, 2023
bd32492
Cleanup
prasannavl Aug 18, 2023
74ad2e0
Test loop check
prasannavl Aug 18, 2023
3ef473c
Revert ecrecover changes
Jouzo Aug 18, 2023
d6fa4ed
Cleanup
prasannavl Aug 18, 2023
4ebf88b
Merge branch 'master' into evm/fix-endianness
prasannavl Aug 18, 2023
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
2 changes: 1 addition & 1 deletion lib/ain-cpp-imports/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub mod ffi {
fn getPoolTransactions() -> Vec<String>;
fn getNativeTxSize(data: Vec<u8>) -> u64;
fn getMinRelayTxFee() -> u64;
fn getEthPrivKey(key_id: [u8; 20]) -> [u8; 32];
fn getEthPrivKey(key: String) -> [u8; 32];
fn getStateInputJSON() -> String;
fn getHighestBlock() -> i32;
fn getCurrentHeight() -> i32;
Expand Down
6 changes: 3 additions & 3 deletions lib/ain-cpp-imports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mod ffi {
pub fn getMinRelayTxFee() -> u64 {
unimplemented!("{}", UNIMPL_MSG)
}
pub fn getEthPrivKey(_key_id: [u8; 20]) -> [u8; 32] {
pub fn getEthPrivKey(_key: String) -> [u8; 32] {
unimplemented!("{}", UNIMPL_MSG)
}
pub fn getStateInputJSON() -> String {
Expand Down Expand Up @@ -136,8 +136,8 @@ pub fn get_min_relay_tx_fee() -> Result<u64, Box<dyn Error>> {
Ok(tx_fee)
}

pub fn get_eth_priv_key(key_id: [u8; 20]) -> Result<[u8; 32], Box<dyn Error>> {
let eth_key = ffi::getEthPrivKey(key_id);
pub fn get_eth_priv_key(key: String) -> Result<[u8; 32], Box<dyn Error>> {
let eth_key = ffi::getEthPrivKey(key);
Ok(eth_key)
}

Expand Down
6 changes: 2 additions & 4 deletions lib/ain-evm/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ use crate::{
Result,
};

pub type NativeTxHash = [u8; 32];

pub struct EVMCoreService {
pub tx_queues: Arc<TransactionQueueMap>,
pub trie_store: Arc<TrieDBStore>,
Expand Down Expand Up @@ -349,7 +347,7 @@ impl EVMCoreService {
queue_id: u64,
address: H160,
amount: U256,
hash: NativeTxHash,
hash: String,
) -> Result<()> {
let queue_tx = QueueTx::SystemTx(SystemTx::EvmIn(BalanceUpdate { address, amount }));
self.tx_queues
Expand All @@ -368,7 +366,7 @@ impl EVMCoreService {
queue_id: u64,
address: H160,
amount: U256,
hash: NativeTxHash,
hash: String,
) -> Result<()> {
let block_number = self
.storage
Expand Down
19 changes: 9 additions & 10 deletions lib/ain-evm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use primitive_types::H256;
use crate::backend::{EVMBackend, Vicinity};
use crate::block::BlockService;
use crate::bytes::Bytes;
use crate::core::{EVMCoreService, NativeTxHash};
use crate::core::EVMCoreService;
use crate::executor::{AinExecutor, TxResponse};
use crate::fee::{calculate_gas_fee, calculate_prepay_gas_fee};
use crate::filters::FilterService;
Expand All @@ -40,7 +40,7 @@ pub struct EVMServices {
}

pub struct FinalizedBlockInfo {
pub block_hash: [u8; 32],
pub block_hash: String,
pub failed_transactions: Vec<String>,
pub total_burnt_fees: U256,
pub total_priority_fees: U256,
Expand Down Expand Up @@ -227,7 +227,7 @@ impl EVMServices {
signed_tx.transaction.hash()
);
if !exit_reason.is_succeed() {
failed_transactions.push(hex::encode(queue_item.tx_hash));
failed_transactions.push(queue_item.tx_hash);
}

let gas_fee = calculate_gas_fee(&signed_tx, U256::from(used_gas), base_fee)?;
Expand All @@ -245,7 +245,7 @@ impl EVMServices {
);
if let Err(e) = executor.add_balance(address, amount) {
debug!("[construct_block] EvmIn failed with {e}");
failed_transactions.push(hex::encode(queue_item.tx_hash));
failed_transactions.push(queue_item.tx_hash);
}
}
QueueTx::SystemTx(SystemTx::EvmOut(BalanceUpdate { address, amount })) => {
Expand All @@ -256,7 +256,7 @@ impl EVMServices {

if let Err(e) = executor.sub_balance(address, amount) {
debug!("[construct_block] EvmOut failed with {e}");
failed_transactions.push(hex::encode(queue_item.tx_hash));
failed_transactions.push(queue_item.tx_hash);
}
}
QueueTx::SystemTx(SystemTx::DeployContract(DeployContractData {
Expand Down Expand Up @@ -304,12 +304,12 @@ impl EVMServices {
Ok(DST20BridgeInfo { address, storage }) => {
if let Err(e) = executor.update_storage(address, storage) {
debug!("[construct_block] EvmOut failed with {e}");
failed_transactions.push(hex::encode(queue_item.tx_hash));
failed_transactions.push(queue_item.tx_hash);
}
}
Err(e) => {
debug!("[construct_block] EvmOut failed with {e}");
failed_transactions.push(hex::encode(queue_item.tx_hash));
failed_transactions.push(queue_item.tx_hash);
}
}
}
Expand Down Expand Up @@ -358,8 +358,7 @@ impl EVMServices {
.collect(),
Vec::new(),
);

let block_hash = *block.header.hash().as_fixed_bytes();
let block_hash = format!("{:?}", block.header.hash());
let receipts = self.receipt.generate_receipts(
&all_transactions,
receipts_v3,
Expand Down Expand Up @@ -436,7 +435,7 @@ impl EVMServices {
&self,
queue_id: u64,
tx: QueueTx,
hash: NativeTxHash,
hash: String,
gas_used: U256,
) -> Result<()> {
let parent_data = self.block.get_latest_block_hash_and_number()?;
Expand Down
6 changes: 3 additions & 3 deletions lib/ain-evm/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ impl LegacyUnsignedTransaction {
H256::from(output)
}

pub fn sign(&self, key: &H256, chain_id: u64) -> Result<LegacyTransaction, TransactionError> {
pub fn sign(&self, key: &[u8], chain_id: u64) -> Result<LegacyTransaction, TransactionError> {
self.sign_with_chain_id(key, chain_id)
}

pub fn sign_with_chain_id(
&self,
key: &H256,
key: &[u8],
chain_id: u64,
) -> Result<LegacyTransaction, TransactionError> {
let hash = self.signing_hash(chain_id);
let msg = libsecp256k1::Message::parse(hash.as_fixed_bytes());
let s = libsecp256k1::sign(&msg, &libsecp256k1::SecretKey::parse_slice(&key[..])?);
let s = libsecp256k1::sign(&msg, &libsecp256k1::SecretKey::parse_slice(key)?);
let sig = s.0.serialize();

let sig = TransactionSignature::new(
Expand Down
7 changes: 3 additions & 4 deletions lib/ain-evm/src/txqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use ethereum::{Block, TransactionV2};
use ethereum_types::{H160, U256};
use rand::Rng;

use crate::core::NativeTxHash;
use crate::fee::calculate_gas_fee;
use crate::receipt::Receipt;
use crate::transaction::{system::SystemTx, SignedTx};
Expand Down Expand Up @@ -119,7 +118,7 @@ impl TransactionQueueMap {
&self,
queue_id: u64,
tx: QueueTx,
hash: NativeTxHash,
hash: String,
gas_used: U256,
base_fee: U256,
) -> Result<()> {
Expand Down Expand Up @@ -219,7 +218,7 @@ pub enum QueueTx {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct QueueTxItem {
pub tx: QueueTx,
pub tx_hash: NativeTxHash,
pub tx_hash: String,
pub tx_fee: U256,
pub gas_used: U256,
}
Expand Down Expand Up @@ -277,7 +276,7 @@ impl TransactionQueue {
pub fn queue_tx(
&self,
tx: QueueTx,
tx_hash: NativeTxHash,
tx_hash: String,
gas_used: U256,
base_fee: U256,
) -> Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions lib/ain-grpc/src/rpc/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,8 +1059,8 @@ fn sign(
message: TransactionMessage,
) -> Result<TransactionV2, Box<dyn std::error::Error>> {
debug!("sign address {:#x}", address);
let key_id = address.as_fixed_bytes().to_owned();
let priv_key = get_eth_priv_key(key_id).unwrap();
let key = format!("{:?}", address);
let priv_key = get_eth_priv_key(key).unwrap();
let secret_key = SecretKey::parse(&priv_key).unwrap();

match message {
Expand Down
Loading
Loading