From 9ce5b1b3d71835860b3ecb81cd0cf0e2d7b39fd4 Mon Sep 17 00:00:00 2001 From: Silas Davis <silas@erisindustries.com> Date: Sat, 6 May 2017 19:34:37 +0100 Subject: [PATCH] change hasBase to bool return as intended and add check for native contracts to simulated call (for query-contract) --- manager/burrow-mint/evm/native.go | 4 ++-- manager/burrow-mint/evm/snative.go | 2 +- manager/burrow-mint/pipe.go | 5 +++++ manager/burrow-mint/state/execution.go | 5 ++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/manager/burrow-mint/evm/native.go b/manager/burrow-mint/evm/native.go index ab4e3207..17478055 100644 --- a/manager/burrow-mint/evm/native.go +++ b/manager/burrow-mint/evm/native.go @@ -24,8 +24,8 @@ import ( var registeredNativeContracts = make(map[Word256]NativeContract) -func RegisteredNativeContract(addr Word256) bool { - _, ok := registeredNativeContracts[addr] +func RegisteredNativeContract(address Word256) bool { + _, ok := registeredNativeContracts[address] return ok } diff --git a/manager/burrow-mint/evm/snative.go b/manager/burrow-mint/evm/snative.go index 37e1031c..ab7e68a4 100644 --- a/manager/burrow-mint/evm/snative.go +++ b/manager/burrow-mint/evm/snative.go @@ -165,7 +165,7 @@ func SNativeContracts() map[string]*SNativeContractDescription { []abi.Arg{ arg("_account", abi.AddressTypeName), arg("_permission", permFlagTypeName)}, - ret("result", permFlagTypeName), + ret("result", abi.BoolTypeName), ptypes.HasBase, hasBase}, diff --git a/manager/burrow-mint/pipe.go b/manager/burrow-mint/pipe.go index e81fa8a3..70910582 100644 --- a/manager/burrow-mint/pipe.go +++ b/manager/burrow-mint/pipe.go @@ -409,6 +409,11 @@ func (pipe *burrowMintPipe) DumpStorage(address []byte) (*rpc_tm_types.ResultDum // TODO: [ben] resolve incompatibilities in byte representation for 0.12.0 release func (pipe *burrowMintPipe) Call(fromAddress, toAddress, data []byte) (*rpc_tm_types.ResultCall, error) { + if vm.RegisteredNativeContract(word256.LeftPadWord256(toAddress)) { + return nil, fmt.Errorf("Attempt to call native contract at address "+ + "%X, but native contracts can not be called directly. Use a deployed "+ + "contract that calls the native function instead.", toAddress) + } st := pipe.burrowMint.GetState() cache := state.NewBlockCache(st) outAcc := cache.GetAccount(toAddress) diff --git a/manager/burrow-mint/state/execution.go b/manager/burrow-mint/state/execution.go index 9fc20e55..edda1cb7 100644 --- a/manager/burrow-mint/state/execution.go +++ b/manager/burrow-mint/state/execution.go @@ -431,7 +431,10 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable } // check if its a native contract if vm.RegisteredNativeContract(LeftPadWord256(tx.Address)) { - return fmt.Errorf("NativeContracts can not be called using CallTx. Use a contract or the appropriate tx type (eg. PermissionsTx, NameTx)") + return fmt.Errorf("Attempt to call a native contract at %X, "+ + "but native contracts cannot be called using CallTx. Use a "+ + "contract that calls the native contract or the appropriate tx "+ + "type (eg. PermissionsTx, NameTx).", tx.Address) } // Output account may be nil if we are still in mempool and contract was created in same block as this tx -- GitLab