Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into restructure-oei
Browse files Browse the repository at this point in the history
  • Loading branch information
sorawit committed Jun 22, 2020
2 parents b6e5b57 + 38463db commit 2bd9afe
Show file tree
Hide file tree
Showing 31 changed files with 832 additions and 1,162 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- (imprv) [\#1924](https://github.com/bandprotocol/bandchain/pull/1924) Shorten bonded token amount on validator home page
- (bug) [\#1918](https://github.com/bandprotocol/bandchain/pull/1918) Fix UI overlap, word, chainIDBadge
- (feat) [\#1913](https://github.com/bandprotocol/bandchain/pull/1913) Add uptime bar on Validator Home Page
- (imprv) [\#1911](https://github.com/bandprotocol/bandchain/pull/1911) Use validator moniker instead of validator address on Account page.
- (imprv) [\#1904](https://github.com/bandprotocol/bandchain/pull/1904) Added helper tooltips.
- (imprv) [\#1900](https://github.com/bandprotocol/bandchain/pull/1900) Shorten marketcap amount on landing page
- (feat) [\#1888](https://github.com/bandprotocol/bandchain/pull/1888) Added OBI bindings and patched scan to use OBI standard
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### Chain

- (patch) [\#2037](https://github.com/bandprotocol/bandchain/pull/2037) Patch Multistore proof to new structure tree of 0.38.
- (impv) [\#1892](https://github.com/bandprotocol/bandchain/pull/1892) Rewrite execution environment for wasmer
- (patch) [\#1999](https://github.com/bandprotocol/bandchain/pull/1999) Patch to Cosmos-SDK 0.38.4
- (impv) [\#1981](https://github.com/bandprotocol/bandchain/pull/1981) Remove gas price refund for report transactions.
Expand All @@ -28,8 +29,10 @@
- (bugs) [\#1996](https://github.com/bandprotocol/bandchain/pull/1996) Fix id bug on `RequestSub.re`
- (chore) [\#1987](https://github.com/bandprotocol/bandchain/pull/1987) Remove `request_tab_t` in `Route.re`
- (impv) [\#1986](https://github.com/bandprotocol/bandchain/pull/1986) Add autofocus input on submittx modal
- (impv) [\#1970](https://github.com/bandprotocol/bandchain/pull/1970) Update oracle script bridge code generator to use Obi standard
- (feat) [\#1985](https://github.com/bandprotocol/bandchain/pull/1985) Add redelegate button and submit transaction modal
- (chore) [\#1982](https://github.com/bandprotocol/bandchain/pull/1982) Update network on `ChainIDBadge.re`
- (impv) [\#1970](https://github.com/bandprotocol/bandchain/pull/1970) Update oracle script bridge code generator to use Obi standard
- (impv) [\#1958](https://github.com/bandprotocol/bandchain/pull/1958) Add human-readable error when broadcast tx, fix withdraw reward msg on guanyu
- (impv) [\#1940](https://github.com/bandprotocol/bandchain/pull/1940) Trim Address input, remind user when sending token to themself
- (impv) [\#1939](https://github.com/bandprotocol/bandchain/pull/1939) Use Format.re on user balance
Expand All @@ -43,6 +46,7 @@
### Owasm

- (impv) [\#2026](https://github.com/bandprotocol/bandchain/pull/2026) Remove get_calldata_size and get_external_data_size from OEI.
- (chore) [\#2025](https://github.com/bandprotocol/bandchain/pull/2025) Cleanup code documentation and error messages
- (feat) [\#1998](https://github.com/bandprotocol/bandchain/pull/1998) Implement safe guard to check import and export from wasm
- (feat) [\#1994](https://github.com/bandprotocol/bandchain/pull/1994) Implement inject stack height when compile wasm code.
- (feat) [\#1988](https://github.com/bandprotocol/bandchain/pull/1988) Implement safe guard to check memory limit from wasm
Expand Down
78 changes: 44 additions & 34 deletions chain/client/proof/multi_store.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
package proof

import (
bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/store/rootmulti"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/evidence"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/cosmos/cosmos-sdk/x/upgrade"
"github.com/ethereum/go-ethereum/common"
"github.com/tendermint/tendermint/crypto/merkle"
tmbytes "github.com/tendermint/tendermint/libs/bytes"

"github.com/bandprotocol/bandchain/chain/x/oracle"
)

type MultiStoreProof struct {
AccToMemCapStoresMerkleHash tmbytes.HexBytes `json:"accToMemCapStoresMerkleHash"`
MintStoresMerkleHash tmbytes.HexBytes `json:"mintStoresMerkleHash"`
AccToGovStoresMerkleHash tmbytes.HexBytes `json:"accToGovStoresMerkleHash"`
MainAndMintStoresMerkleHash tmbytes.HexBytes `json:"mainAndMintStoresMerkleHash"`
OracleIAVLStateHash tmbytes.HexBytes `json:"oracleIAVLStateHash"`
ParamsAndSlashingStoresMerkleHash tmbytes.HexBytes `json:"paramsAndSlashingStoresMerkleHash"`
StakingAndUpgradeStoresMerkleHash tmbytes.HexBytes `json:"stakingAndUpgradeStoresMerkleHash"`
ParamsStoresMerkleHash tmbytes.HexBytes `json:"paramsStoresMerkleHash"`
SlashingToUpgradeStoresMerkleHash tmbytes.HexBytes `json:"slashingToUpgradeStoresMerkleHash"`
}

type MultiStoreProofEthereum struct {
AccToMemCapStoresMerkleHash common.Hash
MintStoresMerkleHash common.Hash
AccToGovStoresMerkleHash common.Hash
MainAndMintStoresMerkleHash common.Hash
OracleIAVLStateHash common.Hash
ParamsAndSlashingStoresMerkleHash common.Hash
StakingAndUpgradeStoresMerkleHash common.Hash
ParamsStoresMerkleHash common.Hash
SlashingToUpgradeStoresMerkleHash common.Hash
}

func (m *MultiStoreProof) encodeToEthFormat() MultiStoreProofEthereum {
return MultiStoreProofEthereum{
AccToMemCapStoresMerkleHash: common.BytesToHash(m.AccToMemCapStoresMerkleHash),
MintStoresMerkleHash: common.BytesToHash(m.MintStoresMerkleHash),
AccToGovStoresMerkleHash: common.BytesToHash(m.AccToGovStoresMerkleHash),
MainAndMintStoresMerkleHash: common.BytesToHash(m.MainAndMintStoresMerkleHash),
OracleIAVLStateHash: common.BytesToHash(m.OracleIAVLStateHash),
ParamsAndSlashingStoresMerkleHash: common.BytesToHash(m.ParamsAndSlashingStoresMerkleHash),
StakingAndUpgradeStoresMerkleHash: common.BytesToHash(m.StakingAndUpgradeStoresMerkleHash),
ParamsStoresMerkleHash: common.BytesToHash(m.ParamsStoresMerkleHash),
SlashingToUpgradeStoresMerkleHash: common.BytesToHash(m.SlashingToUpgradeStoresMerkleHash),
}
}

Expand All @@ -38,27 +52,23 @@ func GetMultiStoreProof(proof rootmulti.MultiStoreProofOp) MultiStoreProof {
m[info.Name] = info.Core.CommitID.Hash
}
return MultiStoreProof{
// AccToMemCapStoresMerkleHash: merkle.SimpleHashFromByteSlices([][]byte{
// encodeStoreMerkleHash(auth.StoreKey, m[auth.StoreKey]),
// encodeStoreMerkleHash(bank.StoreKey, m[bank.StoreKey]),
// encodeStoreMerkleHash(capability.StoreKey, m[capability.StoreKey]),
// encodeStoreMerkleHash(distribution.StoreKey, m[distribution.StoreKey]),
// encodeStoreMerkleHash(evidence.StoreKey, m[evidence.StoreKey]),
// encodeStoreMerkleHash(gov.StoreKey, m[gov.StoreKey]),
// encodeStoreMerkleHash(ibc.StoreKey, m[ibc.StoreKey]),
// encodeStoreMerkleHash(capability.MemStoreKey, m[capability.MemStoreKey]),
// }),
// MintStoresMerkleHash: merkle.SimpleHashFromByteSlices([][]byte{
// encodeStoreMerkleHash(mint.StoreKey, m[mint.StoreKey]),
// }),
// OracleIAVLStateHash: m[oracle.StoreKey],
// ParamsAndSlashingStoresMerkleHash: merkle.SimpleHashFromByteSlices([][]byte{
// encodeStoreMerkleHash(params.StoreKey, m[params.StoreKey]),
// encodeStoreMerkleHash(slashing.StoreKey, m[slashing.StoreKey]),
// }),
// StakingAndUpgradeStoresMerkleHash: merkle.SimpleHashFromByteSlices([][]byte{
// encodeStoreMerkleHash(staking.StoreKey, m[staking.StoreKey]),
// encodeStoreMerkleHash(upgrade.StoreKey, m[upgrade.StoreKey]),
// }),
AccToGovStoresMerkleHash: merkle.SimpleHashFromByteSlices([][]byte{
encodeStoreMerkleHash(auth.StoreKey, m[auth.StoreKey]),
encodeStoreMerkleHash(distribution.StoreKey, m[distribution.StoreKey]),
encodeStoreMerkleHash(evidence.StoreKey, m[evidence.StoreKey]),
encodeStoreMerkleHash(gov.StoreKey, m[gov.StoreKey]),
}),
MainAndMintStoresMerkleHash: merkle.SimpleHashFromByteSlices([][]byte{
encodeStoreMerkleHash(bam.MainStoreKey, m[bam.MainStoreKey]),
encodeStoreMerkleHash(mint.StoreKey, m[mint.StoreKey]),
}),
OracleIAVLStateHash: m[oracle.StoreKey],
ParamsStoresMerkleHash: merkle.SimpleHashFromByteSlices([][]byte{encodeStoreMerkleHash(params.StoreKey, m[params.StoreKey])}),
SlashingToUpgradeStoresMerkleHash: merkle.SimpleHashFromByteSlices([][]byte{
encodeStoreMerkleHash(slashing.StoreKey, m[slashing.StoreKey]),
encodeStoreMerkleHash(staking.StoreKey, m[staking.StoreKey]),
encodeStoreMerkleHash(supply.StoreKey, m[supply.StoreKey]),
encodeStoreMerkleHash(upgrade.StoreKey, m[upgrade.StoreKey]),
}),
}
}
65 changes: 33 additions & 32 deletions chain/client/proof/multi_store_test.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
package proof

// import (
// "testing"
import (
"testing"

// "github.com/cosmos/cosmos-sdk/store/rootmulti"
// "github.com/stretchr/testify/require"
// "github.com/tendermint/tendermint/crypto/merkle"
// "github.com/tendermint/tendermint/crypto/tmhash"
// )
"github.com/cosmos/cosmos-sdk/store/rootmulti"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/crypto/tmhash"
)

// func TestGetMultiStoreProof(t *testing.T) {
// multiStoreProofOp, err := rootmulti.MultiStoreProofOpDecoder(merkle.ProofOp{
// Type: "multistore",
// Key: base64ToBytes("b3JhY2xl"), // oracle
// Data: base64ToBytes("CpcECi4KBGJhbmsSJgokCE8SIFFp5VJl0pN7IB1zm+c7wc160Ev58w29dDHjWZahsS4NChAKDm1lbV9jYXBhYmlsaXR5CjYKDGRpc3RyaWJ1dGlvbhImCiQITxIgLgd/rDfToCd79w5sMBEd5Cz0Wx9T8tz5P0T7imhrxacKMQoHc3Rha2luZxImCiQITxIgWyzwEPdl+6QjNsYAPuWt5s3ygu2rT6Wf755pFPA3ZLMKCwoDaWJjEgQKAghPChIKCmNhcGFiaWxpdHkSBAoCCE8KLgoEbWludBImCiQITxIgn0Ay9in3n018bViYNvakJPGs5NBNApBDJlanzTkoQV8KMAoGcGFyYW1zEiYKJAhPEiD2mMDOrO1Ai0IdR5wU1o/oe9Z6lAATKJaOgfGPNre8UQoQCghldmlkZW5jZRIECgIITwoyCghzbGFzaGluZxImCiQITxIgL+ePlJmSe0nErlzaVL1/XwR5JA0T2kLjsqb/yDCngXUKLQoDZ292EiYKJAhPEiBgzRN8GWLsrGFjidaANIM/KSFQnC0oWqX1FTmXzpaKdAotCgNhY2MSJgokCE8SIDGAt5a/EEkpGtM+eLElNyck5q0BIu0WYE21u2j6bVReCg8KB3VwZ3JhZGUSBAoCCE8KMAoGb3JhY2xlEiYKJAhPEiCywp9PjsehPrpPthUq4Ef1OiNCgJcaQIGwONL8PDs+2A=="),
// })
// require.Nil(t, err)
// mp := GetMultiStoreProof(multiStoreProofOp.(rootmulti.MultiStoreProofOp))
// expectAppHash := hexToBytes("396EC5A6D5D66C0EA13BB6D5BDE8A01D80F78F3BB73D62C2F71BC14DD8B18095")
// oraclePrefix := hexToBytes("066f7261636c6520")
// appHash := branchHash(
// mp.AccToMemCapStoresMerkleHash,
// branchHash(
// branchHash(
// branchHash(
// mp.MintStoresMerkleHash,
// leafHash(append(oraclePrefix, tmhash.Sum(tmhash.Sum(mp.OracleIAVLStateHash))...)),
// ),
// mp.ParamsAndSlashingStoresMerkleHash,
// ),
// mp.StakingAndUpgradeStoresMerkleHash,
// ),
// )
// require.Equal(t, expectAppHash, appHash)
// }
func TestGetMultiStoreProof(t *testing.T) {
multiStoreProofOp, err := rootmulti.MultiStoreProofOpDecoder(merkle.ProofOp{
Type: "multistore",
Key: base64ToBytes("b3JhY2xl"), // oracle
Data: base64ToBytes("pQQKogQKLgoDZ292EicKJQiWAhIgYM0TfBli7KxhY4nWgDSDPykhUJwtKFql9RU5l86WinQKMwoIc2xhc2hpbmcSJwolCJYCEiBfW/Loa4v0ZtxLkuWPQUbz6SVJuKg/E7X4EiG7Hkj/rwovCgRtYWluEicKJQiWAhIgI5l329mAyqoP1+RHld/OmKTaBPWa9NSaifZ6D3aCybsKNwoMZGlzdHJpYnV0aW9uEicKJQiWAhIgAnl+IKwaWnB6M5DPJxnTu+vh51ghtz16f0p4hpsklVEKMQoGcGFyYW1zEicKJQiWAhIgtxWMDPGF+SS8y9rUgmfiSnGykZ3birnksXSJLVsKgn8KLgoDYWNjEicKJQiWAhIgUYQhvmWNF7BiiczyeWHl2ErSxi7AwryrVx1NwhzagfYKMQoGc3VwcGx5EicKJQiWAhIgySh5gpbubLQHNcPKTpNN/CuKDkESvM+1XcfaGw+fydgKMQoGb3JhY2xlEicKJQiWAhIgFTrjBbDFiOtarT5oX7dAsnD9KH7OCLzIXWaPyxDjwfUKEAoHdXBncmFkZRIFCgMIlgIKMgoHc3Rha2luZxInCiUIlgISIPSPOKwdrwBrRV3dGze5ZM0VjHqf6K/7E1E1gjPQTQvcChEKCGV2aWRlbmNlEgUKAwiWAgovCgRtaW50EicKJQiWAhIgVoD/WGhQAMfwiRBMeyy0n/eg11aKq5Aof00pfjTRqCs="),
})
require.Nil(t, err)
mp := GetMultiStoreProof(multiStoreProofOp.(rootmulti.MultiStoreProofOp))
// Must get app hash from next block of multi proof.
expectAppHash := hexToBytes("0DEF6341481C4370D561D546C268FB6AFED8520689B70ABC615C47CFB2A0EEE8")
oraclePrefix := hexToBytes("066f7261636c6520")
appHash := branchHash(
branchHash(
mp.AccToGovStoresMerkleHash,
branchHash(
mp.MainAndMintStoresMerkleHash,
branchHash(
leafHash(append(oraclePrefix, tmhash.Sum(tmhash.Sum(mp.OracleIAVLStateHash))...)),
mp.ParamsStoresMerkleHash,
),
),
),
mp.SlashingToUpgradeStoresMerkleHash,
)
require.Equal(t, expectAppHash, appHash)
}
18 changes: 9 additions & 9 deletions chain/x/oracle/types/exec_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (env *BaseEnv) GetCalldata() []byte {

// SetReturnData implements Owasm ExecEnv interface.
func (env *BaseEnv) SetReturnData(data []byte) error {
return api.ErrSetReturnDataWrongPeriod
return api.ErrWrongPeriodAction
}

// GetAskCount implements Owasm ExecEnv interface.
Expand All @@ -31,22 +31,22 @@ func (env *BaseEnv) GetMinCount() int64 {

// GetAnsCount implements Owasm ExecEnv interface.
func (env *BaseEnv) GetAnsCount() (int64, error) {
return 0, api.ErrAnsCountWrongPeriod
return 0, api.ErrWrongPeriodAction
}

// AskExternalData implements Owasm ExecEnv interface.
func (env *BaseEnv) AskExternalData(eid int64, did int64, data []byte) error {
return api.ErrAskExternalDataWrongPeriod
return api.ErrWrongPeriodAction
}

// GetExternalDataStatus implements Owasm ExecEnv interface.
func (env *PrepareEnv) GetExternalDataStatus(eid int64, vid int64) (int64, error) {
return 0, api.ErrGetExternalDataStatusWrongPeriod
return 0, api.ErrWrongPeriodAction
}

// GetExternalData implements Owasm ExecEnv interface.
func (env *PrepareEnv) GetExternalData(eid int64, vid int64) ([]byte, error) {
return nil, api.ErrGetExternalDataWrongPeriod
return nil, api.ErrWrongPeriodAction
}

// PrepareEnv implements ExecEnv interface only expected function and panic on non-prepare functions.
Expand All @@ -69,10 +69,10 @@ func NewPrepareEnv(req Request, maxRawRequests int64) *PrepareEnv {
// AskExternalData implements Owasm ExecEnv interface.
func (env *PrepareEnv) AskExternalData(eid int64, did int64, data []byte) error {
if int64(len(data)) > MaxRawRequestDataSize {
return api.ErrSpanExceededCapacity
return api.ErrSpanTooSmall
}
if int64(len(env.rawRequests)) >= env.maxRawRequests {
return api.ErrAskExternalDataExceed
return api.ErrTooManyExternalData
}
env.rawRequests = append(env.rawRequests, NewRawRequest(
ExternalID(eid), DataSourceID(did), data,
Expand Down Expand Up @@ -126,7 +126,7 @@ func (env *ExecuteEnv) SetReturnData(data []byte) error {

func (env *ExecuteEnv) getExternalDataFull(eid int64, valIdx int64) ([]byte, int64, error) {
if valIdx < 0 || valIdx >= int64(len(env.request.RequestedValidators)) {
return nil, 0, api.ErrValidatorOutOfRange
return nil, 0, api.ErrBadValidatorIndex
}
valAddr := env.request.RequestedValidators[valIdx].String()
valReports, ok := env.reports[valAddr]
Expand All @@ -135,7 +135,7 @@ func (env *ExecuteEnv) getExternalDataFull(eid int64, valIdx int64) ([]byte, int
}
valReport, ok := valReports[ExternalID(eid)]
if !ok {
return nil, -1, api.ErrInvalidExternalID
return nil, -1, api.ErrBadExternalID
}
return valReport.Data, int64(valReport.ExitCode), nil
}
Expand Down
14 changes: 7 additions & 7 deletions chain/x/oracle/types/exec_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestSetReturnData(t *testing.T) {

penv := mockFreshPrepareEnv()
err := penv.SetReturnData(result)
require.Equal(t, api.ErrSetReturnDataWrongPeriod, err)
require.Equal(t, api.ErrWrongPeriodAction, err)

eenv := mockExecEnv()
eenv.SetReturnData(result)
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestGetAnsCount(t *testing.T) {
// Should return error if call on prepare environment.
penv := mockFreshPrepareEnv()
_, err := penv.GetAnsCount()
require.Equal(t, api.ErrAnsCountWrongPeriod, err)
require.Equal(t, api.ErrWrongPeriodAction, err)

eenv := mockExecEnv()
v, err := eenv.GetAnsCount()
Expand All @@ -139,9 +139,9 @@ func TestGetExternalData(t *testing.T) {
require.Equal(t, int64(-1), status)

_, err = env.GetExternalData(1, 100)
require.Equal(t, api.ErrValidatorOutOfRange, err)
require.Equal(t, api.ErrBadValidatorIndex, err)
_, err = env.GetExternalDataStatus(1, 100)
require.Equal(t, api.ErrValidatorOutOfRange, err)
require.Equal(t, api.ErrBadValidatorIndex, err)

_, err = env.GetExternalData(1, -1)
require.Error(t, err)
Expand All @@ -158,9 +158,9 @@ func TestFailedGetExternalData(t *testing.T) {
penv := mockAlreadyPreparedEnv()

_, err := penv.GetExternalData(1, 1)
require.Equal(t, api.ErrGetExternalDataWrongPeriod, err)
require.Equal(t, api.ErrWrongPeriodAction, err)
_, err = penv.GetExternalDataStatus(1, 1)
require.Equal(t, api.ErrGetExternalDataStatusWrongPeriod, err)
require.Equal(t, api.ErrWrongPeriodAction, err)
}

func TestAskExternalData(t *testing.T) {
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestAskExternalDataOnExecEnv(t *testing.T) {
env := mockExecEnv()
calldata := []byte("CALLDATA")
err := env.AskExternalData(2, 2, calldata)
require.Equal(t, api.ErrAskExternalDataWrongPeriod, err)
require.Equal(t, api.ErrWrongPeriodAction, err)
}

func TestGetRawRequests(t *testing.T) {
Expand Down
Loading

0 comments on commit 2bd9afe

Please sign in to comment.