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

PR690 redo #707

Merged
merged 72 commits into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
3236fb9
Fix conflicts in ContractFactory
alexandrulaurus Aug 24, 2018
b2d4bc5
Change pubKey, signature order and return address type after signatur…
alexandrulaurus Aug 7, 2018
aa31c66
Test cleanup
alexandrulaurus Aug 2, 2018
e5349a1
Add more test cases and document precompiled contract
alexandrulaurus Aug 2, 2018
d851c2e
fix merge conflict
aionjay Oct 26, 2018
65bdb28
Create EDVerify contract
alexandrulaurus Jul 30, 2018
1cf7b09
code reformat
aionjay Oct 26, 2018
7f03246
fix merge error
aionjay Oct 26, 2018
bfa0a83
revise hashing&EDVerify contract
aionjay Oct 26, 2018
b1b999b
refine Blake2bHash&EDVerify contract
aionjay Oct 29, 2018
18bfff0
remove Black2b 128bits hash implementation and fix edverify testcase
aionjay Oct 29, 2018
fb8fb78
implement TXHash precompiled contract
aionjay Oct 31, 2018
bff3a74
1.) revise precompiled contract address 2.) refine testcase 3) update…
aionjay Oct 31, 2018
5e63cb4
temprary comment out the fastVM jar download and update fastvm ref
aionjay Oct 31, 2018
01783fd
revise the ExecutionContext and the TXHashContract for getting the tx…
aionjay Nov 1, 2018
6e08873
update fastVM ref
aionjay Nov 1, 2018
1b76c66
enable the fastvm lib download dependency
aionjay Nov 14, 2018
27089f9
take out unnecessary gradle settings
aionjay Nov 2, 2018
8b9e591
refine ContractFactory
aionjay Nov 2, 2018
f4f06eb
revise blake2bHash contract for limit the input size
aionjay Nov 1, 2018
79550aa
update gitmodule settings
aionjay Nov 1, 2018
e470c34
take out unnecessary gradle settings
aionjay Nov 2, 2018
f0ec1a0
refine precompile contract and formatting - Blake2bHash, EDVerify and…
aionjay Nov 14, 2018
29d30d2
removed un-needed helper method and imports, updated expected result …
aionWilliam Nov 8, 2018
b42cd7f
refine ContractFactory
aionjay Nov 2, 2018
cd18054
added more tests to edverify, refractored tests
aionWilliam Nov 8, 2018
fa1f53c
added input documentations for EDVerifyContract
aionWilliam Nov 9, 2018
a2d8039
improve comments
aionWilliam Nov 9, 2018
fec7ba9
updated tests
aionWilliam Nov 9, 2018
9387838
fix precompiled contract test fail
aionjay Nov 14, 2018
1cee222
fix prepack script and remove client api has been pack into the kerne…
aionjay Nov 14, 2018
e142545
rollback web3 pack settings
aionjay Nov 14, 2018
80d1c61
add benchmark test, modify engergy charge for the precompiled contract
aionjay Nov 15, 2018
10e94ca
Optimize import
aionjay Nov 15, 2018
99de446
add CfgFork
beidouz Nov 16, 2018
7ed73f0
add fork cases to getPrecompiledContract
beidouz Nov 16, 2018
49c58c3
remove redundant code by the PR comments
aionjay Nov 16, 2018
fc6fc9e
fix failing tests in modPrecompiled after adding fork-properties
beidouz Nov 16, 2018
d85a543
update fastvm ref
aionjay Nov 19, 2018
5948c7e
revise gradle pack settings
aionjay Nov 19, 2018
b8f69bd
move precompiled contract into the precompiled package
aionjay Nov 19, 2018
edff9f2
refactor contract
aionjay Nov 19, 2018
4b8c386
refacoring testcase by review
aionjay Nov 19, 2018
0dc8939
fix failing tests in modPrecompiled after adding fork-properties
beidouz Nov 16, 2018
17dd8b1
Merge branch 'AIP_forkproperties' of https://github.com/aionnetwork/a…
aionjay Nov 20, 2018
74aded9
revise cfgFork class
aionjay Nov 20, 2018
d4e0ad1
revise cgfFork implement
aionjay Nov 20, 2018
2533046
update implementation note in the Blake2bHashContract
aionjay Nov 20, 2018
6178ceb
refine method scope in the Blake2bHashContract
aionjay Nov 20, 2018
1747549
revise fork implementation
aionjay Nov 20, 2018
41da690
revise testcase
aionjay Nov 20, 2018
fe2780b
revise testcase
aionjay Nov 20, 2018
36a39c7
update forkNumber
aionjay Nov 20, 2018
756b0c0
print fork info
aionjay Nov 20, 2018
caae18e
Merge branch 'AIP_redo' into AIP_forkproperties
aionjay Nov 20, 2018
e0e7adf
fix pack
aionjay Nov 20, 2018
1fec69e
fix fork default settings logic in Cli and CfgAion
aionjay Nov 21, 2018
9f7348d
refactor fork properties settings by review comments
aionjay Nov 21, 2018
02f917a
1.) revise fork logic in cfgAion and test case 2.) refactoring the Co…
aionjay Nov 21, 2018
8d49e96
fix fork setting overwrite issue
aionjay Nov 21, 2018
a752293
set default fork# to 0 in the custom network
aionjay Nov 21, 2018
a89e939
introduced migration of old kernel configuration
AlexandraRoatis Nov 21, 2018
21a51b1
setting the keystore path from the config file
AlexandraRoatis Nov 21, 2018
454f0db
Update the gitignore to exlucde network data folders
iamyulong Nov 22, 2018
3dbe09c
Move the modBoot/resource to config
iamyulong Nov 22, 2018
19e5f8a
set the absolute path for db and log to be written back to file
AlexandraRoatis Nov 22, 2018
7497336
updated unit tests for migration of old kernel config
AlexandraRoatis Nov 22, 2018
2a19f3e
minor spacking adjustment
AlexandraRoatis Nov 22, 2018
4b8f728
Merge pull request #718 from aionnetwork/AIP_config_migration
AionJayT Nov 22, 2018
1774aa7
Merge pull request #719 from aionnetwork/yulong
AionJayT Nov 23, 2018
0394a42
Merge pull request #710 from aionnetwork/AIP_forkproperties
AionJayT Nov 23, 2018
a80bbf8
Merge branch 'master-pre-merge' into AIP_redo
AionJayT Nov 23, 2018
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 aion_fastvm
Submodule aion_fastvm updated 69 files
+1 −3 .gitignore
+1 −0 README.md
+172 −172 eclipse/jni/.cproject
+1 −1 eclipse/jni/.project
+0 −0 eclipse/jni/.settings/language.settings.xml
+0 −0 eclipse/jni/.settings/org.eclipse.cdt.codan.core.prefs
+153 −153 eclipse/solidity/.cproject
+2 −2 fastvm/Makefile
+0 −0 fastvm/bench/evm/Makefile
+0 −0 fastvm/bench/evm/evm.h
+0 −0 fastvm/bench/evm/evmjit.h
+ fastvm/bench/evm/libevmjit.a
+0 −0 fastvm/bench/evm/main.cpp
+0 −0 fastvm/bench/fastvm/Makefile
+0 −0 fastvm/bench/fastvm/evm.h
+0 −0 fastvm/bench/fastvm/evmjit.h
+ fastvm/bench/fastvm/libevmjit.so
+0 −0 fastvm/bench/fastvm/main.cpp
+0 −0 fastvm/include/evm.h
+0 −0 fastvm/include/evmjit.h
+0 −0 fastvm/jni/org_aion_fastvm_FastVM.cpp
+0 −0 fastvm/jni/org_aion_fastvm_FastVM.h
+0 −0 fastvm/libevmjit/Arith128.cpp
+0 −0 fastvm/libevmjit/Arith128.h
+0 −0 fastvm/libevmjit/Array.cpp
+0 −0 fastvm/libevmjit/Array.h
+0 −0 fastvm/libevmjit/BasicBlock.cpp
+0 −0 fastvm/libevmjit/BasicBlock.h
+0 −0 fastvm/libevmjit/BuildInfo.gen.h
+0 −0 fastvm/libevmjit/Cache.cpp
+0 −0 fastvm/libevmjit/Cache.h
+0 −0 fastvm/libevmjit/Common.h
+0 −0 fastvm/libevmjit/Compiler.cpp
+0 −0 fastvm/libevmjit/Compiler.h
+0 −0 fastvm/libevmjit/CompilerHelper.cpp
+0 −0 fastvm/libevmjit/CompilerHelper.h
+0 −0 fastvm/libevmjit/Endianness.cpp
+0 −0 fastvm/libevmjit/Endianness.h
+0 −0 fastvm/libevmjit/ExecStats.cpp
+0 −0 fastvm/libevmjit/ExecStats.h
+0 −0 fastvm/libevmjit/Ext.cpp
+0 −0 fastvm/libevmjit/Ext.h
+0 −0 fastvm/libevmjit/GasMeter.cpp
+0 −0 fastvm/libevmjit/GasMeter.h
+0 −0 fastvm/libevmjit/Instruction.cpp
+0 −0 fastvm/libevmjit/Instruction.h
+0 −0 fastvm/libevmjit/JIT.cpp
+0 −0 fastvm/libevmjit/JIT.h
+0 −0 fastvm/libevmjit/Memory.cpp
+0 −0 fastvm/libevmjit/Memory.h
+0 −0 fastvm/libevmjit/Optimizer.cpp
+0 −0 fastvm/libevmjit/Optimizer.h
+0 −0 fastvm/libevmjit/RuntimeManager.cpp
+0 −0 fastvm/libevmjit/RuntimeManager.h
+0 −0 fastvm/libevmjit/Type.cpp
+0 −0 fastvm/libevmjit/Type.h
+0 −0 fastvm/libevmjit/Utils.cpp
+0 −0 fastvm/libevmjit/Utils.h
+0 −0 fastvm/libevmjit/preprocessor/llvm_includes_end.h
+0 −0 fastvm/libevmjit/preprocessor/llvm_includes_start.h
+0 −0 fastvm/tests/main.cpp
+33 −39 scripts/release.sh
+8 −2 solidity/libsolidity/analysis/GlobalContext.cpp
+9 −0 solidity/libsolidity/ast/Types.cpp
+5 −2 solidity/libsolidity/ast/Types.h
+14 −3 solidity/libsolidity/codegen/ExpressionCompiler.cpp
+7 −0 solidity/tests/contracts/testBlake2b.sol
+8 −0 solidity/tests/contracts/testTxHash.sol
+12 −0 solidity/tests/contracts/testedvalidate.sol
18 changes: 5 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ def dirPack = "./pack"
def dirLibFile = "lib"
def dirModFile ="./mod"
def javaHome = System.getProperty('java.home')

