Skip to content

[GrantShares] GBA-03 Redundant Null Validation #73

Open
@OT-kraftchain

Description

@OT-kraftchain

An inefficiency has been identified in the GrantSharesBridgeAdapter.java contract code where redundant null value validation is performed. The method implements explicit null value checks before calling the isValid() method, even though this method already incorporates null validation internally.
This redundancy in validations generates unnecessary gas consumption during contract execution on the blockchain. In the context of the N3 blockchain, where each computational operation has an associated gas cost, eliminating these duplicate validations could result in a significant reduction in transaction execution costs.

References
neow3j/devpack/Hash160.java#L68-L85

Source Code References

if (token == null || !Hash160.isValid(token) || token.isZero()) {
abort("invalid token");
}
if (to == null || !Hash160.isValid(to) || to.isZero()) {
abort("invalid to");
}
if (amount == null || amount <= 0) {
abort("invalid amount");
}

if (funder == null || !Hash160.isValid(funder) || funder.isZero()) {

if (gsGovContract == null || !Hash160.isValid(gsGovContract) || gsGovContract.isZero()) {
abort("invalid GrantSharesGov contract");
}
Storage.put(context, GRANTSHARESGOV_CONTRACT_KEY, gsGovContract);
Hash160 gsTreasury = deployData.grantSharesTreasuryContract;
if (gsGovContract == null || !Hash160.isValid(gsTreasury) || gsTreasury.isZero()) {
abort("invalid GrantSharesTreasury contract");
}
Storage.put(context, GRANTSHARESTREASURY_CONTRACT_KEY, gsTreasury);
Hash160 bridgeContract = deployData.bridgeContract;
if (bridgeContract == null || !Hash160.isValid(bridgeContract) || bridgeContract.isZero()) {
abort("invalid bridge contract");
}
Storage.put(context, BRIDGE_CONTRACT_KEY, bridgeContract);
Integer initialMaxFee = deployData.initialMaxFee;
if (initialMaxFee == null || initialMaxFee < 0) {
abort("invalid initial max fee");
}
Storage.put(context, MAX_FEE_KEY, initialMaxFee);
Hash160 whitelistedFunder = deployData.initialWhitelistedFunder;
if (whitelistedFunder == null || !Hash160.isValid(whitelistedFunder) || whitelistedFunder.isZero()) {
abort("invalid whitelisted funder");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions