小白求教,在remix上部署合约成功调用,但本地私链虽然能正常部署但是调用时出现了invalid opcode: RETURNDATASIZE 的问题。 网上找资料改了几次后还是这样。之前看到说可能是数组没初始化,可测试函数几个数组应该都正常初始化赋值了。 求解!
//本地私链调用结果
//remix VM上运行结果
智能合约如下:
实现简单的Merkle树路径验证
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.4.0;
pragma experimental ABIEncoderV2;
contract MerkleTreePDP {
bytes32 public rootHash;
event VerificationResult(address indexed sender ,bool success);
function verifyProof(bytes32[] memory leaves, bytes32[][] memory proofs,bool[][] memory locations) public view returns (bool) {
require(leaves.length == proofs.length, "Invalid input");
for (uint256 i = 0; i < leaves.length; i++) {
require(verifySingleProof(leaves[i], proofs[i],locations[i]), "Proof verification failed");
}
return true;
}
function verifySingleProof(bytes32 leaf, bytes32[] memory proof,bool[] memory location) public view returns (bool) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
bytes32 proofElement = proof[i];
if (location[i]) {
computedHash = sha256(abi.encodePacked(computedHash, proofElement));
} else {
computedHash = sha256(abi.encodePacked(proofElement, computedHash));
}
}
return computedHash == rootHash;
}
function requestVerification(bytes32[] memory leaves, bytes32[][] memory proofs, bytes32 hash,bool[][] memory locations) public view returns (bool) {
rootHash = hash;
bool result = verifyProof(leaves, proofs, locations);
emit VerificationResult(msg.sender,result);
return result;
}
function testRequestVerification() public {
bytes32[] memory leaves = new bytes32[](1);
leaves[0] = 0x6b23c0d5f35d1b11f9b683f0b0a617355deb11277d91ae091d399c655b87940d;
bytes32[][] memory proofs = new bytes32[][](1);
proofs[0] = new bytes32[](2);
proofs[0][0] = 0x3f39d5c348e5b79d06e842c114e6cc571583bbf44e4b0ebfda1a01ec05745d43;
proofs[0][1] = 0x63956f0ce48edc48a0d528cb0b5d58e4d625afb14d63ca1bb9950eb657d61f40;
bool[][] memory locations = new bool[][](1);
locations[0] = new bool[](2);
locations[0][0] = true;
locations[0][1] = false;
bytes32 hash = 0x1b3faa3fcc5ed50cd8592f805c6f8fce976b8582c739b26a6f3613b7f9b13617;
bool result = requestVerification(leaves, proofs, hash, locations);
emit VerificationResult(msg.sender, result);
} }