mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-20 11:46:44 +00:00
parent
f230c8259b
commit
3cba3a2dca
5 changed files with 44 additions and 1 deletions
|
|
@ -421,6 +421,14 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
|
|||
break;
|
||||
}
|
||||
|
||||
case Instruction::SHA3:
|
||||
{
|
||||
auto inOff = stack.pop();
|
||||
auto inSize = stack.pop();
|
||||
auto hash = ext.sha3(inOff, inSize);
|
||||
stack.push(hash);
|
||||
}
|
||||
|
||||
case Instruction::POP:
|
||||
{
|
||||
stack.pop();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include <llvm/IR/TypeBuilder.h>
|
||||
#include <llvm/IR/IntrinsicInst.h>
|
||||
|
||||
#include <libdevcrypto/SHA3.h>
|
||||
|
||||
#include "Runtime.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
|
@ -90,6 +92,7 @@ Ext::Ext(llvm::IRBuilder<>& _builder, llvm::Module* module)
|
|||
Type* args[] = {i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy};
|
||||
m_call = Function::Create(FunctionType::get(m_builder.getVoidTy(), args, false), Linkage::ExternalLinkage, "ext_call", module);
|
||||
m_bswap = Intrinsic::getDeclaration(module, Intrinsic::bswap, i256Ty);
|
||||
m_sha3 = Function::Create(TypeBuilder<void(i<256>*, i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_sha3", module);
|
||||
|
||||
|
||||
m_builder.CreateCall(m_init, m_data);
|
||||
|
|
@ -182,6 +185,17 @@ llvm::Value* Ext::call(llvm::Value* _gas, llvm::Value* _receiveAddress, llvm::Va
|
|||
return m_builder.CreateLoad(m_args[1]);
|
||||
}
|
||||
|
||||
llvm::Value* Ext::sha3(llvm::Value* _inOff, llvm::Value* _inSize)
|
||||
{
|
||||
m_builder.CreateStore(_inOff, m_args[0]);
|
||||
m_builder.CreateStore(_inSize, m_arg2);
|
||||
llvm::Value* args[] = {m_args[0], m_arg2, m_args[1]};
|
||||
m_builder.CreateCall(m_sha3, args);
|
||||
Value* hash = m_builder.CreateLoad(m_args[1]);
|
||||
hash = bswap(hash); // to LE
|
||||
return hash;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
|
|
@ -285,6 +299,15 @@ EXPORT void ext_call(i256* _gas, h256* _receiveAddress, i256* _value, i256* _inO
|
|||
_ret->a = ret ? 1 : 0;
|
||||
}
|
||||
|
||||
EXPORT void ext_sha3(i256* _inOff, i256* _inSize, i256* _ret)
|
||||
{
|
||||
auto inOff = static_cast<size_t>(llvm2eth(*_inOff));
|
||||
auto inSize = static_cast<size_t>(llvm2eth(*_inSize));
|
||||
auto dataRef = dev::bytesConstRef(Runtime::getMemory().data() + inOff, inSize);
|
||||
auto hash = dev::eth::sha3(dataRef);
|
||||
*_ret = *reinterpret_cast<i256*>(&hash);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ public:
|
|||
llvm::Value* create(llvm::Value* _endowment, llvm::Value* _initOff, llvm::Value* _initSize);
|
||||
llvm::Value* call(llvm::Value* _gas, llvm::Value* _receiveAddress, llvm::Value* _value, llvm::Value* _inOff, llvm::Value* _inSize, llvm::Value* _outOff, llvm::Value* _outSize);
|
||||
|
||||
llvm::Value* sha3(llvm::Value* _inOff, llvm::Value* _inSize);
|
||||
|
||||
private:
|
||||
llvm::Value* getDataElem(unsigned _index, const llvm::Twine& _name = "");
|
||||
|
||||
|
|
@ -63,6 +65,7 @@ private:
|
|||
llvm::Function* m_create;
|
||||
llvm::Function* m_call;
|
||||
llvm::Function* m_bswap;
|
||||
llvm::Function* m_sha3;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
5a3031333234363a4041424344455a36600035602635601335387f1111222233334444555566667777888899990000aaaabbbbccccddddeeeeffff600054602060006000f06020600060206000600030610bb8f130ff60016002f2
|
||||
5a3031333234363a4041424344455a36600035602635601335387f1111222233334444555566667777888899990000aaaabbbbccccddddeeeeffff600054602060006000f06020600060206000600030610bb8f1600053611000545b60200260002030ff60016002f2
|
||||
|
|
|
|||
|
|
@ -38,6 +38,15 @@ CREATE
|
|||
ADDRESS
|
||||
3000
|
||||
CALL
|
||||
0
|
||||
MLOAD
|
||||
4096
|
||||
MSTORE
|
||||
MSIZE
|
||||
32
|
||||
MUL
|
||||
0
|
||||
SHA3
|
||||
ADDRESS
|
||||
SUICIDE
|
||||
1
|
||||
|
|
|
|||
Loading…
Reference in a new issue