Improve accuracy of constraint system violation diagnostics.
This commit is contained in:
parent
b55744e1ad
commit
5f0a73ce11
|
@ -204,14 +204,12 @@ void invokeAPIFailure(
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
invokeAPI(js, inputs, outputs, vpub_old, vpub_new, rt);
|
invokeAPI(js, inputs, outputs, vpub_old, vpub_new, rt);
|
||||||
|
FAIL() << "It worked, when it shouldn't have!";
|
||||||
} catch(std::invalid_argument const & err) {
|
} catch(std::invalid_argument const & err) {
|
||||||
EXPECT_EQ(err.what(), reason);
|
EXPECT_EQ(err.what(), reason);
|
||||||
return;
|
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
FAIL() << "Expected invalid_argument exception.";
|
FAIL() << "Expected invalid_argument exception.";
|
||||||
}
|
}
|
||||||
|
|
||||||
FAIL() << "It worked, when it shouldn't have!";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(joinsplit, h_sig)
|
TEST(joinsplit, h_sig)
|
||||||
|
|
|
@ -70,6 +70,17 @@ void IncrementalMerkleTree<Depth, Hash>::wfcheck() const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<size_t Depth, typename Hash>
|
||||||
|
Hash IncrementalMerkleTree<Depth, Hash>::last() const {
|
||||||
|
if (right) {
|
||||||
|
return *right;
|
||||||
|
} else if (left) {
|
||||||
|
return *left;
|
||||||
|
} else {
|
||||||
|
throw std::runtime_error("tree has no cursor");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<size_t Depth, typename Hash>
|
template<size_t Depth, typename Hash>
|
||||||
void IncrementalMerkleTree<Depth, Hash>::append(Hash obj) {
|
void IncrementalMerkleTree<Depth, Hash>::append(Hash obj) {
|
||||||
if (is_complete(Depth)) {
|
if (is_complete(Depth)) {
|
||||||
|
|
|
@ -79,6 +79,7 @@ public:
|
||||||
Hash root() const {
|
Hash root() const {
|
||||||
return root(Depth, std::deque<Hash>());
|
return root(Depth, std::deque<Hash>());
|
||||||
}
|
}
|
||||||
|
Hash last() const;
|
||||||
|
|
||||||
IncrementalWitness<Depth, Hash> witness() const {
|
IncrementalWitness<Depth, Hash> witness() const {
|
||||||
return IncrementalWitness<Depth, Hash>(*this);
|
return IncrementalWitness<Depth, Hash>(*this);
|
||||||
|
@ -138,6 +139,12 @@ public:
|
||||||
return tree.path(partial_path());
|
return tree.path(partial_path());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the element being witnessed (should be a note
|
||||||
|
// commitment!)
|
||||||
|
Hash element() const {
|
||||||
|
return tree.last();
|
||||||
|
}
|
||||||
|
|
||||||
Hash root() const {
|
Hash root() const {
|
||||||
return tree.root(Depth, partial_path());
|
return tree.root(Depth, partial_path());
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,10 +205,17 @@ public:
|
||||||
for (size_t i = 0; i < NumInputs; i++) {
|
for (size_t i = 0; i < NumInputs; i++) {
|
||||||
// Sanity checks of input
|
// Sanity checks of input
|
||||||
{
|
{
|
||||||
// If note has nonzero value, its witness's root must be equal to the
|
// If note has nonzero value
|
||||||
// input.
|
if (inputs[i].note.value != 0) {
|
||||||
if ((inputs[i].note.value != 0) && (inputs[i].witness.root() != rt)) {
|
// The witness root must equal the input root.
|
||||||
throw std::invalid_argument("joinsplit not anchored to the correct root");
|
if (inputs[i].witness.root() != rt) {
|
||||||
|
throw std::invalid_argument("joinsplit not anchored to the correct root");
|
||||||
|
}
|
||||||
|
|
||||||
|
// The tree must witness the correct element
|
||||||
|
if (inputs[i].note.cm() != inputs[i].witness.element()) {
|
||||||
|
throw std::invalid_argument("witness of wrong element for joinsplit input");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we have the key to this note.
|
// Ensure we have the key to this note.
|
||||||
|
|
Loading…
Reference in New Issue