def vmVersion = "0.3.1"
def vmVersion = "0.3.2"
def dirRuntimeJars = 'jars' // we'll store mod and lib stuff in here

allprojects {
Expand Down Expand Up @@ -60,7 +59,7 @@ task compileNative(type:Exec) {
"-shared",
"-I${javaHome}/include",
"-I${javaHome}/include/linux",
"-I${dirBuildNative}",
"-I${dirBuildNative}",
"-I${dirNative}/linux/sodium",
"-mtune=generic",
"-m64",
Expand Down Expand Up @@ -196,7 +195,7 @@ task downloadFastVmGit(type:Download) {
dest buildDir
}

task downloadSolidityGit(type:Download) {
task downloadSolidityGit(type:Download) {
overwrite false // TODO This seems to work only when this task is directly invoked
onlyIfModified true
src "https://github.com/aionnetwork/aion_fastvm/releases/download/v${vmVersion}/solidity_v${vmVersion}.tar.gz"
Expand Down Expand Up @@ -283,18 +282,11 @@ task pack(type: Tar) {
from "${dirPack}/rt"
include '**'
}
into('/aion/web3') {
into('/aion/console') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we find another name for this folder? console has a common prefix with config leading to a lot of frustrations when trying to auto-complete with tab in the terminal. Perhaps web-console?

from "${dirPack}/web3"
include '**'
}
into('/aion/docs') {
from "${dirPack}/docs"
include '**'
}
into('/aion/clientAPI') {
from "${dirPack}/clientAPI"
include '**'
}

AlexandraRoatis marked this conversation as resolved.
Show resolved Hide resolved
into('/aion/script') {
from "${dirPack}/script"
include 'generateSslCert.sh', 'nohup_wrapper.sh'
Expand Down
3 changes: 1 addition & 2 deletions deploy/serverList.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
52.237.31.69
52.179.100.107
13.89.244.125
86 changes: 70 additions & 16 deletions modPrecompiled/src/org/aion/precompiled/ContractFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,41 @@
import org.aion.mcf.core.AccountState;
import org.aion.mcf.db.IBlockStoreBase;
import org.aion.precompiled.contracts.ATB.TokenBridgeContract;
import org.aion.precompiled.contracts.Blake2bHashContract;
import org.aion.precompiled.contracts.EDVerifyContract;
import org.aion.precompiled.contracts.TXHashContract;
import org.aion.vm.ExecutionContext;
import org.aion.vm.IContractFactory;
import org.aion.vm.IPrecompiledContract;

/** A factory class that produces pre-compiled contract instances. */
public class ContractFactory implements IContractFactory {
private static final String OWNER =

private static final String ADDR_OWNER =
"0000000000000000000000000000000000000000000000000000000000000000";
private static final String TOTAL_CURRENCY =
private static final String ADDR_TOTAL_CURRENCY =
"0000000000000000000000000000000000000000000000000000000000000100";

private static final String TOKEN_BRIDGE =
private static final String ADDR_TOKEN_BRIDGE =
"0000000000000000000000000000000000000000000000000000000000000200";
private static final String TOKEN_BRIDGE_INITIAL_OWNER =
private static final String ADDR_TOKEN_BRIDGE_INITIAL_OWNER =
"a008d7b29e8d1f4bfab428adce89dc219c4714b2c6bf3fd1131b688f9ad804aa";

private static final String ADDR_ED_VERIFY =
"0000000000000000000000000000000000000000000000000000000000000010";
private static final String ADDR_BLAKE2B_HASH =
"0000000000000000000000000000000000000000000000000000000000000011";
private static final String ADDR_TX_HASH =
"0000000000000000000000000000000000000000000000000000000000000012";

private static IPrecompiledContract PC_ED_VERIFY;
private static IPrecompiledContract PC_BLAKE2B_HASH;

static {
PC_ED_VERIFY = new EDVerifyContract();
PC_BLAKE2B_HASH = new Blake2bHashContract();
}

public ContractFactory() {}

/**
Expand All @@ -60,21 +79,27 @@ public IPrecompiledContract getPrecompiledContract(
IRepositoryCache<AccountState, IDataWord, IBlockStoreBase<?, ?>> track) {

switch (context.address().toString()) {
case TOTAL_CURRENCY:
// return new TotalCurrencyContract(track, context.sender(), Address.wrap(OWNER));
return null;
case TOKEN_BRIDGE:
case ADDR_TOKEN_BRIDGE:
TokenBridgeContract contract =
new TokenBridgeContract(
context,
track,
Address.wrap(TOKEN_BRIDGE_INITIAL_OWNER),
Address.wrap(TOKEN_BRIDGE));
Address.wrap(ADDR_TOKEN_BRIDGE_INITIAL_OWNER),
Address.wrap(ADDR_TOKEN_BRIDGE));

if (!context.origin().equals(Address.wrap(TOKEN_BRIDGE_INITIAL_OWNER))
&& !contract.isInitialized()) return null;
if (!context.origin().equals(Address.wrap(ADDR_TOKEN_BRIDGE_INITIAL_OWNER))
&& !contract.isInitialized()) {
return null;
}

return contract;
case ADDR_ED_VERIFY:
return PC_ED_VERIFY;
case ADDR_BLAKE2B_HASH:
return PC_BLAKE2B_HASH;
case ADDR_TX_HASH:
return new TXHashContract(context);
case ADDR_TOTAL_CURRENCY:
default:
return null;
}
Expand All @@ -88,10 +113,12 @@ public IPrecompiledContract getPrecompiledContract(
*/
public static boolean isPrecompiledContract(Address address) {
switch (address.toString()) {
case TOTAL_CURRENCY:
return true;
case TOKEN_BRIDGE:
case ADDR_TOKEN_BRIDGE:
case ADDR_ED_VERIFY:
case ADDR_BLAKE2B_HASH:
case ADDR_TX_HASH:
return true;
case ADDR_TOTAL_CURRENCY:
default:
return false;
}
Expand All @@ -103,6 +130,33 @@ public static boolean isPrecompiledContract(Address address) {
* @return the contract address.
*/
public static Address getTotalCurrencyContractAddress() {
return Address.wrap(TOTAL_CURRENCY);
return Address.wrap(ADDR_TOTAL_CURRENCY);
}

/**
* Returns the address of the EdVerifyContract contract.
*
* @return the contract address
*/
public static Address getEdVerifyContractAddress() {
return Address.wrap(ADDR_ED_VERIFY);
}

/**
* Returns the address of the TxHash contract.
*
* @return the contract address
*/
public static Address getTxHashContractAddress() {
return Address.wrap(ADDR_TX_HASH);
}

/**
* Returns the address of the blake2b hash contract.
*
* @return the contract address
*/
public static Address getBlake2bHashContractAddress() {
return Address.wrap(ADDR_BLAKE2B_HASH);
}
}
96 changes: 0 additions & 96 deletions modPrecompiled/src/org/aion/precompiled/contracts/Blake2bHash.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2017-2018 Aion foundation.
*
* This file is part of the aion network project.
*
* The aion network project is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or any later version.
*
* The aion network project is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the aion network project source files.
* If not, see <https://www.gnu.org/licenses/>.
*
* Contributors:
* Aion foundation.
*/
package org.aion.precompiled.contracts;

import static org.aion.crypto.HashUtil.blake256;

import com.google.common.annotations.VisibleForTesting;
import org.aion.vm.AbstractExecutionResult.ResultCode;
import org.aion.vm.ExecutionResult;
import org.aion.vm.IPrecompiledContract;

/**
* @author Jay Tseng
* @author William Zhai
* @implNote Base on benchmark the keccak256hash and blake2bhash precompiled contract blake2b is
* 5 times faster then keccak256. Therefore, blake2b modify the energy charge to 1/3 of the
* Ethereum keccak256 precompiled contract charge.
*/
public class Blake2bHashContract implements IPrecompiledContract {

private static final long COST = 10L;
private static final int WORD_LENGTH = 4;
private static final int NRG_CHARGE_PER_WORD = 2;
private static final String INPUT_LENGTH_ERROR_MESSAGE = "incorrect size of the input data.";

public Blake2bHashContract() {}

/**
* Returns the hash of given input
*
* @param input data input; must be less or equal than 2 MB
* @return the returned blake2b 256bits hash is in ExecutionResult.getOutput
*/
public ExecutionResult execute(byte[] input, long nrg) {

// check length
if (input == null || input.length == 0 || input.length > 2_097_152L) {
return new ExecutionResult(
ResultCode.FAILURE, nrg - COST, INPUT_LENGTH_ERROR_MESSAGE.getBytes());
}

long additionalNRG =
((long) Math.ceil(((double) input.length - 1) / WORD_LENGTH)) * NRG_CHARGE_PER_WORD;

// check input nrg
long nrgLeft = nrg - (COST + additionalNRG);

if (nrgLeft < 0) {
return new ExecutionResult(ResultCode.OUT_OF_NRG, 0);
}

return blake256Hash(input, nrgLeft);
}

private ExecutionResult blake256Hash(byte[] input, long nrg) {
byte[] hash = blake256(input);
return new ExecutionResult(ResultCode.SUCCESS, nrg, hash);
}

@VisibleForTesting
static byte[] setupInput(int operation, byte[] inputByteArray) {
byte[] ret = new byte[1 + inputByteArray.length];
ret[0] = (byte) operation;
System.arraycopy(inputByteArray, 0, ret, 1, inputByteArray.length);
return ret;
}
}
Loading