Skip to content

Commit

Permalink
Merge pull request #16 from vitelabs/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
charles-liu committed Mar 3, 2022
2 parents d95a576 + ef41f32 commit 345c843
Show file tree
Hide file tree
Showing 2,593 changed files with 30,361 additions and 9,535 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ include(ViteUtils)

include(EthToolchains)

option(SOLC_LINK_STATIC "Link solc executable statically on supported platforms" OFF)
option(SOLC_LINK_STATIC "Link solc executable statically on supported platforms" ON)
option(SOLC_STATIC_STDLIBS "Link solc against static versions of libgcc and libstdc++ on supported platforms" OFF)

# Let's find our dependencies
Expand All @@ -37,7 +37,7 @@ find_package(Threads)
include(EthPolicy)
eth_policy()

set(PROJECT_VERSION "0.8.0")
set(PROJECT_VERSION "0.8.1")

# Figure out what compiler and system are we using
include(ViteCompilerSettings)
Expand Down
10 changes: 5 additions & 5 deletions libevmasm/Assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ AssemblyItem Assembly::namedTag(string const& _name)

AssemblyItem Assembly::newPushLibraryAddress(string const& _identifier)
{
h256 h(util::blake2b(_identifier)); // Solidity++: keccak256 -> blake2b
h256 h(util::keccak256(_identifier));
m_libraries[h] = _identifier;
return AssemblyItem{PushLibraryAddress, h};
}
Expand Down Expand Up @@ -675,9 +675,9 @@ LinkerObject const& Assembly::assemble() const
break;
}
case PushLibraryAddress:
ret.bytecode.push_back(static_cast<uint8_t>(Instruction::PUSH20));
ret.bytecode.push_back(static_cast<uint8_t>(Instruction::PUSH21)); // Solidity++: 168-bit address
ret.linkReferences[ret.bytecode.size()] = m_libraries.at(i.data());
ret.bytecode.resize(ret.bytecode.size() + 20);
ret.bytecode.resize(ret.bytecode.size() + 21); // Solidity++: 168-bit address
break;
case PushImmutable:
ret.bytecode.push_back(static_cast<uint8_t>(Instruction::PUSH32));
Expand Down Expand Up @@ -711,8 +711,8 @@ LinkerObject const& Assembly::assemble() const
break;
}
case PushDeployTimeAddress:
ret.bytecode.push_back(static_cast<uint8_t>(Instruction::PUSH20));
ret.bytecode.resize(ret.bytecode.size() + 20);
ret.bytecode.push_back(static_cast<uint8_t>(Instruction::PUSH21)); // Solidity++: 168-bit address
ret.bytecode.resize(ret.bytecode.size() + 21); // Solidity++: 168-bit address
break;
case Tag:
assertThrow(i.data() != 0, AssemblyException, "Invalid tag position.");
Expand Down
1 change: 1 addition & 0 deletions libevmasm/Assembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <libsolutil/Common.h>
#include <libsolutil/Assertions.h>
#include <libsolutil/Keccak256.h>
#include <libsolutil/Blake2.h>

