Skip to content

Commit

Permalink
Merge pull request hyperledger-archives#476 from VoR0220/fixesSNative…
Browse files Browse the repository at this point in the history
…CallsFromSolc

issue-476: return One256 for EXTCODESIZE on native contracts
  • Loading branch information
silasdavis authored Feb 8, 2017
2 parents f278b24 + a4d01f6 commit 325e91d
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions manager/eris-mint/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ import (
)

var (
ErrUnknownAddress = errors.New("Unknown address")
ErrInsufficientBalance = errors.New("Insufficient balance")
ErrInvalidJumpDest = errors.New("Invalid jump dest")
ErrInsufficientGas = errors.New("Insufficient gas")
ErrMemoryOutOfBounds = errors.New("Memory out of bounds")
ErrCodeOutOfBounds = errors.New("Code out of bounds")
ErrInputOutOfBounds = errors.New("Input out of bounds")
ErrCallStackOverflow = errors.New("Call stack overflow")
ErrCallStackUnderflow = errors.New("Call stack underflow")
ErrDataStackOverflow = errors.New("Data stack overflow")
ErrDataStackUnderflow = errors.New("Data stack underflow")
ErrInvalidContract = errors.New("Invalid contract")
ErrUnknownAddress = errors.New("Unknown address")
ErrInsufficientBalance = errors.New("Insufficient balance")
ErrInvalidJumpDest = errors.New("Invalid jump dest")
ErrInsufficientGas = errors.New("Insufficient gas")
ErrMemoryOutOfBounds = errors.New("Memory out of bounds")
ErrCodeOutOfBounds = errors.New("Code out of bounds")
ErrInputOutOfBounds = errors.New("Input out of bounds")
ErrCallStackOverflow = errors.New("Call stack overflow")
ErrCallStackUnderflow = errors.New("Call stack underflow")
ErrDataStackOverflow = errors.New("Data stack overflow")
ErrDataStackUnderflow = errors.New("Data stack underflow")
ErrInvalidContract = errors.New("Invalid contract")
ErrNativeContractCodeCopy = errors.New("Tried to copy native contract code")
)

type ErrPermission struct {
Expand Down Expand Up @@ -567,20 +568,28 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas
}
acc := vm.appState.GetAccount(addr)
if acc == nil {
return nil, firstErr(err, ErrUnknownAddress)
if _, ok := registeredNativeContracts[addr]; !ok {
return nil, firstErr(err, ErrUnknownAddress)
}
dbg.Printf(" => returning code size of 1 to indicated existence of native contract at %X\n", addr)
stack.Push(One256)
} else {
code := acc.Code
l := int64(len(code))
stack.Push64(l)
dbg.Printf(" => %d\n", l)
}
code := acc.Code
l := int64(len(code))
stack.Push64(l)
dbg.Printf(" => %d\n", l)

case EXTCODECOPY: // 0x3C
addr := stack.Pop()
if useGasNegative(gas, GasGetAccount, &err) {
return nil, err
}
acc := vm.appState.GetAccount(addr)
if acc == nil {
if _, ok := registeredNativeContracts[addr]; ok {
dbg.Printf(" => attempted to copy native contract at %X but this is not supported\n", addr)
return nil, firstErr(err, ErrNativeContractCodeCopy)
}
return nil, firstErr(err, ErrUnknownAddress)
}
code := acc.Code
Expand Down

0 comments on commit 325e91d

Please sign in to comment.