-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Transaction energy rule check within kernel and FVM
- Loading branch information
Showing
8 changed files
with
62 additions
and
12 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
modAionImpl/src/org/aion/zero/impl/vm/common/TransactionUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.aion.zero.impl.vm.common; | ||
|
||
import org.aion.fastvm.FvmConstants; | ||
|
||
/** Duplicate from the fastVM module. */ | ||
public final class TransactionUtil { | ||
|
||
public static long computeTransactionCost(boolean isCreate, byte[] data) { | ||
long nonZeroes = nonZeroBytesInData(data); | ||
long zeroes = zeroBytesInData(data); | ||
|
||
return (isCreate ? FvmConstants.CREATE_TRANSACTION_FEE : 0) | ||
+ FvmConstants.TRANSACTION_BASE_FEE | ||
+ zeroes * FvmConstants.ZERO_BYTE_FEE | ||
+ nonZeroes * FvmConstants.NONZERO_BYTE_FEE; | ||
} | ||
|
||
private static long nonZeroBytesInData(byte[] data) { | ||
int total = (data == null) ? 0 : data.length; | ||
|
||
return total - zeroBytesInData(data); | ||
} | ||
|
||
private static long zeroBytesInData(byte[] data) { | ||
if (data == null) { | ||
return 0; | ||
} | ||
|
||
int c = 0; | ||
for (byte b : data) { | ||
c += (b == 0) ? 1 : 0; | ||
} | ||
return c; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters