Skip to content

Commit

Permalink
Fix gas calculation error.[skip audit] (#908)
Browse files Browse the repository at this point in the history
  • Loading branch information
leeyr338 committed Feb 7, 2020
1 parent 8fd7ed7 commit 8896c6d
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions cita-executor/core/src/cita_executive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,16 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> {

match result {
Ok(InterpreterResult::Normal(output, gas_left, logs)) => {
let refund = get_refund(store.clone(), sender, gas_limit.as_u64(), gas_left);
let gas_left = gas_left + refund;
if self.payment_required() {
let refund = get_refund(store.clone(), sender, gas_limit.as_u64(), gas_left);
if let Err(e) = liquidtion(
self.state_provider.clone(),
store.clone(),
sender,
gas_price,
gas_limit.as_u64(),
gas_left,
refund,
) {
finalize_result.exception = Some(ExecutedException::VM(e));
return finalize_result;
Expand All @@ -280,14 +280,15 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> {
finalize_result.quota_left = U256::from(gas_left);
finalize_result.logs = transform_logs(logs);
finalize_result.logs_bloom = logs_to_bloom(&finalize_result.logs);

trace!(
"Get data after executed the transaction [Normal]: {:?}",
output
);
finalize_result.output = output;
}
Ok(InterpreterResult::Revert(output, gas_left)) => {
let refund = get_refund(store.clone(), sender, gas_limit.as_u64(), gas_left);
let gas_left = gas_left + refund;
if self.payment_required() {
if let Err(e) = liquidtion(
self.state_provider.clone(),
Expand All @@ -296,7 +297,6 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> {
gas_price,
gas_limit.as_u64(),
gas_left,
0,
) {
finalize_result.exception = Some(ExecutedException::VM(e));
return finalize_result;
Expand All @@ -315,16 +315,16 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> {
);
}
Ok(InterpreterResult::Create(output, gas_left, logs, addr)) => {
let refund = get_refund(store.clone(), sender, gas_limit.as_u64(), gas_left);
let gas_left = gas_left + refund;
if self.payment_required() {
let refund = get_refund(store.clone(), sender, gas_limit.as_u64(), gas_left);
if let Err(e) = liquidtion(
self.state_provider.clone(),
store.clone(),
sender,
gas_price,
gas_limit.as_u64(),
gas_left,
refund,
) {
finalize_result.exception = Some(ExecutedException::VM(e));
return finalize_result;
Expand Down Expand Up @@ -357,7 +357,6 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> {
gas_price,
gas_limit.as_u64(),
0,
0,
) {
finalize_result.exception = Some(ExecutedException::VM(e));
return finalize_result;
Expand Down Expand Up @@ -753,21 +752,19 @@ fn liquidtion<B: DB + 'static>(
gas_price: U256,
gas_limit: u64,
gas_left: u64,
refund: u64,
) -> Result<(), VMError> {
trace!(
"gas_price: {:?}, gas limit:{:?}, gas left: {:?}, refund: {:?}",
"gas_price: {:?}, gas limit:{:?}, gas left: {:?}",
gas_price,
gas_limit,
gas_left,
refund
);
state_provider
.borrow_mut()
.add_balance(&sender, gas_price * (gas_left + refund))?;
.add_balance(&sender, gas_price * gas_left)?;
state_provider.borrow_mut().add_balance(
&store.borrow().evm_context.coinbase,
gas_price * (gas_limit - gas_left - refund),
gas_price * (gas_limit - gas_left),
)?;
Ok(())
}
Expand Down

0 comments on commit 8896c6d

Please sign in to comment.