mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-17 23:21:21 +00:00
(╯°□°)╯︵ ┻━┻
This commit is contained in:
@ -31,7 +31,10 @@ func (w Word256) Compare(other Word256) int {
|
||||
|
||||
func Uint64ToWord256(i uint64) Word256 {
|
||||
word := Word256{}
|
||||
PutUint64(word[:], i)
|
||||
buf := [8]byte{}
|
||||
PutUint64(buf[:], i)
|
||||
word[24], word[25], word[26], word[27] = buf[7], buf[6], buf[5], buf[4]
|
||||
word[28], word[29], word[30], word[31] = buf[3], buf[2], buf[1], buf[0]
|
||||
return word
|
||||
}
|
||||
|
||||
@ -46,7 +49,10 @@ func LeftPadWord256(bz []byte) (word Word256) {
|
||||
}
|
||||
|
||||
func Uint64FromWord256(word Word256) uint64 {
|
||||
return binary.LittleEndian.Uint64(word[:])
|
||||
buf := [8]byte{}
|
||||
buf[0], buf[1], buf[2], buf[3] = word[31], word[30], word[29], word[28]
|
||||
buf[4], buf[5], buf[6], buf[7] = word[27], word[26], word[25], word[24]
|
||||
return binary.LittleEndian.Uint64(buf[:])
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
@ -36,7 +36,7 @@ func GetStorage(address, key []byte) (*ctypes.ResponseGetStorage, error) {
|
||||
storageRoot := account.StorageRoot
|
||||
storageTree := state.LoadStorage(storageRoot)
|
||||
|
||||
_, value := storageTree.Get(RightPadWord256(key).Bytes())
|
||||
_, value := storageTree.Get(LeftPadWord256(key).Bytes())
|
||||
if value == nil {
|
||||
return &ctypes.ResponseGetStorage{key, nil}, nil
|
||||
}
|
||||
|
@ -12,11 +12,11 @@ import (
|
||||
|
||||
func toVMAccount(acc *account.Account) *vm.Account {
|
||||
return &vm.Account{
|
||||
Address: RightPadWord256(acc.Address),
|
||||
Address: LeftPadWord256(acc.Address),
|
||||
Balance: acc.Balance,
|
||||
Code: acc.Code, // This is crazy.
|
||||
Nonce: uint64(acc.Sequence),
|
||||
StorageRoot: RightPadWord256(acc.StorageRoot),
|
||||
StorageRoot: LeftPadWord256(acc.StorageRoot),
|
||||
Other: acc.PubKey,
|
||||
}
|
||||
}
|
||||
@ -26,7 +26,6 @@ func toVMAccount(acc *account.Account) *vm.Account {
|
||||
// Run a contract's code on an isolated and unpersisted state
|
||||
// Cannot be used to create new contracts
|
||||
func Call(address, data []byte) (*ctypes.ResponseCall, error) {
|
||||
|
||||
st := consensusState.GetState() // performs a copy
|
||||
cache := mempoolReactor.Mempool.GetCache()
|
||||
outAcc := cache.GetAccount(address)
|
||||
@ -38,7 +37,7 @@ func Call(address, data []byte) (*ctypes.ResponseCall, error) {
|
||||
txCache := state.NewTxCache(cache)
|
||||
params := vm.Params{
|
||||
BlockHeight: uint64(st.LastBlockHeight),
|
||||
BlockHash: RightPadWord256(st.LastBlockHash),
|
||||
BlockHash: LeftPadWord256(st.LastBlockHash),
|
||||
BlockTime: st.LastBlockTime.Unix(),
|
||||
GasLimit: 10000000,
|
||||
}
|
||||
@ -63,7 +62,7 @@ func CallCode(code, data []byte) (*ctypes.ResponseCall, error) {
|
||||
txCache := state.NewTxCache(cache)
|
||||
params := vm.Params{
|
||||
BlockHeight: uint64(st.LastBlockHeight),
|
||||
BlockHash: RightPadWord256(st.LastBlockHash),
|
||||
BlockHash: LeftPadWord256(st.LastBlockHash),
|
||||
BlockTime: st.LastBlockTime.Unix(),
|
||||
GasLimit: 10000000,
|
||||
}
|
||||
|
@ -288,7 +288,7 @@ func simpleContract() ([]byte, []byte, []byte) {
|
||||
// the is the code we need to return the contractCode when the contract is initialized
|
||||
lenCode := len(contractCode)
|
||||
// push code to the stack
|
||||
//code := append([]byte{byte(0x60 + lenCode - 1)}, LeftPadWord256(contractCode).Bytes()...)
|
||||
//code := append([]byte{byte(0x60 + lenCode - 1)}, RightPadWord256(contractCode).Bytes()...)
|
||||
code := append([]byte{0x7f}, RightPadWord256(contractCode).Bytes()...)
|
||||
// store it in memory
|
||||
code = append(code, []byte{0x60, 0x0, 0x52}...)
|
||||
|
@ -119,8 +119,8 @@ func testGetStorage(t *testing.T, typ string) {
|
||||
mempoolCount = 0
|
||||
|
||||
v := getStorage(t, typ, contractAddr, []byte{0x1})
|
||||
got := RightPadWord256(v)
|
||||
expected := RightPadWord256([]byte{0x5})
|
||||
got := LeftPadWord256(v)
|
||||
expected := LeftPadWord256([]byte{0x5})
|
||||
if got.Compare(expected) != 0 {
|
||||
t.Fatalf("Wrong storage value. Got %x, expected %x", got.Bytes(), expected.Bytes())
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ func (cache *BlockCache) GetStorage(addr Word256, key Word256) (value Word256) {
|
||||
_, val_ := storage.Get(key.Bytes())
|
||||
value = Zero256
|
||||
if val_ != nil {
|
||||
value = RightPadWord256(val_.([]byte))
|
||||
value = LeftPadWord256(val_.([]byte))
|
||||
}
|
||||
cache.storages[Tuple256{addr, key}] = storageInfo{value, false}
|
||||
return value
|
||||
|
@ -395,7 +395,7 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
|
||||
txCache = NewTxCache(blockCache)
|
||||
params = vm.Params{
|
||||
BlockHeight: uint64(_s.LastBlockHeight),
|
||||
BlockHash: RightPadWord256(_s.LastBlockHash),
|
||||
BlockHash: LeftPadWord256(_s.LastBlockHash),
|
||||
BlockTime: _s.LastBlockTime.Unix(),
|
||||
GasLimit: 10000000,
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ func toVMAccount(acc *ac.Account) *vm.Account {
|
||||
Balance: acc.Balance,
|
||||
Code: acc.Code, // This is crazy.
|
||||
Nonce: uint64(acc.Sequence),
|
||||
StorageRoot: RightPadWord256(acc.StorageRoot),
|
||||
StorageRoot: LeftPadWord256(acc.StorageRoot),
|
||||
Other: acc.PubKey,
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func ecrecoverFunc(input []byte, gas *uint64) (output []byte, err error) {
|
||||
return nil, err
|
||||
}
|
||||
hashed := sha3.Sha3(recovered[1:])
|
||||
return RightPadBytes(hashed, 32), nil
|
||||
return LeftPadBytes(hashed, 32), nil
|
||||
}
|
||||
|
||||
func sha256Func(input []byte, gas *uint64) (output []byte, err error) {
|
||||
@ -73,7 +73,7 @@ func ripemd160Func(input []byte, gas *uint64) (output []byte, err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return RightPadBytes(hasher.Sum(nil), 32), nil
|
||||
return LeftPadBytes(hasher.Sum(nil), 32), nil
|
||||
}
|
||||
|
||||
func identityFunc(input []byte, gas *uint64) (output []byte, err error) {
|
||||
|
@ -51,7 +51,7 @@ func (st *Stack) PushBytes(bz []byte) {
|
||||
if len(bz) != 32 {
|
||||
panic("Invalid bytes size: expected 32")
|
||||
}
|
||||
st.Push(RightPadWord256(bz))
|
||||
st.Push(LeftPadWord256(bz))
|
||||
}
|
||||
|
||||
func (st *Stack) Push64(i uint64) {
|
||||
@ -73,7 +73,8 @@ func (st *Stack) PopBytes() []byte {
|
||||
}
|
||||
|
||||
func (st *Stack) Pop64() uint64 {
|
||||
return GetUint64(st.Pop().Bytes())
|
||||
d := st.Pop()
|
||||
return Uint64FromWord256(d)
|
||||
}
|
||||
|
||||
func (st *Stack) Len() int {
|
||||
|
@ -90,5 +90,5 @@ func createAddress(creator *Account) Word256 {
|
||||
temp := make([]byte, 32+8)
|
||||
copy(temp, creator.Address[:])
|
||||
PutUint64(temp[32:], nonce)
|
||||
return RightPadWord256(sha3.Sha3(temp)[:20])
|
||||
return LeftPadWord256(sha3.Sha3(temp)[:20])
|
||||
}
|
||||
|
@ -64,10 +64,10 @@ func TestSubcurrency(t *testing.T) {
|
||||
st := newAppState()
|
||||
// Create accounts
|
||||
account1 := &Account{
|
||||
Address: RightPadWord256(makeBytes(20)),
|
||||
Address: LeftPadWord256(makeBytes(20)),
|
||||
}
|
||||
account2 := &Account{
|
||||
Address: RightPadWord256(makeBytes(20)),
|
||||
Address: LeftPadWord256(makeBytes(20)),
|
||||
}
|
||||
st.accounts[account1.Address.String()] = account1
|
||||
st.accounts[account2.Address.String()] = account2
|
||||
|
Reference in New Issue
Block a user