#include <json/json.h>
Expand Down
2 changes: 1 addition & 1 deletion libevmasm/AssemblyItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ size_t AssemblyItem::bytesRequired(size_t _addressLength) const
return 1 + _addressLength;
case PushLibraryAddress:
case PushDeployTimeAddress:
return 1 + 20;
return 1 + 21; // Solidity++: 168-bit address
case PushImmutable:
return 1 + 32;
case AssignImmutable:
Expand Down
4 changes: 2 additions & 2 deletions libevmasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ set(sources
${ORIGINAL_SOURCE_DIR}/JumpdestRemover.h
${ORIGINAL_SOURCE_DIR}/KnownState.cpp
${ORIGINAL_SOURCE_DIR}/KnownState.h
${ORIGINAL_SOURCE_DIR}/LinkerObject.cpp
${ORIGINAL_SOURCE_DIR}/LinkerObject.h
LinkerObject.cpp
LinkerObject.h
${ORIGINAL_SOURCE_DIR}/PathGasMeter.cpp
${ORIGINAL_SOURCE_DIR}/PathGasMeter.h
${ORIGINAL_SOURCE_DIR}/PeepholeOptimiser.cpp
Expand Down
4 changes: 2 additions & 2 deletions libevmasm/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ static std::map<Instruction, InstructionInfo> const c_instructionInfo =
{ Instruction::CALLCODE, { "CALLCODE", 0, 5, 1, true, Tier::Special } },

{ Instruction::RETURN, { "RETURN", 0, 2, 0, true, Tier::Zero } },
{ Instruction::DELEGATECALL, { "DELEGATECALL", 0, 6, 1, true, Tier::Special } },
{ Instruction::DELEGATECALL, { "DELEGATECALL", 0, 5, 1, true, Tier::Special } },

// Solidity++:
{ Instruction::SYNCCALL, { "SYNCCALL", 0, 6, 0, true, Tier::Special } },
{ Instruction::CALLBACKDEST, { "CALLBACKDEST", 0, 0, 0, true, Tier::Special } },
{ Instruction::CALLBACKDEST, { "CALLBACKDEST", 0, 0, 1, true, Tier::Special } },

{ Instruction::STATICCALL, { "STATICCALL", 0, 6, 1, true, Tier::Special } },
{ Instruction::CREATE2, { "CREATE2", 0, 4, 1, true, Tier::Special } },
Expand Down
92 changes: 92 additions & 0 deletions libevmasm/LinkerObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
This file is part of solidity.
solidity 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
(at your option) any later version.
solidity 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 solidity. If not, see <http://www.gnu.org/licenses/>.
*/
// SPDX-License-Identifier: GPL-3.0
/** @file LinkerObject.cpp
* @author Christian R <c@ethdev.com>
* @date 2015
*/

#include <libevmasm/LinkerObject.h>
#include <libsolutil/CommonData.h>
#include <libsolutil/Keccak256.h>

using namespace std;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::evmasm;

void LinkerObject::append(LinkerObject const& _other)
{
for (auto const& ref: _other.linkReferences)
linkReferences[ref.first + bytecode.size()] = ref.second;
bytecode += _other.bytecode;
}

// Solidity++: 168-bit address
void LinkerObject::link(map<string, h168> const& _libraryAddresses)
{
std::map<size_t, std::string> remainingRefs;
for (auto const& linkRef: linkReferences)
if (h168 const* address = matchLibrary(linkRef.second, _libraryAddresses))
copy(address->data(), address->data() + 20, bytecode.begin() + vector<uint8_t>::difference_type(linkRef.first));
else
remainingRefs.insert(linkRef);
linkReferences.swap(remainingRefs);
}

string LinkerObject::toHex() const
{
string hex = solidity::util::toHex(bytecode);
for (auto const& ref: linkReferences)
{
size_t pos = ref.first * 2;
string hash = libraryPlaceholder(ref.second);
hex[pos] = hex[pos + 1] = hex[pos + 38] = hex[pos + 39] = '_';
// Solidity++: Vite use 168-bit address, placeholder is end with '____'
hex[pos + 40] = hex[pos + 41] = '_';

for (size_t i = 0; i < 36; ++i)
hex[pos + 2 + i] = hash.at(i);
}
return hex;
}

string LinkerObject::libraryPlaceholder(string const& _libraryName)
{
return "$" + keccak256(_libraryName).hex().substr(0, 34) + "$";
}

// Solidity++: 168-bit address
h168 const*
LinkerObject::matchLibrary(
string const& _linkRefName,
map<string, h168> const& _libraryAddresses
)
{
auto it = _libraryAddresses.find(_linkRefName);
if (it != _libraryAddresses.end())
return &it->second;
// If the user did not supply a fully qualified library name,
// try to match only the simple library name
size_t colon = _linkRefName.find(':');
if (colon == string::npos)
return nullptr;
it = _libraryAddresses.find(_linkRefName.substr(colon + 1));
if (it != _libraryAddresses.end())
return &it->second;
return nullptr;
}
71 changes: 71 additions & 0 deletions libevmasm/LinkerObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
This file is part of solidity.
solidity 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
(at your option) any later version.
solidity 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 solidity. If not, see <http://www.gnu.org/licenses/>.
*/
// SPDX-License-Identifier: GPL-3.0
/** @file Assembly.h
* @author Gav Wood <i@gavwood.com>
* @date 2014
*/

#pragma once

#include <libsolutil/Common.h>
#include <libsolutil/FixedHash.h>

namespace solidity::evmasm
{

/**
* Binary object that potentially still needs to be linked (i.e. addresses of other contracts
* need to be filled in).
*/
struct LinkerObject
{
/// The bytecode.
bytes bytecode;

/// Map from offsets in bytecode to library identifiers. The addresses starting at those offsets
/// need to be replaced by the actual addresses by the linker.
std::map<size_t, std::string> linkReferences;

/// Map from hashes of the identifiers of immutable variables to the full identifier of the immutable and
/// to a list of offsets into the bytecode that refer to their values.
std::map<u256, std::pair<std::string, std::vector<size_t>>> immutableReferences;

/// Appends the bytecode of @a _other and incorporates its link references.
void append(LinkerObject const& _other);

/// Links the given libraries by replacing their uses in the code and removes them from the references.
void link(std::map<std::string, util::h168> const& _libraryAddresses); // Solidity++: 168-bit address

/// @returns a hex representation of the bytecode of the given object, replacing unlinked
/// addresses by placeholders. This output is lowercase.
std::string toHex() const;

/// @returns a 36 character string that is used as a placeholder for the library
/// address (enclosed by `__` on both sides). The placeholder is the hex representation
/// of the first 18 bytes of the keccak-256 hash of @a _libraryName.
static std::string libraryPlaceholder(std::string const& _libraryName);

private:
// Solidity++: 168-bit address
static util::h168 const* matchLibrary(
std::string const& _linkRefName,
std::map<std::string, util::h168> const& _libraryAddresses
);
};

}
10 changes: 2 additions & 8 deletions liblangutil/Token.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ namespace solidity::langutil
K(Send, "send", 0) \
\
K(Event, "event", 0) \
/* Solidity++: message keyword */ \
K(Message, "message", 0) \
/* Solidity++: offchain keyword */ \
K(Offchain, "offchain", 0) \
\
K(External, "external", 0) \
K(Fallback, "fallback", 0) \
Expand Down Expand Up @@ -201,7 +197,7 @@ namespace solidity::langutil
T(BytesM, "bytesM", 0) \
T(FixedMxN, "fixedMxN", 0) \
T(UFixedMxN, "ufixedMxN", 0) \
K(TokenId, "tokenId", 0) /* Solidity++: Vite token id */ \
K(TokenId, "vitetoken", 0) /* Solidity++: Vite token id */ \
T(TypesEnd, nullptr, 0) /* used as type enum end marker */ \
\
/* Literals */ \
Expand Down Expand Up @@ -250,8 +246,6 @@ namespace solidity::langutil
K(Var, "var", 0) \
\
/* Solidity++ keywords */ \
K(OnMessage, "onMessage", 0) \
K(Getter, "getter", 0) \
K(Async, "async", 0) \
K(Await, "await", 0) \
\
Expand Down Expand Up @@ -294,7 +288,7 @@ namespace TokenTraits
constexpr bool isCountOp(Token op) { return op == Token::Inc || op == Token::Dec; }
constexpr bool isShiftOp(Token op) { return (Token::SHL <= op) && (op <= Token::SHR); }
constexpr bool isVariableVisibilitySpecifier(Token op) { return op == Token::Public || op == Token::Private || op == Token::Internal; }
constexpr bool isVisibilitySpecifier(Token op) { return isVariableVisibilitySpecifier(op) || op == Token::External || op == Token::Offchain; } // Solidity++: add offchain visibility
constexpr bool isVisibilitySpecifier(Token op) { return isVariableVisibilitySpecifier(op) || op == Token::External; }
constexpr bool isLocationSpecifier(Token op) { return op == Token::Memory || op == Token::Storage || op == Token::CallData; }

constexpr bool isStateMutabilitySpecifier(Token op)
Expand Down
39 changes: 24 additions & 15 deletions libsolidity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ set(ORIGINAL_SOURCE_DIR ${PROJECT_SOURCE_DIR}/solidity/libsolidity)
set(sources
${ORIGINAL_SOURCE_DIR}/analysis/ConstantEvaluator.cpp
${ORIGINAL_SOURCE_DIR}/analysis/ConstantEvaluator.h
analysis/ContractLevelChecker.cpp
analysis/ContractLevelChecker.h
${ORIGINAL_SOURCE_DIR}/analysis/ContractLevelChecker.cpp
${ORIGINAL_SOURCE_DIR}/analysis/ContractLevelChecker.h
${ORIGINAL_SOURCE_DIR}/analysis/ControlFlowAnalyzer.cpp
${ORIGINAL_SOURCE_DIR}/analysis/ControlFlowAnalyzer.h
${ORIGINAL_SOURCE_DIR}/analysis/ControlFlowBuilder.cpp
Expand Down Expand Up @@ -34,25 +34,34 @@ set(sources
${ORIGINAL_SOURCE_DIR}/analysis/Scoper.h
${ORIGINAL_SOURCE_DIR}/analysis/StaticAnalyzer.cpp
${ORIGINAL_SOURCE_DIR}/analysis/StaticAnalyzer.h
analysis/SyntaxChecker.cpp
${ORIGINAL_SOURCE_DIR}/analysis/SyntaxChecker.h
analysis/TypeChecker.cpp
analysis/SolidityppSyntaxChecker.cpp
analysis/SolidityppSyntaxChecker.h
${ORIGINAL_SOURCE_DIR}/analysis/SyntaxChecker.cpp
analysis/SyntaxChecker.h
analysis/SolidityppTypeChecker.cpp
analysis/SolidityppTypeChecker.h
${ORIGINAL_SOURCE_DIR}/analysis/TypeChecker.cpp
analysis/TypeChecker.h
${ORIGINAL_SOURCE_DIR}/analysis/ViewPureChecker.cpp
${ORIGINAL_SOURCE_DIR}/analysis/ViewPureChecker.h
ast/AST.cpp
ast/AST.h
ast/AST_accept.h
ast/SolidityppAST.cpp
ast/SolidityppAST.h
${ORIGINAL_SOURCE_DIR}/ast/AST_accept.h
ast/SolidityppAST_accept.h
${ORIGINAL_SOURCE_DIR}/ast/ASTAnnotations.cpp
ast/ASTAnnotations.h
ast/ASTEnums.h
ast/ASTForward.h
ast/ASTJsonConverter.cpp
ast/SolidityppASTJsonConverter.cpp
ast/SolidityppASTJsonConverter.h
${ORIGINAL_SOURCE_DIR}/ast/ASTJsonConverter.cpp
ast/ASTJsonConverter.h
${ORIGINAL_SOURCE_DIR}/ast/ASTUtils.cpp
${ORIGINAL_SOURCE_DIR}/ast/ASTUtils.h
ast/ASTJsonImporter.cpp
ast/ASTJsonImporter.h
${ORIGINAL_SOURCE_DIR}/ast/ASTJsonImporter.cpp
${ORIGINAL_SOURCE_DIR}/ast/ASTJsonImporter.h
ast/ASTVisitor.h
${ORIGINAL_SOURCE_DIR}/ast/ExperimentalFeatures.h
ast/Types.cpp
Expand Down Expand Up @@ -122,8 +131,8 @@ set(sources
${ORIGINAL_SOURCE_DIR}/formal/SymbolicVariables.h
${ORIGINAL_SOURCE_DIR}/formal/VariableUsage.cpp
${ORIGINAL_SOURCE_DIR}/formal/VariableUsage.h
interface/ABI.cpp
interface/ABI.h
${ORIGINAL_SOURCE_DIR}/interface/ABI.cpp
${ORIGINAL_SOURCE_DIR}/interface/ABI.h
interface/CompilerStack.cpp
interface/CompilerStack.h
${ORIGINAL_SOURCE_DIR}/interface/DebugSettings.h
Expand All @@ -133,12 +142,12 @@ set(sources
${ORIGINAL_SOURCE_DIR}/interface/Natspec.h
${ORIGINAL_SOURCE_DIR}/interface/OptimiserSettings.h
${ORIGINAL_SOURCE_DIR}/interface/ReadFile.h
${ORIGINAL_SOURCE_DIR}/interface/StandardCompiler.cpp
${ORIGINAL_SOURCE_DIR}/interface/StandardCompiler.h
interface/StandardCompiler.cpp
interface/StandardCompiler.h
${ORIGINAL_SOURCE_DIR}/interface/StorageLayout.cpp
${ORIGINAL_SOURCE_DIR}/interface/StorageLayout.h
${ORIGINAL_SOURCE_DIR}/interface/Version.cpp
${ORIGINAL_SOURCE_DIR}/interface/Version.h
interface/Version.cpp
interface/Version.h
${ORIGINAL_SOURCE_DIR}/parsing/DocStringParser.cpp
${ORIGINAL_SOURCE_DIR}/parsing/DocStringParser.h
parsing/Parser.cpp
Expand Down
Loading

0 comments on commit 345c843

Please sign in to comment.