Browse Source

some panics, dont panic on invalid opcode

pull/102/head
Ethan Buchman 10 years ago
committed by Jae Kwon
parent
commit
8d6f80592b
4 changed files with 17 additions and 20 deletions
  1. +8
    -10
      state/execution.go
  2. +1
    -1
      state/genesis.go
  3. +2
    -8
      vm/native.go
  4. +6
    -1
      vm/vm.go

+ 8
- 10
state/execution.go View File

@ -293,15 +293,6 @@ func adjustByOutputs(accounts map[string]*account.Account, outs []*types.TxOutpu
// If the tx is invalid, an error will be returned.
// Unlike ExecBlock(), state will not be altered.
func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Fireable) error {
defer func() {
if r := recover(); r != nil {
err := errors.New(Fmt("Recovered from panic in ExecTx", "err", r, "tx", tx_))
log.Error(err.Error())
// TODO return error
}
}()
// TODO: do something with fees
fees := int64(0)
_s := blockCache.State() // hack to access validators and block height
@ -822,6 +813,10 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
// Get permission on an account or fall back to global value
func HasPermission(state AccountGetter, acc *account.Account, perm ptypes.PermFlag) bool {
if perm > ptypes.AllBasePermissions {
panic("Checking an unknown permission in state should never happen")
}
if acc == nil {
// TODO
// this needs to fall back to global or do some other specific things
@ -830,7 +825,10 @@ func HasPermission(state AccountGetter, acc *account.Account, perm ptypes.PermFl
v, err := acc.Permissions.Base.Get(perm)
if _, ok := err.(ptypes.ErrValueNotSet); ok {
return HasPermission(state, state.GetAccount(ptypes.GlobalPermissionsAddress), perm)
if state == nil {
panic("All known global permissions should be set!")
}
return HasPermission(nil, state.GetAccount(ptypes.GlobalPermissionsAddress), perm)
}
return v
}


+ 1
- 1
state/genesis.go View File

@ -108,7 +108,7 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State {
if genDoc.Params != nil && genDoc.Params.GlobalPermissions != nil {
globalPerms = genDoc.Params.GlobalPermissions
// XXX: make sure the set bits are all true
// Without it the HasPermission() functions will recurse till death
// Without it the HasPermission() functions will fail
globalPerms.Base.SetBit = ptypes.AllSet
}


+ 2
- 8
vm/native.go 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
vm/vm.go 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)
}


Loading…
Cancel
Save