Skip to content

Commit 69ad210

Browse files
authored
Merge branch 'develop' into develop_eip1559
2 parents aca8d38 + 9c727a6 commit 69ad210

File tree

8 files changed

+37
-22
lines changed

8 files changed

+37
-22
lines changed

src/components/contracts/modules/evm/precompile/eth-pairings/src/lib.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use evm_precompile_utils::{EvmDataReader, EvmDataWriter, EvmResult, Gasometer};
88
use module_evm::precompile::{FinState, Precompile, PrecompileId, PrecompileResult};
99
use tracing::debug;
1010

11-
const GAS_EXECUTION: u64 = 3437;
12-
1311
/// The Verifier precompile.
1412
pub struct EthPairing;
1513

@@ -50,20 +48,35 @@ impl Precompile for EthPairing {
5048
}
5149

5250
impl EthPairing {
53-
fn call_public_api_on_vector(data: &[u8]) -> Result<Vec<u8>, ApiError> {
51+
fn get_operation(data: &[u8]) -> Result<(OperationType, &[u8]), ApiError> {
5452
if data.is_empty() {
5553
return Err(ApiError::InputError("input is zero length".to_owned()));
5654
}
5755
let op = OperationType::from_u8(data[0]).ok_or(ApiError::MissingValue)?;
58-
perform_operation(op, &data[0..])
56+
Ok((op, &data[1..]))
57+
}
58+
59+
fn call_public_api_on_vector(data: &[u8]) -> Result<Vec<u8>, ApiError> {
60+
let (op, input) = Self::get_operation(data)?;
61+
perform_operation(op, input)
62+
}
63+
64+
fn calculate_gas_for_operation(data: &[u8]) -> Result<u64, ApiError> {
65+
let (op, input) = Self::get_operation(data)?;
66+
eth_pairings::gas_meter::meter_operation(op, input)
5967
}
6068

6169
fn execute_operation(
6270
mut input: EvmDataReader,
6371
target_gas: Option<u64>,
6472
) -> EvmResult<PrecompileOutput> {
73+
// Calculate and record required gas for operation
6574
let mut gasometer = Gasometer::new(target_gas);
66-
gasometer.record_cost(GAS_EXECUTION)?;
75+
let gas = match Self::calculate_gas_for_operation(input.get_slice()) {
76+
Ok(res) => res,
77+
Err(api_err) => return Err(ExitError::Other(api_err.to_string().into())),
78+
};
79+
gasometer.record_cost(gas)?;
6780

6881
debug!(target: "evm", "EthPairing#executingOp");
6982
let result = match Self::call_public_api_on_vector(input.get_slice()) {

src/components/contracts/modules/evm/precompile/eth-pairings/src/tests.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use fp_mocks::*;
44

55
// Test from eth-pairings (eip1962) repository https://github.com/FindoraNetwork/eip1962
66
#[test]
7-
fn test_g1_mul() {
7+
fn test_bls12_pairing() {
88
use hex;
9-
let hex_string = "02820d8080001026e1318f230000000000000080be6dc885e544bee65620747e191023316695af6989f85b230000000000044eccc6886286fbaee7561d483d50d89e9e9e95af2989f85b230000000000044eccc688628631";
9+
let hex_string = "07202912811758d871b77a9c3635c28570dc020576f9fc2719d8d0494439162b2b89000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011603e65409b693c8a08aeb3478d10aa3732a6672ba06d12912811758d871b77a9c3635c28570dc020576f9fc2719d8d0494439162b2b84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010206059efde42f3701020127ccb2831f0011c1d547c491b9dffbd4cfdb87598a4b370f5873ea62094a2f201faa6cb7f6fcca66de3f308a25776dac3f61edb792948fbe53e4d18a3d8aefbe011a7e9f75f3fdc77b83a97f7acd58326a0545f8aa37b69bfb32c52dc195763e8c17176e0ad4ee94d9c720e922d42688127c4b812cd7c2f8cf6126acd4c3d7568121e48b3fefe66c279f2ec71f0d6f8156a3343d1cfa54b808d747cd02419278290ad2d7d03f5de1e7b3c97732f53dbe1dfd42e51f9571f7fee3d9c1785d5a1ed6010b4f7f211a0a5f4425728e2df580196d3e3b85ef148ed769acd23e9be6e8440726cb40655787f48eaf46154cb740e2a58db5b96fa02d83fb9d0f94320da1471e0104ece4c46ac4f05a7c28ecda84292f15999747bb77c530c65448f1f837a47dd70e972c4065d0b39d40b5d550a55901516afa7f02b395963d1535fcba1705e31a117cb4beab1dc582198c4ab0c02e96a22f7bd10dde3bbbdbc9182a9596cb0ed32121616b692e8036437efb4c3816f018f11e643c6e0a049da431986a3a722b06";
1010
let data = hex::decode(hex_string).unwrap();
1111

12-
assert!(EthPairing::execute(
12+
let output = EthPairing::execute(
1313
&EvmDataWriter::new()
1414
.write_selector(Call::ExecuteOperation)
1515
.write_raw_bytes(&data)
@@ -21,6 +21,9 @@ fn test_g1_mul() {
2121
apparent_value: From::from(0),
2222
},
2323
&BASE_APP.lock().unwrap().deliver_state,
24-
)
25-
.is_ok());
24+
);
25+
26+
assert!(output.is_ok());
27+
assert_eq!(output.as_ref().unwrap().cost, 164986);
28+
assert_eq!(output.unwrap().output, vec![0x1]);
2629
}

src/components/contracts/primitives/types/src/crypto.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,12 @@ impl Verify for XfrSignature {
450450
pub fn secp256k1_ecdsa_recover(sig: &[u8; 65], msg: &[u8; 32]) -> ruc::Result<[u8; 64]> {
451451
let rs = libsecp256k1::Signature::parse_standard_slice(&sig[0..64])
452452
.map_err(|_| eg!("Ecdsa signature verify error: bad RS"))?;
453-
let v =
454-
libsecp256k1::RecoveryId::parse(
455-
if sig[64] > 26 { sig[64] - 27 } else { sig[64] },
456-
)
457-
.map_err(|_| eg!("Ecdsa signature verify error: bad V"))?;
453+
let v = libsecp256k1::RecoveryId::parse(if sig[64] > 26 {
454+
sig[64] - 27
455+
} else {
456+
sig[64]
457+
})
458+
.map_err(|_| eg!("Ecdsa signature verify error: bad V"))?;
458459
let pubkey = libsecp256k1::recover(&libsecp256k1::Message::parse(msg), &rs, &v)
459460
.map_err(|_| eg!("Ecdsa signature verify error: bad signature"))?;
460461
let mut res = [0u8; 64];

src/components/contracts/rpc/src/eth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ impl EthApi for EthApiImpl {
681681

682682
let task = spawn_blocking(move || -> Result<Option<RichBlock>> {
683683
if let Some(h) = height {
684-
if 0 < h && h < *EVM_FIRST_BLOCK_HEIGHT {
684+
if 0 < h && h < CFG.checkpoint.evm_first_block_height as u64 {
685685
return Ok(Some(dummy_block(h, full)));
686686
}
687687
}

src/components/finutils/src/txn_builder/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,7 @@ impl AnonTransferOperationBuilder {
18711871
};
18721872
}
18731873

1874-
let remainder = sum_input - sum_output - (fees);
1874+
let remainder = sum_input - sum_output - fees;
18751875
if remainder > 0 {
18761876
let oabar_money_back = OpenAnonAssetRecordBuilder::new()
18771877
.amount(remainder)

src/ledger/src/store/api_cache.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,7 @@ pub fn check_lost_data(ledger: &mut LedgerState) -> Result<()> {
462462
}
463463

464464
// update the last txo sid
465-
api_cache
466-
.last_sid
467-
.insert("last_txo_sid".to_string(), index);
465+
api_cache.last_sid.insert("last_txo_sid".to_string(), index);
468466
}
469467
}
470468

src/ledger/src/store/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ impl LedgerStatus {
14741474
);
14751475
if seq_id > self.block_commit_count {
14761476
return Err(eg!(("Transaction seq_id ahead of block_count")));
1477-
} else if seq_id + (TRANSACTION_WINDOW_WIDTH) < self.block_commit_count {
1477+
} else if seq_id + TRANSACTION_WINDOW_WIDTH < self.block_commit_count {
14781478
return Err(eg!(("Transaction seq_id too far behind block_count")));
14791479
} else {
14801480
// Check to see that this nrpt has not been seen before

src/libs/bitmap/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ fn count_byte(mask: usize) -> u8 {
566566
let mut result = 0;
567567

568568
for i in 0..8 {
569-
result += u8::from(mask & (1 << i) != 0);
569+
result += (mask & (1 << i) != 0) as u8;
570570
}
571571

572572
result

0 commit comments

Comments
 (0)