Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validator for transactions ensuring AVM tx can be used only when the …
…AVM is enabled
- Loading branch information
1 parent
1acc164
commit 9a30633
Showing
11 changed files
with
94 additions
and
6 deletions.
There are no files selected for viewing
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,7 @@ | ||
package org.aion.base.vm; | ||
|
||
public final class VirtualMachineSpecs { | ||
|
||
public static final byte AVM_VM_CODE = 0xf; | ||
public static final byte FVM_DEFAULT_TX_TYPE = 0x01; | ||
} |
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
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
32 changes: 32 additions & 0 deletions
32
modAionImpl/src/org/aion/zero/impl/valid/TransactionTypeValidator.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,32 @@ | ||
package org.aion.zero.impl.valid; | ||
|
||
import static org.aion.mcf.valid.TransactionTypeRule.isValidAVMTransactionType; | ||
import static org.aion.mcf.valid.TransactionTypeRule.isValidFVMTransactionType; | ||
|
||
import org.aion.zero.types.AionTransaction; | ||
|
||
/** | ||
* Validator for the type field of transactions allowed by the network. The transaction types | ||
* currently correlate with which virtual machines are enabled. This field mainly impacts contract | ||
* creation. Contracts created using the default transaction type should be deployed on the FastVM. | ||
* AVM contracts creations/transactions are declared valid only if the AVM is enabled from the | ||
* configuration and the transaction has the correct type associated with the AVM. | ||
* | ||
* @author Alexandra Roatis | ||
*/ | ||
public class TransactionTypeValidator { | ||
|
||
private boolean avmEnabled; | ||
|
||
public TransactionTypeValidator(boolean enableAVM) { | ||
this.avmEnabled = enableAVM; | ||
} | ||
|
||
public boolean isValid(AionTransaction tx) { | ||
// verify transaction type | ||
byte type = tx.getTransactionType(); | ||
// the type must be either valid for the FVM | ||
// or for the AVM when the AVM is enabled | ||
return isValidFVMTransactionType(type) || (avmEnabled && isValidAVMTransactionType(type)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.aion.mcf.valid; | ||
|
||
import org.aion.base.vm.VirtualMachineSpecs; | ||
|
||
/** | ||
* Rules for validating transactions based on allowed types. | ||
* | ||
* @author Alexandra Roatis | ||
*/ | ||
public class TransactionTypeRule { | ||
|
||
public static boolean isValidFVMTransactionType(byte type) { | ||
return type == VirtualMachineSpecs.FVM_DEFAULT_TX_TYPE; | ||
} | ||
|
||
public static boolean isValidAVMTransactionType(byte type) { | ||
return type == VirtualMachineSpecs.AVM_VM_CODE; | ||
} | ||
} |