Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

stack overflow in Call method of vm.go #1224

Closed
madiazp opened this issue Aug 22, 2019 · 11 comments
Closed

stack overflow in Call method of vm.go #1224

madiazp opened this issue Aug 22, 2019 · 11 comments

Comments

@madiazp
Copy link

madiazp commented Aug 22, 2019

Hi.

I'm currently using the fabric-chaincode-evm. I've deployed a smartcontract which has a function like this:
"dd129313": "verifyTx(uint256[2],uint256[2][2],uint256[2],uint256[1])"

So when the chaincode use the vm.Call to call it I got a runtime error:

error 9 - call stack overflow: int64 overflow from word: �������������������������������l

the argument of the verifyTx is something like this: dd12931324ea66eccb0af86fac0422d914240bc576d0ae0f6ea1cbe60737393f4b93562c05ae9a7fa7371cde3aaa92cc3bc953c152a7312d6e56f382b3c922e5959707f41faf45da658fc9ffd9fb741707366515dafe7b5bd45a3462984e22736eaf38b12c44eb99df7eaa9fff456e0a42799acdbd41ecde0e4c5239e970c10565a847ed2b91804dc2138235e4521eacd0a13bd604a39054b3e10d38ba56734df24c4c4a2eef134e22ad618834c0a179c925252612e624528943c1a2a78fe42d56b962322d342cdd65ef0320eb3a07e22299731ba085151b6383e9acd5f0e1ac7a3530892e8549dce4604fc4b551110c07e72dfae1dca032cecdd1d2f6aa15394506db2e0000000000000000000000000000000000000000000000000000000000000001

And the contract code is

