You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
In their current state, the SingleDecapacitor and the HashChainDecapacitor only seem to be doing some mathematical computation (verifyMessageInclusion()), without accessing any meaningful state. If no more state-based computations are planned to be added in them in the future, it makes sense to either
or convert them into libraries, if more such stateless computations are anticipated
to save deployment costs for a separate contract (>= 21k gas).
Describe the solution you'd like
(1) above is self-explanatory.
For (2), the HashChainDecapacitor library could look something like this:
// SPDX-License-Identifier: GPL-3.0-onlypragma solidity0.8.7;
libraryHashChainDecapacitor {
/** * @notice Verifies whether a message is included in the given hash chain. * @param root_ The root of the hash chain. * @param packedMessage_ The packed message whose inclusion in the hash chain needs to be verified. * @param proof_ The proof for the inclusion of the packed message in the hash chain. * @return True if the packed message is included in the hash chain and the provided root is the calculated root; otherwise, false. */function verifyMessageInclusion(
bytes32root_,
bytes32packedMessage_,
bytescalldataproof_
) internalpurereturns (bool) {
bytes32[] memory chain =abi.decode(proof_, (bytes32[]));
uint256 len = chain.length;
bytes32 generatedRoot;
bool isIncluded;
for (uint256 i =0; i < len; i++) {
generatedRoot =keccak256(abi.encode(generatedRoot, chain[i]));
if (chain[i] == packedMessage_) isIncluded =true;
}
return root_ == generatedRoot && isIncluded;
}
}
and be used in the HashChainCapacitor contract as:
// SPDX-License-Identifier: GPL-3.0-onlypragma solidity0.8.7;
import"./BaseCapacitor.sol";
import"../libraries/HashChainDecapacitor.sol";
/** * @title HashChainCapacitor * @notice This is an experimental contract and have known bugs * @dev A contract that implements ICapacitor and stores packed messages in a hash chain. * The hash chain is made of packets, each packet contains a maximum of 10 messages. * Each new message added to the chain is hashed with the previous root to create a new root. * When a packet is full, a new packet is created and the root of the last packet is sealed. */contractHashChainCapacitorisBaseCapacitor {
uint256private _chainLength;
uint256private constant _MAX_LEN =10;
/** rest of the contract *//** * @notice Verifies whether a message is included in the given hash chain. * @param root_ The root of the hash chain. * @param packedMessage_ The packed message whose inclusion in the hash chain needs to be verified. * @param proof_ The proof for the inclusion of the packed message in the hash chain. * @return True if the packed message is included in the hash chain and the provided root is the calculated root; otherwise, false. */function verifyMsgInclusion(
bytes32root_,
bytes32packedMessage_,
bytescalldataproof_
) externalpurereturns (bool) {
HashChainDecapacitor.verifyMessageInclusion(root_, packedMessage_, proof_);
}
}
Plus, this library fits perfectly with the gas optimization suggested in #256.
We want to leave room to make the decapacitor stateful and to support different hash functions when sibling chain is non EVM. Both have not been made libraries due to this.
Is your feature request related to a problem? Please describe.
In their current state, the SingleDecapacitor and the HashChainDecapacitor only seem to be doing some mathematical computation (
verifyMessageInclusion()
), without accessing any meaningful state. If no more state-based computations are planned to be added in them in the future, it makes sense to eitherverifyMessageInclusion()
s of SingleDecapacitor and HashChainDecapacitor in SingleCapacitor and HashChainCapacitor respectivelyto save deployment costs for a separate contract (>= 21k gas).
Describe the solution you'd like
(1) above is self-explanatory.
For (2), the HashChainDecapacitor library could look something like this:
and be used in the HashChainCapacitor contract as:
Plus, this library fits perfectly with the gas optimization suggested in #256.
A similar argument could also be made for Hasher.
Describe alternatives you've considered
Alternative has been discussed above.
The text was updated successfully, but these errors were encountered: