-
-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Labels
Description
Bounty
Calling checkSpendingCondition to calculate the outputs of a transaction returns a misleading error message, e.g.:
{
"jsonrpc": "2.0",
"id": 666,
"result": {
"error": "outputs do not match computation results. \n outputs \n calculated: {\"address\":\"0x513ab0d35ea18a8a36f16d7e7762b61f893c34ba\",\"value\":\"99999978434176\",\"color\":0}",
"outputs": [
{
"address": "0x513ab0d35ea18a8a36f16d7e7762b61f893c34ba",
"value": "99999978434176",
"color": 0
}
]
}
}As you can see, result.error says:
outputs do not match computation results.
outputs
calculated: {"address":"0x513ab0d35ea18a8a36f16d7e7762b61f893c34ba","value":"99999978434176","color":0}
And result.outputs is:
[
{
"address": "0x513ab0d35ea18a8a36f16d7e7762b61f893c34ba",
"value": "99999978434176",
"color": 0
}
]
(The only difference between the value in result.error and result.outputs is that the latter is wrapped in an array).
How to reproduce
The steps are:
- create and compile a simple contract
- put some leap in it
- call
checkSpendingConditionon a method of the contract
Check the bug on the testnet
I've already put some leap on the target contract. You can try to reproduce it in the test network by running:
curl --data '{"jsonrpc":"2.0","id":666,"method":"checkSpendingCondition","params":["0x0d10b3cc080bbe22f955c421221709a3e9f97ff784dde5d125943cd805b07dc8a65a0000249b8305ef000000000000000000000000000000000000000000000000000000000000003700fd6080604052348015600f57600080fd5b506004361060285760003560e01c80639b8305ef14602d575b600080fd5b605660048036036020811015604157600080fd5b81019080803590602001909291905050506058565b005b602a81141560ce576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600d8152602001807f53746f702069742c206e6572640000000000000000000000000000000000000081525060200191505060405180910390fd5b5056fea165627a7a72305820141f4c20603edb2e2cf296ae7baa8542d658b46711765b6c9da9fbeb58c11df50029"]}' -H "Content-Type: application/json" -X POST https://testnet-node.leapdao.orgActual code
The script I use to reproduce the error is the following:
const Web3 = require("web3");
const { Tx, Input, helpers } = require("leap-core");
const { bufferToHex, ripemd160 } = require("ethereumjs-util");
const web3 = helpers.extendWeb3(new Web3("https://testnet-node.leapdao.org"));
const privateKey = "MY PRIVATE KEY";
const wallet = web3.eth.accounts.privateKeyToAccount(privateKey);
const abi = [
{
constant: false,
inputs: [
{
name: "a",
type: "uint256"
}
],
name: "aMethod",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
}
];
let deployedBytecode =
"0x6080604052348015600f57600080fd5b506004361060285760003560e01c80639b8305ef14602d575b600080fd5b605660048036036020811015604157600080fd5b81019080803590602001909291905050506058565b005b602a81141560ce576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600d8152602001807f53746f702069742c206e6572640000000000000000000000000000000000000081525060200191505060405180910390fd5b5056fea165627a7a72305820141f4c20603edb2e2cf296ae7baa8542d658b46711765b6c9da9fbeb58c11df50029";
const contractAddress = bufferToHex(ripemd160(deployedBytecode));
console.log(contractAddress);
deployedBytecode = Buffer.from(deployedBytecode.replace("0x", ""), "hex");
async function send() {
const leapOutput = await web3.getUnspent(contractAddress, 0);
const inputs = [
{
prevout: leapOutput[0].outpoint,
script: deployedBytecode,
address: contractAddress
}
];
const contract = new web3.eth.Contract(abi);
const data = contract.methods.aMethod(55).encodeABI();
console.log(data);
let transaction = Tx.spendCond(
inputs.map(input => {
const i = new Input(input);
i.address = input.address;
return i;
})
);
transaction.inputs[0].setMsgData(data);
transaction = transaction.signAll(privateKey);
//transaction = signMatching(transaction, privateKey);
//
console.log(
JSON.stringify({
jsonrpc: "2.0",
id: 666,
method: "checkSpendingCondition",
params: [transaction.hex()]
})
);
web3.currentProvider.send(
{
jsonrpc: "2.0",
id: 666,
method: "checkSpendingCondition",
params: [transaction.hex()]
},
(err, response) => {
if (err) {
throw new Error("smth went wrong", err.toString());
}
console.log("checkSpendingCondition", err, JSON.stringify(response));
}
);
}
send();Scope
- reproduce and fix the issue
Deliverables
- fix the issue 😃
Gain for the project
Less confused devs.
Roles
bounty gardener: @vrde / 15%
bounty worker: name / share
bounty reviewer: name / share
Reactions are currently unavailable