在evm中使用solidity合约中调用其他solodity合约报jump out of range错
【问题分类】
- [] bug
- P2P网络相关(包含libp2p,liquid)
- 链账户身份与权限相关(证书问题、public、多签投票问题)
- 核心交易引擎相关(交易池、DAG)
- 共识相关
- 智能合约相关
- 存储相关
- SDK相关
- 长安链CMC工具
- 长安链管理台
- 长安链浏览器
- 长安链合约IDE
- 长安链web签名插件
- 跨链相关
- 轻节点相关
- 隐私计算相关
- 密码学相关
- 环境依赖
- 其他补充:
【问题描述】(请对问题进行描述,方便定位问题)
在已部署的solidity合约中,通过传入已部署的合约地址,通过call方法调用其他合约中的方法报jump out of range 错,下附合约源码
pragma solidity >=0.4.22 <0.6.0;
contract Test {
function callOtherContract(address contractAddress,string memory method,string memory n)public returns(bytes memory result)
{
bool success;
(success, result) = contractAddress.call( abi.encodeWithSignature(method, n));
return result;
}
function get() public view returns(string memory){
return "1111";
}
}
pragma solidity >=0.5.0 <0.6.0;
contract HelloWorld {
string name = "HelloWorld!";
constructor(string memory n) public {
name = n;
}
function get() public view returns (string memory) {
return name;
}
function set(string memory n) public {
name = n;
}
function get1(string memory s) public pure returns (string memory) {
return s;
}
function get2(string memory s1, string memory s2) public pure returns (string memory) {
return string(abi.encodePacked(s1, s2));
}
}
附java代码实现
public static String deployHelloWorld(ChainClient chainClient) throws Exception {
ResultOuterClass.TxResponse responseInfo = null;
String contractAddress = calculateContractAddress("HelloWorld");
try {
byte[] byteCode = FileUtils.getResourceFileBytes("HelloWorld.bin");
Function selectFunction = new Function("", Arrays.asList(new Utf8String("HellWordld2023")), Collections.emptyList());
String selectFunctionEncode = FunctionEncoder.encode(selectFunction);
Map<String, byte[]> queryParamMap = new HashMap<>();
queryParamMap.put("data", selectFunctionEncode.getBytes());
System.out.println("hello world contract address:" + contractAddress);
Request.Payload payload = chainClient.createContractCreatePayload(contractAddress, "1", byteCode,
ContractOuterClass.RuntimeType.EVM, queryParamMap );
Request.EndorsementEntry[] endorsementEntries = SdkUtils
.getEndorsers(payload, new User[]{chainClient.getClientUser()});
responseInfo = chainClient.sendContractManageRequest(payload, endorsementEntries, 10000, 10000);
System.out.println("response:" + responseInfo.toString());
} catch (Exception e) {
e.printStackTrace();
}
Function selectFunction = new Function("get", Collections.emptyList(),
Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {
}));
String selectFunctionEncode = FunctionEncoder.encode(selectFunction);
String selectFunctionId = selectFunctionEncode.substring(0, 10);
Map<String, byte[]> queryParamMap = new HashMap<>();
queryParamMap.put("data", selectFunctionEncode.getBytes());
ResultOuterClass.TxResponse result = chainClient.invokeContract(contractAddress, selectFunctionId, null, queryParamMap, 300000, 300000);
String hexString = Hex.toHexString(result.getContractResult().getResult().toByteArray());
System.out.println("hex string:" + hexString);
List<Type> decode = FunctionReturnDecoder.decode(hexString, selectFunction.getOutputParameters());
String value = (String) decode.get(0).getValue();
System.out.println("result:" + value);
return contractAddress;
}
public static void deployTest(ChainClient chainClient,String contractAddress) throws Exception {
ResultOuterClass.TxResponse responseInfo = null;
Thread.sleep(3000L);
String testAddress = calculateContractAddress("Test");
try {
byte[] byteCode = FileUtils.getResourceFileBytes("Test.bin");
Request.Payload payload = chainClient.createContractCreatePayload(testAddress, "1", byteCode,
ContractOuterClass.RuntimeType.EVM, null);
Request.EndorsementEntry[] endorsementEntries = SdkUtils
.getEndorsers(payload, new User[]{chainClient.getClientUser()});
responseInfo = chainClient.sendContractManageRequest(payload, endorsementEntries, 10000, 10000);
System.out.println("response:" + responseInfo.toString());
} catch (Exception e) {
e.printStackTrace();
}
Function function = new Function("get", Collections.emptyList(),
Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {
}));
String methodDataStr = FunctionEncoder.encode(function);
HashMap<String, byte[]> params = new HashMap<>();
String methodId = methodDataStr.substring(0, 10);
params.put("data", methodDataStr.getBytes());
ResultOuterClass.TxResponse result = chainClient.invokeContract(testAddress, methodId, null, params, 3000, 3000);
System.out.println("result:" + result);
String hexString = Hex.toHexString(result.getContractResult().getResult().toByteArray());
List<Type> getResult = FunctionReturnDecoder.decode(hexString, function.getOutputParameters());
System.out.println("0x1:"+(String)getResult.get(0).getValue());
Function callFunction = new Function("callOtherContract", Arrays.asList(new Address(contractAddress),new Utf8String("get1(string)"),new Utf8String("123")),
Arrays.<TypeReference<?>>asList(new TypeReference<DynamicBytes>() {
}));
String callMethod = FunctionEncoder.encode(callFunction);
HashMap<String, byte[]> callParams = new HashMap<>();
String callMethodId = callMethod.substring(0, 10);
callParams.put("data", callMethod.getBytes());
ResultOuterClass.TxResponse callResult = chainClient.invokeContract(testAddress, callMethodId, null, callParams, 3000, 3000);
System.out.println("result:" + callResult);
String callHex = Hex.toHexString(callResult.getContractResult().getResult().toByteArray());
System.out.println("hex string:"+callHex);
}
在调用过程中会报错误,错误异常如下
result:message: "OK"
contract_result {
code: 1
message: "jump out of range"
}
具体的现象,操作步骤,前置条件等,尽可能描述清楚,有截图说明更佳
【相关日志文件】(如果有报错日志请贴图,或者上传附件)
chainmaker-go 的 log/system.log & bin/panic.log file * system.log.2023081818 SDK 的 sdk.log file
【系统信息】(请填写系统信息,方便定位问题)
- chainmaker-go version * : [v2.3.0]
- OS & version * :
- docker镜像 version:
-
管理台 version:
- 如果是管理台的相关问题,请附带管理台版本,如果不是可忽略。
-
区块浏览器 version:
- 如果是浏览器的相关问题,请附带浏览器版本,如果不是可忽略。
-
合约IDE version:
- 如果是合约IDE的相关问题,请附带合约IDE版本,如果不是可忽略。
-
web签名插件 version:
- 如果是web签名插件的相关问题,请附带web签名插件版本,如果不是可忽略。
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information