-
Notifications
You must be signed in to change notification settings - Fork 344
issue-476: return One256 for EXTCODESIZE on native contracts #476
issue-476: return One256 for EXTCODESIZE on native contracts #476
Conversation
Could you be a bit clearer with "problem with not being able to get at the Snative contract.", what problem prompted your investigation here? It does seem like there can be a problem here and your solution will in some sense work. However this is a special case of a broader problem. That is making sure we have some special case handling for snatives. The other obvious place this will be an issue is https://github.com/eris-ltd/eris-db/blob/master/manager/eris-mint/evm/vm.go#L583 in fact What is the context of use here? Pretending a native contract exists and has code length 1 may make certain code execute, but it doesn't make it make any sense, seems ad hoc, and does nothing to allow you to treat native contracts as if they have code accessible in contract-space. It seems like the best thing to do here might be to just make in an error. But we need more context about where this was encountered. Another place where we don't check whether we are dealing with an snative, and perhaps we should is in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need a proper understanding of the motivating changes in solc; if for snative contracts we would need to return a non-error; then we need to first understand what should be returned;
@@ -565,13 +565,17 @@ 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 { |
There was a problem hiding this comment.
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?
manager/eris-mint/evm/vm.go
Outdated
if _, ok := registeredNativeContracts[addr]; !ok { | ||
return nil, firstErr(err, ErrUnknownAddress) | ||
} | ||
stack.Push64(int64(1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More idiomatic and a little more efficient to use stack.Push(One256) here
Here's a fragment of solc 4.4.0 compiled bytecode that helps illuminate what the solidity compiler is up to:
Here's the relevant line in the solidity compiler that generates this type of code: https://github.com/ethereum/solidity/blob/develop/libsolidity/codegen/ExpressionCompiler.cpp#L1662 The check amounts to an existence check for the contract/contract code before running it. I am not certain why this is, but it seems like in the current pricing model it might be better to check the code exists before calling empty code. Worth checking. In this compiler case returning any truthy value seems to be the right thing to do, and 1 is probably the most elegant. There is a worry with how this interacts with If someone is deliberately trying to access snative code from an |
manager/eris-mint/evm/vm.go
Outdated
} else { | ||
code := acc.Code | ||
l := int64(len(code)) | ||
stack.Push64(l) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, I think this should be stack.Push(One256)
it saves doing the conversion to use the constant, and it is used elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual code length for normal contracts that are not natives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should stay as it is.
LGTM |
Signed-off-by: RJ Catalano <rj@monax.io>
Signed-off-by: RJ Catalano <rj@monax.io>
Signed-off-by: RJ Catalano <rj@monax.io>
8dcb9d0
to
9e141fa
Compare
…CallsFromSolc issue-476: return One256 for EXTCODESIZE on native contracts
Fixes problem with not being able to get at the Snative contract.
Signed-off-by: RJ Catalano rj@monax.io