some panics, dont panic on invalid opcode

This commit is contained in:
Ethan Buchman
2015-07-07 14:11:21 -07:00
committed by Jae Kwon
parent 415c12fca5
commit 8d6f80592b
4 changed files with 17 additions and 20 deletions
+2 -8
View File
@@ -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
}
+6 -1
View File
@@ -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)
}