Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions docs/POSTAGE_STAMP.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ struct Batch {
address owner; // Owner of the batch
uint8 depth; // Total depth (2^depth = max chunks)
uint8 bucketDepth; // Bucket depth for addressing
bool immutableFlag; // Whether batch can be modified
uint256 normalisedBalance; // Normalized balance per chunk
uint256 lastUpdatedBlockNumber; // Last update timestamp
}
Expand All @@ -59,7 +58,6 @@ Creates a new postage stamp batch.
- `_depth`: Total batch depth (capacity = 2^depth)
- `_bucketDepth`: Bucket depth for chunk addressing
- `_nonce`: Random nonce for batch ID generation
- `_immutable`: Whether batch can be topped up later

**Requirements**:
- `_initialBalancePerChunk >= minimumInitialBalancePerChunk()` (24h minimum validity)
Expand Down Expand Up @@ -207,8 +205,7 @@ event BatchCreated(
uint256 normalisedBalance,
address owner,
uint8 depth,
uint8 bucketDepth,
bool immutableFlag
uint8 bucketDepth
);

event BatchTopUp(
Expand Down
3 changes: 1 addition & 2 deletions scripts/migration/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ for row in $(cat ./migration/batchesG2.json | jq -c '.batches[]'); do
depth=$(_field $row ".depth")
bucketdepth=$(_field $row ".bucketDepth")
batchid=$(_field $row ".batchid")
immutable=$(_field $row ".immutable")

echo "Batch balance #####"
echo ${balance}

cmd="npx hardhat --network testnet copy --owner ${owner} --initialbalance ${balance} --depth ${depth} --bucketdepth ${bucketdepth} --batchid ${batchid} --immutable ${immutable} --contract ${postagecontract}"
cmd="npx hardhat --network testnet copy --owner ${owner} --initialbalance ${balance} --depth ${depth} --bucketdepth ${bucketdepth} --batchid ${batchid} --contract ${postagecontract}"
$cmd
[ $? -eq 0 ] && echo "${batchid} migration successful" || echo "${batchid} migration failure"
done
2 changes: 0 additions & 2 deletions scripts/migration/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ interface Batch {
owner: string;
depth: number;
bucketDepth: number;
immutable: boolean;
remainingBalance: number;
}

Expand Down Expand Up @@ -39,7 +38,6 @@ async function main() {
owner: batch.owner,
depth: batch.depth,
bucketDepth: batch.bucketDepth,
immutableFlag: batch.immutable,
remainingBalance: batch.remainingBalance,
}));

