Cumulative U256

Concurrent Delta Friendly uint256

TheU256Cum contract is designed for handling cumulative operations in full parallel. The U256Cumulative is a concurrent variable that supports concurrent addition and subtraction. It has both minimum and maximum bounds and allows concurrent delta changes. It is conceptionally similar to an atomic integer but with some major constraints.

Out-of-limit delta changes will fail to ensure that the variable stays within its prescribed bounds. Attempting to invoke timing-dependent operations like read()on the variable while being updated by other threads will result in a transaction rollback.

Custom Types: Due to the unique properties of the commutative, only a very limited types can be classified as such, Custom commutative variables aren't supported by Arcology.

Usage

A typical application is implementing numerical variables that need to be incremented or decremented by multiple transactions. Examples include counters, tallies, or any situation where a count needs to be updated frequently and concurrently. U256Cumulative can also help manage the supply of tokens in scenarios where tokens are frequently minted or burned by multiple transactions.

Example

The CumulativeU256Test is a test contract that demonstrates the usage of the U256Cumulative contract, which is designed for cumulative operations in full concurrency. The purpose of this test contract is to verify that the U256Cumulative contract behaves correctly according to its specifications and that it properly enforces the defined minimum and maximum bounds.

This test contract demonstrates the proper behavior of the U256Cumulative contract in handling cumulative operations and enforcing the specified bounds, ensuring that the variable stays within the prescribed range.

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;

import "./U256Cum.sol";

contract Visit {
    U256Cumulative totalVisits = new U256Cumulative(0, 1000000)

    function visit() {     
        totalVisits.add(1);
    }
    
    function get() {     
        totalVisits.get();
    }
}

Last updated