mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-06 16:17:11 +00:00
some panics, dont panic on invalid opcode
This commit is contained in:
+2
-8
@@ -53,10 +53,7 @@ func sha256Func(input []byte, gas *int64) (output []byte, err error) {
|
||||
// Hash
|
||||
hasher := sha256.New()
|
||||
// CONTRACT: this does not err
|
||||
_, err = hasher.Write(input)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
hasher.Write(input)
|
||||
return hasher.Sum(nil), nil
|
||||
}
|
||||
|
||||
@@ -71,10 +68,7 @@ func ripemd160Func(input []byte, gas *int64) (output []byte, err error) {
|
||||
// Hash
|
||||
hasher := ripemd160.New()
|
||||
// CONTRACT: this does not err
|
||||
_, err = hasher.Write(input)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
hasher.Write(input)
|
||||
return LeftPadBytes(hasher.Sum(nil), 32), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -90,11 +90,16 @@ func (vm *VM) EnablePermissions() {
|
||||
vm.perms = true
|
||||
}
|
||||
|
||||
// XXX: it is the duty of the contract writer to call known permissions
|
||||
// we do not convey if a permission is not set
|
||||
// (unlike in state/execution, where we guarantee HasPermission is called
|
||||
// on known permissions and panics else)
|
||||
func HasPermission(appState AppState, acc *Account, perm ptypes.PermFlag) bool {
|
||||
v, err := acc.Permissions.Base.Get(perm)
|
||||
if _, ok := err.(ptypes.ErrValueNotSet); ok {
|
||||
if appState == nil {
|
||||
panic(fmt.Sprintf("Global permission value not set for %b", perm))
|
||||
fmt.Printf("\n\n***** Unknown permission %b! ********\n\n", perm)
|
||||
return false
|
||||
}
|
||||
return HasPermission(nil, appState.GetAccount(ptypes.GlobalPermissionsAddress256), perm)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user