Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validating transaction data bug #19

Open
Banega00 opened this issue Jul 30, 2022 · 0 comments
Open

validating transaction data bug #19

Banega00 opened this issue Jul 30, 2022 · 0 comments

Comments

@Banega00
Copy link

I found that validTransactionData method of Blockchain class does not work properly.

Precisely I think that this part is problem

      const trueBalance = Wallet.calculateBalance({
        chain: this.chain,
        address: transaction.input.address
      });

      if (transaction.input.amount !== trueBalance) {
        console.error('Invalid input amount');
        return false;
      }

Here you are comparing for every transaction's input amount with true balance of its sender. True balance will always be same for one wallet on blockchain but transaction.input.amount can be different for every transaction. So here is the problem that I faced when i tried to broadcast my blockchain to other nodes in the network, they wouldn't accept it becouse they marked it as invalid.
validTransactionData always outputs 'Invalid input amount' error.
So my fix is - only calculate balance of the wallet from start of blockchain up to this block transaction - this.chain.slice(0,i)

          const trueBalance = Wallet.calculateBalance({
            chain: this.chain.slice(0,i),
            address: transaction.input.address
          });

          if (transaction.input.amount !== trueBalance) {
            console.error('Invalid input amount');
            return false;
          }

I've tested it and it works perfectly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant