Token without Limit

Published by Mario Oettler on

Last Updated on 7. September 2024 by Mario Oettler

Der folgende Ausschnitt des Smart Contracts wurde in verschiedenen Projekten eingesetzt und ausgenutzt.

pragma solidity 0.8.26;

contract Balance{

    mapping(address => uint256) public _balances;

    constructor(){
        _balances[<hier Adresse 1>] = 100;
        _balances[<hier Adresse 2>] = 100;
    }

    function _update(address from, address to, uint256 value) public virtual {

    uint256 fromBalance = _balances[from];
    uint256 toBalance = _balances[to];

    _balances[from] = fromBalance - value;
    _balances[to] = toBalance + value; // Vulnerable
    }
}

Den Quellcode finden Sie in der Datei 10_Token_Without_Limit.sol.

Aufgabe

Dem Ersteller werden 100 Token zugewiesen. Erhöhen Sie den Betrag, den der Ersteller auf seiner Adresse hält auf 150 Token, ohne dass ein anderer Account Token verliert.

Lösung

Erst wird die toBalance zwischengespeichert. Dann wird das zwischengespeicherte Ergebnis + value zurück in das Mapping geschrieben. Wenn to and from die gleiche Adresse haben, wird der Betrag einfach draufgerechnet.

Man muss die Funktion transfer mit der gleichen Adresse aufrufen und den gewünschten Betrag eingeben.

Quellen:

Categories:

https://blockchain-academy.hs-mittweida.de/wp-content/uploads/2021/04/logo_bcam_rgb_gross.png

Welcome

Blockchain Academy

Continue with credential

No account yet?

Powered by Hidy

Register with Hidy


Register
Sign in

We need the following credential to register:

please select:

To create a new account, we need the following data from you:

We would appreciate the following additional information from you for the creation of your account:

Welcome

Blockchain Academy

Continue with credential

Already have an account?

Powered by Hidy

Sign in with Hidy


Register
Sign in

We need the following credential to log in:

please select: