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

issue-476: return One256 for EXTCODESIZE on native contracts #476

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thus far we have not returned a code size for native contracts. Is this motivated by a change in solidity, where it newly checks the code length before going to a contract. We have not had a problem before calling our snative contracts. Can you document and elaborate?

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