: Click to expand 608060405234801561001057600080fd5b50611176806100206000396000f3fe60806040526004361061003b576000357c010000000000000000000000000000000000000000000000000000000090048063dd12931314610040575b600080fd5b34801561004c57600080fd5b506101ac600480360361012081101561006457600080fd5b8101908080604001906002806020026040519081016040528092919082600260200280828437600081840152601f19601f82011690508083019250505050505091929192908060800190600280602002604051908101604052809291906000905b82821015610119578382604002016002806020026040519081016040528092919082600260200280828437600081840152601f19601f820116905080830192505050505050815260200190600101906100c5565b50505050919291929080604001906002806020026040519081016040528092919082600260200280828437600081840152601f19601f820116905080830192505050505050919291929080602001906001806020026040519081016040528092919082600160200280828437600081840152601f19601f82011690508083019250505050505091929192905050506101c6565b604051808215151515815260200191505060405180910390f35b60006101d0610fe6565b60408051908101604052808760006002811015156101ea57fe5b6020020151815260200187600160028110151561020357fe5b602002015181525081600001819052506040805190810160405280604080519081016040528088600060028110151561023857fe5b6020020151600060028110151561024b57fe5b6020020151815260200188600060028110151561026457fe5b6020020151600160028110151561027757fe5b60200201518152508152602001604080519081016040528088600160028110151561029e57fe5b602002015160006002811015156102b157fe5b602002015181526020018860016002811015156102ca57fe5b602002015160016002811015156102dd57fe5b60200201518152508152508160200181905250604080519081016040528085600060028110151561030a57fe5b6020020151815260200185600160028110151561032357fe5b60200201518152508160400181905250606060016040519080825280602002602001820160405280156103655781602001602082028038833980820191505090505b50905060008090505b60018110156103b357848160018110151561038557fe5b6020020151828281518110151561039857fe5b9060200190602002018181525050808060010191505061036e565b5060006103c0828461046e565b141561045f577f3f3cfdb26fb5f9f1786ab4f1a1f9cd4c0b5e726cbdfc26e495261731aad44e396040518080602001828103825260228152602001807f5472616e73616374696f6e207375636365737366756c6c79207665726966696581526020017f642e00000000000000000000000000000000000000000000000000000000000081525060400191505060405180910390a1600192505050610466565b6000925050505b949350505050565b6000807f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001905061049c61101b565b6104a46105f6565b905080608001515160018651011415156104bd57600080fd5b6104c5611064565b6040805190810160405280600081526020016000815250905060008090505b8651811015610569578387828151811015156104fc57fe5b9060200190602002015110151561051257600080fd5b61055a8261055585608001516001850181518110151561052e57fe5b906020019060200201518a8581518110151561054657fe5b906020019060200201516109da565b610a76565b915080806001019150506104e4565b50610590818360800151600081518110151561058157fe5b90602001906020020151610a76565b90506105d6856000015186602001516105a884610b33565b85604001516105ba8a60400151610b33565b87606001516105cc8960000151610b33565b8960200151610bcf565b15156105e857600193505050506105f0565b600093505050505b92915050565b6105fe61101b565b60408051908101604052807f0a66d7b33789fe1ddf9e9aa10f58a9d065a849090bed127be938354fa43d9a9881526020017f07740ba2bbe9e5a7b3cb1aa428092e5c0f7b38ba9d0d1443918f55da3f3badc48152508160000181905250604080519081016040528060408051908101604052807f19a14cfdd576230bec3b5fd70c2cafb5989587ad089f0647ddc432cf7242d9cc81526020017e281428ebd57bc8f1b67adb6864b0de18ff816d9256b237ffa142a95c2f7518815250815260200160408051908101604052807f0e185f834d55f5d993b48a71774a42af57958b79339a7cc053701c1b2c5d912e81526020017f06d7d4a913ba1ab5ac30b4a9e1c82bfa32fea565fb3dd2635c953b1554fda8ae8152508152508160200181905250604080519081016040528060408051908101604052807f0b12276c517e61ee10baca921053db31a7b905c78443563d5686c707d567c33981526020017f0d40711bac3b28570c633c4deb0873b0d7bfd835fca219f6a02e00a51fc43b94815250815260200160408051908101604052807f1ee1b47b522a00884ff2f821a6e0439d1c80b13513014a9a288c67da04b53a9681526020017f1828a2e4a05a7292e65e94a5a12bcad046cefa7321ba2a768e754c367c9204038152508152508160400181905250604080519081016040528060408051908101604052807f25b8450aa1e6a01f2cf51b942379f733ca770a12c3958428c780fbbdd4d2aee281526020017f2cd84fed31e7b27262cd9e9d38e5b30f5cd22ea33ea091ccb3d58dfc4ed81f46815250815260200160408051908101604052807f1997cd56eccea640a70f3927f05e4a1cc3f7dab5d361bad472942860642cd26981526020017f26f81da02c5a5c05dc868ce5f58c3ae0c2b31923274fd2ed90fb65bffd18fee7815250815250816060018190525060026040519080825280602002602001820160405280156108e457816020015b6108d161107e565b8152602001906001900390816108c95790505b50816080018190525060408051908101604052807f1d3b1ee1603366b684466d4cb9e39cb6627552b65130d223e9c5eb52d2b0bd4081526020017f28fd0ea47d452a5450fa8a198e7aa8858eb6a3147d9ee75f70966ac5e632fc168152508160800151600081518110151561095557fe5b9060200190602002018190525060408051908101604052807f2f0d7b0aedde5e3ba8b6902cfeaa163b0e7fc920af0fdbf8fca4d91c479636f781526020017f0a8ef077748ad3f1652c954a96b3afd93866d1198f70657f713149d47a32824a815250816080015160018151811015156109ca57fe5b9060200190602002018190525090565b6109e2611064565b6109ea611098565b83600001518160006003811015156109fe57fe5b6020020181815250508360200151816001600381101515610a1b57fe5b60200201818152505082816002600381101515610a3457fe5b6020020181815250506000606083608084600060076107d05a03f190508060008114610a5f57610a61565bfe5b50801515610a6e57600080fd5b505092915050565b610a7e611064565b610a866110bb565b8360000151816000600481101515610a9a57fe5b6020020181815250508360200151816001600481101515610ab757fe5b6020020181815250508260000151816002600481101515610ad457fe5b6020020181815250508260200151816003600481101515610af157fe5b602002018181525050600060608360c084600060066107d05a03f190508060008114610b1c57610b1e565bfe5b50801515610b2b57600080fd5b505092915050565b610b3b611064565b60007f30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47905060008360000151148015610b78575060008360200151145b15610b9c576040805190810160405280600081526020016000815250915050610bca565b604080519081016040528084600001518152602001828560200151811515610bc057fe5b0683038152509150505b919050565b600060606004604051908082528060200260200182016040528015610c0e57816020015b610bfb61107e565b815260200190600190039081610bf35790505b50905060606004604051908082528060200260200182016040528015610c4e57816020015b610c3b6110de565b815260200190600190039081610c335790505b5090508a826000815181101515610c6157fe5b9060200190602002018190525088826001815181101515610c7e57fe5b9060200190602002018190525086826002815181101515610c9b57fe5b9060200190602002018190525084826003815181101515610cb857fe5b9060200190602002018190525089816000815181101515610cd557fe5b9060200190602002018190525087816001815181101515610cf257fe5b9060200190602002018190525085816002815181101515610d0f57fe5b9060200190602002018190525083816003815181101515610d2c57fe5b90602001906020020181905250610d438282610d53565b9250505098975050505050505050565b600081518351141515610d6557600080fd5b6000835190506000600682029050606081604051908082528060200260200182016040528015610da45781602001602082028038833980820191505090505b50905060008090505b83811015610f82578681815181101515610dc357fe5b90602001906020020151600001518260006006840201815181101515610de557fe5b90602001906020020181815250508681815181101515610e0157fe5b90602001906020020151602001518260016006840201815181101515610e2357fe5b90602001906020020181815250508581815181101515610e3f57fe5b90602001906020020151600001516000600281101515610e5b57fe5b60200201518260026006840201815181101515610e7457fe5b90602001906020020181815250508581815181101515610e9057fe5b90602001906020020151600001516001600281101515610eac57fe5b60200201518260036006840201815181101515610ec557fe5b90602001906020020181815250508581815181101515610ee157fe5b90602001906020020151602001516000600281101515610efd57fe5b60200201518260046006840201815181101515610f1657fe5b90602001906020020181815250508581815181101515610f3257fe5b90602001906020020151602001516001600281101515610f4e57fe5b60200201518260056006840201815181101515610f6757fe5b90602001906020020181815250508080600101915050610dad565b50610f8b611105565b60006020826020860260208601600060086107d05a03f190508060008114610fb257610fb4565bfe5b50801515610fc157600080fd5b6000826000600181101515610fd257fe5b602002015114159550505050505092915050565b61010060405190810160405280610ffb61107e565b81526020016110086110de565b815260200161101561107e565b81525090565b6101e06040519081016040528061103061107e565b815260200161103d6110de565b815260200161104a6110de565b81526020016110576110de565b8152602001606081525090565b604080519081016040528060008152602001600081525090565b604080519081016040528060008152602001600081525090565b606060405190810160405280600390602082028038833980820191505090505090565b608060405190810160405280600490602082028038833980820191505090505090565b6080604051908101604052806110f2611128565b81526020016110ff611128565b81525090565b602060405190810160405280600190602082028038833980820191505090505090565b604080519081016040528060029060208202803883398082019150509050509056fea165627a7a723058205b703142091c21704f001f578b6569edd8b4fe0e4bdd7f36f3a23b7e597ef0a50029