Expand Down
33 changes: 6 additions & 27 deletions src/PostageStamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ contract PostageStamp is AccessControl, Pausable {
uint8 depth;
// Bucket depth defined in this batch
uint8 bucketDepth;
// Whether this batch is immutable.
bool immutableFlag;
// Normalised balance per chunk.
uint256 normalisedBalance;
// When was this batch last updated
Expand All @@ -92,7 +90,6 @@ contract PostageStamp is AccessControl, Pausable {
address owner;
uint8 depth;
uint8 bucketDepth;
bool immutableFlag;
uint256 remainingBalance;
}

Expand All @@ -107,8 +104,7 @@ contract PostageStamp is AccessControl, Pausable {
uint256 normalisedBalance,
address owner,
uint8 depth,
uint8 bucketDepth,
bool immutableFlag
uint8 bucketDepth
);

/**
Expand Down Expand Up @@ -184,15 +180,13 @@ contract PostageStamp is AccessControl, Pausable {
* @param _initialBalancePerChunk Initial balance per chunk.
* @param _depth Initial depth of the new batch.
* @param _nonce A random value used in the batch id derivation to allow multiple batches per owner.
* @param _immutable Whether the batch is mutable.
*/
function createBatch(
address _owner,
uint256 _initialBalancePerChunk,
uint8 _depth,
uint8 _bucketDepth,
bytes32 _nonce,
bool _immutable
bytes32 _nonce
) external whenNotPaused returns (bytes32) {
if (_owner == address(0)) {
revert ZeroAddress();
Expand Down Expand Up @@ -228,14 +222,13 @@ contract PostageStamp is AccessControl, Pausable {
owner: _owner,
depth: _depth,
bucketDepth: _bucketDepth,
immutableFlag: _immutable,
normalisedBalance: normalisedBalance,
lastUpdatedBlockNumber: block.number
});

tree.insert(batchId, normalisedBalance);

emit BatchCreated(batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);
emit BatchCreated(batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth);

return batchId;
}
Expand All @@ -247,15 +240,13 @@ contract PostageStamp is AccessControl, Pausable {
* @param _initialBalancePerChunk Initial balance per chunk of the batch.
* @param _depth Initial depth of the new batch.
* @param _batchId BatchId being copied (from previous version contract data).
* @param _immutable Whether the batch is mutable.
*/
function copyBatch(
address _owner,
uint256 _initialBalancePerChunk,
uint8 _depth,
uint8 _bucketDepth,
bytes32 _batchId,
bool _immutable
bytes32 _batchId
) public whenNotPaused {
if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {
revert AdministratorOnly();
Expand Down Expand Up @@ -288,14 +279,13 @@ contract PostageStamp is AccessControl, Pausable {
owner: _owner,
depth: _depth,
bucketDepth: _bucketDepth,
immutableFlag: _immutable,
normalisedBalance: normalisedBalance,
lastUpdatedBlockNumber: block.number
});

tree.insert(_batchId, normalisedBalance);

emit BatchCreated(_batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth, _immutable);
emit BatchCreated(_batchId, totalAmount, normalisedBalance, _owner, _depth, _bucketDepth);
}

/**
Expand All @@ -311,14 +301,7 @@ contract PostageStamp is AccessControl, Pausable {
for (uint i = 0; i < bulkBatches.length; i++) {
ImportBatch memory _batch = bulkBatches[i];
try
this.copyBatch(
_batch.owner,
_batch.remainingBalance,
_batch.depth,
_batch.bucketDepth,
_batch.batchId,
_batch.immutableFlag
)
this.copyBatch(_batch.owner, _batch.remainingBalance, _batch.depth, _batch.bucketDepth, _batch.batchId)
{
// Successful copyBatch call
} catch {
Expand Down Expand Up @@ -628,10 +611,6 @@ contract PostageStamp is AccessControl, Pausable {
return batches[_batchId].bucketDepth;
}

function batchImmutableFlag(bytes32 _batchId) public view returns (bool) {
return batches[_batchId].immutableFlag;
}

function batchNormalisedBalance(bytes32 _batchId) public view returns (uint256) {
return batches[_batchId].normalisedBalance;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Redistribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ contract Redistribution is AccessControl, Pausable {

function stampFunction(ChunkInclusionProof calldata entryProof) internal view {
// authentic
(address batchOwner, uint8 batchDepth, uint8 bucketDepth, , , ) = PostageContract.batches(
(address batchOwner, uint8 batchDepth, uint8 bucketDepth, , ) = PostageContract.batches(
entryProof.postageProof.postageId
);

Expand Down
51 changes: 5 additions & 46 deletions src/echidna/EchidnaPostageStampHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract EchidnaPostageActor {
token.approve(address(stamp), type(uint256).max);
}

function createBatchMutable(
function createBatch(
uint256 initialBalancePerChunk,
uint8 depth,
uint8 bucketDepth,
Expand All @@ -28,29 +28,7 @@ contract EchidnaPostageActor {
initialBalancePerChunk,
depth,
bucketDepth,
nonce,
false
)
);
if (ok && data.length >= 32) batchId = abi.decode(data, (bytes32));
}

function createBatchImmutable(
uint256 initialBalancePerChunk,
uint8 depth,
uint8 bucketDepth,
bytes32 nonce
) external returns (bool ok, bytes32 batchId) {
bytes memory data;
(ok, data) = address(stamp).call(
abi.encodeWithSelector(
stamp.createBatch.selector,
address(this),
initialBalancePerChunk,
depth,
bucketDepth,
nonce,
true
nonce
)
);
if (ok && data.length >= 32) batchId = abi.decode(data, (bytes32));
Expand Down Expand Up @@ -113,7 +91,6 @@ contract EchidnaPostageStampHarness {
uint256 internal pendingCreateNormalisedExpected;
uint8 internal pendingCreateDepth;
uint8 internal pendingCreateBucketDepth;
bool internal pendingCreateImmutable;

bool internal pendingTopUp;
bytes32 internal pendingTopUpBatchId;
Expand Down Expand Up @@ -146,7 +123,6 @@ contract EchidnaPostageStampHarness {

// Temporary inputs to reduce stack pressure in helpers.
bytes32 internal tmpNonce;
bool internal tmpImmutable;
bytes32 internal tmpBatchA;
bytes32 internal tmpBatchB;
bytes32 internal tmpBatchC;
Expand Down Expand Up @@ -193,18 +169,11 @@ contract EchidnaPostageStampHarness {
token.transfer(address(_actor(actorId)), x);
}

function act_createBatch(
uint8 actorId,
uint256 initialPerChunk,
uint8 depthRaw,
bytes32 nonce,
bool immutableFlag
) external {
function act_createBatch(uint8 actorId, uint256 initialPerChunk, uint8 depthRaw, bytes32 nonce) external {
_clearPending();
// Normalize expiry so createBatch's internal expireLimited() doesn't unexpectedly mutate other batches.
stamp.expireLimited(type(uint256).max);
tmpNonce = nonce;
tmpImmutable = immutableFlag;
_createBatchInternal(actorId, initialPerChunk, depthRaw);
_observePot(false);
}
Expand Down Expand Up @@ -424,7 +393,6 @@ contract EchidnaPostageStampHarness {
if (stamp.batchOwner(pendingBatchId) == address(0)) return false;
if (stamp.batchDepth(pendingBatchId) != pendingCreateDepth) return false;
if (stamp.batchBucketDepth(pendingBatchId) != pendingCreateBucketDepth) return false;
if (stamp.batchImmutableFlag(pendingBatchId) != pendingCreateImmutable) return false;

// Normalised balance is computed as currentTotalOutPayment + perChunk at creation time.
if (stamp.batchNormalisedBalance(pendingBatchId) != pendingCreateNormalisedExpected) return false;
Expand Down Expand Up @@ -497,7 +465,6 @@ contract EchidnaPostageStampHarness {
pendingCreateNormalisedExpected = 0;
pendingCreateDepth = 0;
pendingCreateBucketDepth = 0;
pendingCreateImmutable = false;

pendingTopUp = false;
pendingTopUpBatchId = bytes32(0);
Expand Down Expand Up @@ -537,7 +504,6 @@ contract EchidnaPostageStampHarness {
owner,
stamp.batchDepth(batchId),
stamp.batchBucketDepth(batchId),
stamp.batchImmutableFlag(batchId),
stamp.batchNormalisedBalance(batchId),
stamp.batchLastUpdatedBlockNumber(batchId)
)
Expand Down Expand Up @@ -604,15 +570,8 @@ contract EchidnaPostageStampHarness {
pendingCreateNormalisedExpected = stamp.currentTotalOutPayment() + perChunk;
pendingCreateDepth = depth;
pendingCreateBucketDepth = bucketDepth;
pendingCreateImmutable = tmpImmutable;

bool ok;
bytes32 batchId;
if (tmpImmutable) {
(ok, batchId) = a.createBatchImmutable(perChunk, depth, bucketDepth, tmpNonce);
} else {
(ok, batchId) = a.createBatchMutable(perChunk, depth, bucketDepth, tmpNonce);
}

(bool ok, bytes32 batchId) = a.createBatch(perChunk, depth, bucketDepth, tmpNonce);
if (!ok || batchId == bytes32(0)) return;

tracked[trackedCount % MAX_TRACKED] = batchId;
Expand Down
3 changes: 1 addition & 2 deletions src/echidna/EchidnaRedistributionClaimHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,11 @@ contract EchidnaPostageStampPotMock is IPostageStamp {
address owner,
uint8 depth,
uint8 bucketDepth,
bool immutableFlag,
uint256 normalisedBalance,
uint256 lastUpdatedBlockNumber
)
{
return (address(0), 0, 0, false, 0, 0);
return (address(0), 0, 0, 0, 0);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/echidna/EchidnaRedistributionHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ contract EchidnaPostageStampMock is IPostageStamp {
address owner,
uint8 depth,
uint8 bucketDepth,
bool immutableFlag,
uint256 normalisedBalance,
uint256 lastUpdatedBlockNumber
)
{
return (address(0), 0, 0, false, 0, 0);
return (address(0), 0, 0, 0, 0);
}
}

Expand Down
18 changes: 4 additions & 14 deletions src/echidna/EchidnaSystemHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,10 @@ contract EchidnaSystemActor {
uint256 initialBalancePerChunk,
uint8 depth,
uint8 bucketDepth,
bytes32 nonce,
bool immutableFlag
bytes32 nonce
) external returns (bool ok) {
(ok, ) = address(stamp).call(
abi.encodeWithSelector(
stamp.createBatch.selector,
owner,
initialBalancePerChunk,
depth,
bucketDepth,
nonce,
immutableFlag
)
abi.encodeWithSelector(stamp.createBatch.selector, owner, initialBalancePerChunk, depth, bucketDepth, nonce)
);
}

Expand Down Expand Up @@ -167,8 +158,7 @@ contract EchidnaSystemHarness {
uint256 initialBalancePerChunk,
uint8 depth,
uint8 bucketDepth,
bytes32 nonce,
bool imm
bytes32 nonce
) external {
EchidnaSystemActor a = actors[uint256(actorId) % ACTOR_COUNT];
uint8 minBucket = stamp.minimumBucketDepth();
Expand All @@ -182,7 +172,7 @@ contract EchidnaSystemHarness {
if (init < min) init = min;
if (init == 0) init = 1;

a.callCreateBatch(address(a), init, d, b, nonce, imm);
a.callCreateBatch(address(a), init, d, b, nonce);
}

function act_actor_topUp(uint8 actorId, bytes32 batchId, uint256 topupAmountPerChunk) external {
Expand Down
1 change: 0 additions & 1 deletion src/interface/IPostageStamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ interface IPostageStamp {
address owner,
uint8 depth,
uint8 bucketDepth,
bool immutableFlag,
uint256 normalisedBalance,
uint256 lastUpdatedBlockNumber
);
Expand Down
2 changes: 0 additions & 2 deletions tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ npx hardhat copy \
--depth 20 \
--bucketdepth 16 \
--batchid 0xabcd... \
--immutable false \
--contract 0x5678...
```

Expand All @@ -202,7 +201,6 @@ npx hardhat copy \
- `--depth`: Batch depth
- `--bucketdepth`: Bucket depth
- `--batchid`: Batch ID
- `--immutable`: Whether batch is immutable (true/false)
- `--contract`: PostageStamp contract address

#### What it does
Expand Down
Loading
Loading