Is the argument too large? or the smartcontract code? or is something else that I'm missing?

@silasdavis
Copy link
Contributor

This error is generator when we try to extract a 64-bit integer from the 256-bit word on the top of stack.

This either means:

  • There is a bug in the EVM code you have that is causing the stack to contain a number wider than 64 bits when it shouldn't
  • You are trying using a gas or transferring a value with a call that is bigger than a 64-bit integer
  • There is a bug in the VM

The possible locations where the VM can emit this error are stack.Pop64 or stack.PopU64 in vm.go, for example:

https://github.com/hyperledger/burrow/blob/develop/execution/evm/vm.go#L448

or

https://github.com/hyperledger/burrow/blob/develop/execution/evm/vm.go#L638

There are more but all in that file.

We have an option that would help you debug which opcode caused the error: https://github.com/hyperledger/burrow/blob/develop/execution/evm/options.go#L11-L13 but it looks like fabric-evm doesn't currently expose any switch to make that run.

If you want to dig into the behaviour you can clone us and add a test in https://github.com/hyperledger/burrow/blob/develop/execution/evm/vm_test.go like this:

func TestIssue1124(t *testing.T) {
	bc := hex.MustDecodeString("608060405234801561001057600080fd5b50611176806100206000396000f3fe60806040526004361061003b576000357c010000000000000000000000000000000000000000000000000000000090048063dd12931314610040575b600080fd5b34801561004c57600080fd5b506101ac600480360361012081101561006457600080fd5b8101908080604001906002806020026040519081016040528092919082600260200280828437600081840152601f19601f82011690508083019250505050505091929192908060800190600280602002604051908101604052809291906000905b82821015610119578382604002016002806020026040519081016040528092919082600260200280828437600081840152601f19601f820116905080830192505050505050815260200190600101906100c5565b50505050919291929080604001906002806020026040519081016040528092919082600260200280828437600081840152601f19601f820116905080830192505050505050919291929080602001906001806020026040519081016040528092919082600160200280828437600081840152601f19601f82011690508083019250505050505091929192905050506101c6565b604051808215151515815260200191505060405180910390f35b60006101d0610fe6565b60408051908101604052808760006002811015156101ea57fe5b6020020151815260200187600160028110151561020357fe5b602002015181525081600001819052506040805190810160405280604080519081016040528088600060028110151561023857fe5b6020020151600060028110151561024b57fe5b6020020151815260200188600060028110151561026457fe5b6020020151600160028110151561027757fe5b60200201518152508152602001604080519081016040528088600160028110151561029e57fe5b602002015160006002811015156102b157fe5b602002015181526020018860016002811015156102ca57fe5b602002015160016002811015156102dd57fe5b60200201518152508152508160200181905250604080519081016040528085600060028110151561030a57fe5b6020020151815260200185600160028110151561032357fe5b60200201518152508160400181905250606060016040519080825280602002602001820160405280156103655781602001602082028038833980820191505090505b50905060008090505b60018110156103b357848160018110151561038557fe5b6020020151828281518110151561039857fe5b9060200190602002018181525050808060010191505061036e565b5060006103c0828461046e565b141561045f577f3f3cfdb26fb5f9f1786ab4f1a1f9cd4c0b5e726cbdfc26e495261731aad44e396040518080602001828103825260228152602001807f5472616e73616374696f6e207375636365737366756c6c79207665726966696581526020017f642e00000000000000000000000000000000000000000000000000000000000081525060400191505060405180910390a1600192505050610466565b6000925050505b949350505050565b6000807f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001905061049c61101b565b6104a46105f6565b905080608001515160018651011415156104bd57600080fd5b6104c5611064565b6040805190810160405280600081526020016000815250905060008090505b8651811015610569578387828151811015156104fc57fe5b9060200190602002015110151561051257600080fd5b61055a8261055585608001516001850181518110151561052e57fe5b906020019060200201518a8581518110151561054657fe5b906020019060200201516109da565b610a76565b915080806001019150506104e4565b50610590818360800151600081518110151561058157fe5b90602001906020020151610a76565b90506105d6856000015186602001516105a884610b33565b85604001516105ba8a60400151610b33565b87606001516105cc8960000151610b33565b8960200151610bcf565b15156105e857600193505050506105f0565b600093505050505b92915050565b6105fe61101b565b60408051908101604052807f0a66d7b33789fe1ddf9e9aa10f58a9d065a849090bed127be938354fa43d9a9881526020017f07740ba2bbe9e5a7b3cb1aa428092e5c0f7b38ba9d0d1443918f55da3f3badc48152508160000181905250604080519081016040528060408051908101604052807f19a14cfdd576230bec3b5fd70c2cafb5989587ad089f0647ddc432cf7242d9cc81526020017e281428ebd57bc8f1b67adb6864b0de18ff816d9256b237ffa142a95c2f7518815250815260200160408051908101604052807f0e185f834d55f5d993b48a71774a42af57958b79339a7cc053701c1b2c5d912e81526020017f06d7d4a913ba1ab5ac30b4a9e1c82bfa32fea565fb3dd2635c953b1554fda8ae8152508152508160200181905250604080519081016040528060408051908101604052807f0b12276c517e61ee10baca921053db31a7b905c78443563d5686c707d567c33981526020017f0d40711bac3b28570c633c4deb0873b0d7bfd835fca219f6a02e00a51fc43b94815250815260200160408051908101604052807f1ee1b47b522a00884ff2f821a6e0439d1c80b13513014a9a288c67da04b53a9681526020017f1828a2e4a05a7292e65e94a5a12bcad046cefa7321ba2a768e754c367c9204038152508152508160400181905250604080519081016040528060408051908101604052807f25b8450aa1e6a01f2cf51b942379f733ca770a12c3958428c780fbbdd4d2aee281526020017f2cd84fed31e7b27262cd9e9d38e5b30f5cd22ea33ea091ccb3d58dfc4ed81f46815250815260200160408051908101604052807f1997cd56eccea640a70f3927f05e4a1cc3f7dab5d361bad472942860642cd26981526020017f26f81da02c5a5c05dc868ce5f58c3ae0c2b31923274fd2ed90fb65bffd18fee7815250815250816060018190525060026040519080825280602002602001820160405280156108e457816020015b6108d161107e565b8152602001906001900390816108c95790505b50816080018190525060408051908101604052807f1d3b1ee1603366b684466d4cb9e39cb6627552b65130d223e9c5eb52d2b0bd4081526020017f28fd0ea47d452a5450fa8a198e7aa8858eb6a3147d9ee75f70966ac5e632fc168152508160800151600081518110151561095557fe5b9060200190602002018190525060408051908101604052807f2f0d7b0aedde5e3ba8b6902cfeaa163b0e7fc920af0fdbf8fca4d91c479636f781526020017f0a8ef077748ad3f1652c954a96b3afd93866d1198f70657f713149d47a32824a815250816080015160018151811015156109ca57fe5b9060200190602002018190525090565b6109e2611064565b6109ea611098565b83600001518160006003811015156109fe57fe5b6020020181815250508360200151816001600381101515610a1b57fe5b60200201818152505082816002600381101515610a3457fe5b6020020181815250506000606083608084600060076107d05a03f190508060008114610a5f57610a61565bfe5b50801515610a6e57600080fd5b505092915050565b610a7e611064565b610a866110bb565b8360000151816000600481101515610a9a57fe5b6020020181815250508360200151816001600481101515610ab757fe5b6020020181815250508260000151816002600481101515610ad457fe5b6020020181815250508260200151816003600481101515610af157fe5b602002018181525050600060608360c084600060066107d05a03f190508060008114610b1c57610b1e565bfe5b50801515610b2b57600080fd5b505092915050565b610b3b611064565b60007f30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47905060008360000151148015610b78575060008360200151145b15610b9c576040805190810160405280600081526020016000815250915050610bca565b604080519081016040528084600001518152602001828560200151811515610bc057fe5b0683038152509150505b919050565b600060606004604051908082528060200260200182016040528015610c0e57816020015b610bfb61107e565b815260200190600190039081610bf35790505b50905060606004604051908082528060200260200182016040528015610c4e57816020015b610c3b6110de565b815260200190600190039081610c335790505b5090508a826000815181101515610c6157fe5b9060200190602002018190525088826001815181101515610c7e57fe5b9060200190602002018190525086826002815181101515610c9b57fe5b9060200190602002018190525084826003815181101515610cb857fe5b9060200190602002018190525089816000815181101515610cd557fe5b9060200190602002018190525087816001815181101515610cf257fe5b9060200190602002018190525085816002815181101515610d0f57fe5b9060200190602002018190525083816003815181101515610d2c57fe5b90602001906020020181905250610d438282610d53565b9250505098975050505050505050565b600081518351141515610d6557600080fd5b6000835190506000600682029050606081604051908082528060200260200182016040528015610da45781602001602082028038833980820191505090505b50905060008090505b83811015610f82578681815181101515610dc357fe5b90602001906020020151600001518260006006840201815181101515610de557fe5b90602001906020020181815250508681815181101515610e0157fe5b90602001906020020151602001518260016006840201815181101515610e2357fe5b90602001906020020181815250508581815181101515610e3f57fe5b90602001906020020151600001516000600281101515610e5b57fe5b60200201518260026006840201815181101515610e7457fe5b90602001906020020181815250508581815181101515610e9057fe5b90602001906020020151600001516001600281101515610eac57fe5b60200201518260036006840201815181101515610ec557fe5b90602001906020020181815250508581815181101515610ee157fe5b90602001906020020151602001516000600281101515610efd57fe5b60200201518260046006840201815181101515610f1657fe5b90602001906020020181815250508581815181101515610f3257fe5b90602001906020020151602001516001600281101515610f4e57fe5b60200201518260056006840201815181101515610f6757fe5b90602001906020020181815250508080600101915050610dad565b50610f8b611105565b60006020826020860260208601600060086107d05a03f190508060008114610fb257610fb4565bfe5b50801515610fc157600080fd5b6000826000600181101515610fd257fe5b602002015114159550505050505092915050565b61010060405190810160405280610ffb61107e565b81526020016110086110de565b815260200161101561107e565b81525090565b6101e06040519081016040528061103061107e565b815260200161103d6110de565b815260200161104a6110de565b81526020016110576110de565b8152602001606081525090565b604080519081016040528060008152602001600081525090565b604080519081016040528060008152602001600081525090565b606060405190810160405280600390602082028038833980820191505090505090565b608060405190810160405280600490602082028038833980820191505090505090565b6080604051908101604052806110f2611128565b81526020016110ff611128565b81525090565b602060405190810160405280600190602082028038833980820191505090505090565b604080519081016040528060029060208202803883398082019150509050509056fea165627a7a723058205b703142091c21704f001f578b6569edd8b4fe0e4bdd7f36f3a23b7e597ef0a50029")
	input := hex.MustDecodeString("dd12931324ea66eccb0af86fac0422d914240bc576d0ae0f6ea1cbe60737393f4b93562c05ae9a7fa7371cde3aaa92cc3bc953c152a7312d6e56f382b3c922e5959707f41faf45da658fc9ffd9fb741707366515dafe7b5bd45a3462984e22736eaf38b12c44eb99df7eaa9fff456e0a42799acdbd41ecde0e4c5239e970c10565a847ed2b91804dc2138235e4521eacd0a13bd604a39054b3e10d38ba56734df24c4c4a2eef134e22ad618834c0a179c925252612e624528943c1a2a78fe42d56b962322d342cdd65ef0320eb3a07e22299731ba085151b6383e9acd5f0e1ac7a3530892e8549dce4604fc4b551110c07e72dfae1dca032cecdd1d2f6aa15394506db2e0000000000000000000000000000000000000000000000000000000000000001")
	addr := crypto.Address{2, 3}
	vm := NewVM(Params{}, addr, nil, logging.NewNoopLogger())

	appState := newAppState()
	acc := &acm.Account{
		Address:addr,
		Balance: 213123312,
	}
	err := appState.UpdateAccount(acc)
	require.NoError(t, err)
	evmState := NewState(appState, blockHashGetter)
	gas := uint64(324234324)
	output, err := vm.Call(evmState, NewNoopEventSink(), addr, addr, bc, input, 0, &gas)
	require.NoError(t, err)
	fmt.Println(string(output))
}

This test runs the code and input you have provided and passes for me.

If you can demonstrate a failure I can take a look.

@madiazp
Copy link
Author

madiazp commented Aug 28, 2019

Thanks a lot for the reply, I ran the test and it ran successfully. So it was the amount of gas in the fabric-cc-evm. I put a random value var gas uint64 = 10123122000 and it kind of worked fine (not the output that I expected but it ran without errors. ).
I will report this to the fabric-cc-evm team.

@madiazp
Copy link
Author

madiazp commented Aug 29, 2019

UPDATE:

So I dig more in the issue and used the commit to enable burrow opcode debug that the fabric-cc-evm team pass me. And I found a weird behavior of the evm.

Some context first. I'm trying to deploy a smart contract auto-generated by ZoKrates, The Remix compiler outputs 3 codes (2 libraries and the smart contract ). and I'm using the 3rd one (I still don't know if I have to concatenate the 3 codes or the 3rd one is sufficient).

Well, when I ran your test with a gas in the range (1,24) It outputs a insufficient gas error, and from 25 and so on it outputs the code without errors.

But when I ran it in the fabric-cc-evm environment with a gas between the range 1-3666 it output a insufficient gas error. With gas between the range 3667-10915 it outputs the stack overflow error. And from 10916 and so on it works fine.

So the 3660 gas opcode throw this log in the peer:
Error: endorsement failure during query. response: status:500 message:"transaction returned with failure: proto: invalid UTF-8 string"

And the burrow opcode log throw this:

`
[...]

{"log_channel":"Trace","message":"(pc) 2637 (op) GAS (st) 33 (gas) 6","scope":"NewVM","tag":"DebugOpcodes"}

{"log_channel":"Trace","message":" =\u003e 5\n","scope":"NewVM","tag":"DebugOpcodes"}

{"log_channel":"Trace","message":"(pc) 2638 (op) SUB (st) 34 (gas) 5","scope":"NewVM","tag":"DebugOpcodes"}

{"log_channel":"Trace","message":" 6 - 2000 = -1994 (FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF836)\n","scope":"NewVM","tag":"DebugOpcodes"}

{"log_channel":"Trace","message":"(pc) 2639 (op) CALL (st) 33 (gas) 2","scope":"NewVM","tag":"DebugOpcodes"}

{"log_channel":"Trace","message":" =\u003e
0000000000000000000000000000000000000007\n","scope":"NewVM","tag":"DebugOpcodes"}

2019/08/29 01:21:50 output:
2019-08-29 01:21:50.812 UTC [shim] 2 -> ERRO 015 [ef9533f2] Transaction execution failed. Sending ERROR
`

That seems to be this part of the code :

`

  GAS 			gas
  SUB 			sub(gas, 2000)
  CALL 	        call(sub(gas, 2000), 7, 0, inp....

`

In the other hand the code fails with 10915 gas with this burrow opcode log:

{"log_channel":"Trace","message":" =\u003e 7CE\n","scope":"NewVM","tag":"DebugOpcodes"} {"log_channel":"Trace","message":"(pc) 4001 (op) SUB (st) 46 (gas) 1998","scope":"NewVM","tag":"DebugOpcodes"} {"log_channel":"Trace","message":" 1999 - 2000 = -1 (FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)\n","scope":"NewVM","tag":"DebugOpcodes"} {"log_channel":"Trace","message":"(pc) 4002 (op) CALL (st) 45 (gas) 1995","scope":"NewVM","tag":"DebugOpcodes"} {"log_channel":"Trace","message":" =\u003e 0000000000000000000000000000000000000008\n","scope":"NewVM","tag":"DebugOpcodes"}

So my guess is it seems to try to do a call with a negative gas or something like that and that make explode the code.
PD: This is the smart contract made by ZoKrates.

@j-h-scheufen
Copy link
Contributor

j-h-scheufen commented Aug 29, 2019

@madiazp Not entirely sure, but this could be related to your contract deployment. Because you have two libraries (BN256G2 and Pairing), did you deploy these in order and bind the library addresses into the compilation?
Deploy BN256G2 first. Then this address must be injected into the compilation of Pairing. Then the deployed Pairing address is needed when compiling Verifier.
I'm not sure how Remix does that, though.
Burrow has a yaml language to orchestrate deployments where your sequence would look like this:

jobs:

- name: deployBN256G2
  deploy:
    contract: Issue1224.sol
    instance: BN256G2

- name: deployPairing
  deploy:
    contract: Issue1224.sol
    instance: Pairing
    libraries: BN256G2:$deployBN256G2

- name: deployVerifier
  deploy:
    contract: Issue1224.sol
    instance: Verifier
    libraries: Pairing:$deployPairing

This is simply an EVM/Solidity thing that when using libraries they need to be deployed first and their addresses are compiled into the bytecode of the contracts that use them.

@j-h-scheufen
Copy link
Contributor

If you save the above in a file Issue1224.yaml, you can run burrow deploy --chain=localhost:10997 --address=<deployment-account> Issue1224.yaml
The deployment-account is the one signing the deploy tx. You might have to adapt the chain URL.

@madiazp
Copy link
Author

madiazp commented Aug 29, 2019

That's really useful, thanks. I'm not sure how can I do it with fabric-cc-evm, but that can solve the issue.

@j-h-scheufen
Copy link
Contributor

j-h-scheufen commented Aug 29, 2019

@madiazp Yeah, I figured. It helped to illustrate the sequence though.
Remix uses solc under the hood, just like Burrow. In your case it would probably be easier, if you separate the two libs and one contract into their own files and use import statements for the libraries. As long as all files are in the same directory, solc can find them easily.
Then follow the same sequence to deploy. You have to see how Remix supports setting extra compiler settings, but on the command line the one you're looking for is --libraries "BN256G2.sol:BN256G2:0x1234567890123456789012345678901234567890" to bind the library address into the bytecode.

See here: https://solidity.readthedocs.io/en/v0.5.3/using-the-compiler.html#using-the-commandline-compiler

@silasdavis
Copy link
Contributor

I was going to come back here to mention that you ought to be seeing insufficient gas rather than stack overflow (actually that error is coded wrong it is not a stack overflow it is an integer overflow - I have fixed this). The integer overflow is more likely to indicate an issue in the EVM bug. @j-h-scheufen might be on to something here.

@madiazp
Copy link
Author

madiazp commented Sep 4, 2019

@j-h-scheufen I've search a little bit and this is not the case.
The solc version of burrow (and remix) add the opcodes of the libraries in the final code if the functions of the library are internal functions (see deployment of libraries). You can see in the assembly of my contract opcodes that are part of the libraries imported. In fact I added a public function in the BN256G2 library to test something and the _$tag_space$_ appeared in the code.

@silasdavis So the reason why the contract don't work is because is trying to call pre-compiled ethereum smart contracts (1, 2 and 3) specifically the address 5,6 and 7 that are not part of the native functions supported by burrow and because of that the contract cannot be executed. Moreover are in these calls where the gas subtractions are made and the int overflows happens, for example:

        bool success;
        assembly {
            success := call(sub(gas, 2000), 7, 0, input, 0x80, r, 0x60)
            // Use "invalid" to make gas estimation work
            switch success case 0 { invalid() }
        }
        require (success)

I'm pretty screwed ajaja. I will see how to implement these smart contracts. If I can make it work in my local repo I will try to do the pull request if you feel like to add them in the native contracts. All the help in this matter are highly appreciated.

@j-h-scheufen
Copy link
Contributor

@madiazp You are correct about the "inlining" of bytecode when using private functions. I had not checked whether you were purely relying on private library functions.

@silasdavis
Copy link
Contributor

Resolved if this gets picked up #1284

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants