-
Notifications
You must be signed in to change notification settings - Fork 0
codegen: use LibCodeGen.addressConstantString instead of a local copy #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thedavidmeister
wants to merge
2
commits into
main
Choose a base branch
from
codegen-dedupe-address-constant
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // SPDX-License-Identifier: LicenseRef-DCL-1.0 | ||
| // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd | ||
| pragma solidity =0.8.25; | ||
|
|
||
| import {Evidence} from "rain-verify-interface-0.1.0/src/interface/IVerifyV1.sol"; | ||
| import {LibEvidence} from "../../src/lib/LibEvidence.sol"; | ||
|
|
||
| /// @title LibEvidenceHarness | ||
| /// @notice Exposes `LibEvidence` internal functions as external calls so they | ||
| /// can be exercised from Foundry tests. | ||
| contract LibEvidenceHarness { | ||
| using LibEvidence for uint256[]; | ||
|
|
||
| /// Wraps `LibEvidence._updateEvidenceRef`. | ||
| function updateEvidenceRef(uint256[] memory refs, Evidence memory evidence, uint256 refsIndex) | ||
| external | ||
| pure | ||
| returns (uint256[] memory) | ||
| { | ||
| refs._updateEvidenceRef(evidence, refsIndex); | ||
| return refs; | ||
| } | ||
|
|
||
| /// Wraps `LibEvidence.asEvidences`. | ||
| function asEvidences(uint256[] memory refs) external pure returns (Evidence[] memory) { | ||
| return refs.asEvidences(); | ||
| } | ||
|
|
||
| /// Convenience: update a ref then immediately convert to `Evidence[]`. | ||
| function updateAndConvert(uint256[] memory refs, Evidence memory evidence, uint256 refsIndex) | ||
| external | ||
| pure | ||
| returns (Evidence[] memory) | ||
| { | ||
| refs._updateEvidenceRef(evidence, refsIndex); | ||
| return refs.asEvidences(); | ||
| } | ||
|
|
||
| /// Batch update three refs then convert to `Evidence[]` in a single call. | ||
| /// Required because `_updateEvidenceRef` stores memory pointers that don't | ||
| /// survive ABI encoding across external call boundaries. | ||
| function updateThreeAndConvert(Evidence memory e0, Evidence memory e1, Evidence memory e2) | ||
| external | ||
| pure | ||
| returns (Evidence[] memory) | ||
| { | ||
| uint256[] memory refs = new uint256[](3); | ||
| refs._updateEvidenceRef(e0, 0); | ||
| refs._updateEvidenceRef(e1, 1); | ||
| refs._updateEvidenceRef(e2, 2); | ||
| return refs.asEvidences(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // SPDX-License-Identifier: LicenseRef-DCL-1.0 | ||
| // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd | ||
| pragma solidity =0.8.25; | ||
|
|
||
| import {Evidence} from "rain-verify-interface-0.1.0/src/interface/IVerifyV1.sol"; | ||
| import {IVerifyCallbackV1} from "rain-verify-interface-0.1.0/src/interface/IVerifyCallbackV1.sol"; | ||
|
|
||
| /// @dev Tracks which callback hooks were called and with what arguments. | ||
| /// Implements `IVerifyCallbackV1` directly (no access control) so the Verify | ||
| /// contract can call it without ownership setup. Suitable only for testing. | ||
| contract MockCallback is IVerifyCallbackV1 { | ||
| /// @dev Incremented each time `afterAdd` is called. | ||
| uint256 public afterAddCalls; | ||
| /// @dev Incremented each time `afterApprove` is called. | ||
| uint256 public afterApproveCalls; | ||
| /// @dev Incremented each time `afterBan` is called. | ||
| uint256 public afterBanCalls; | ||
| /// @dev Incremented each time `afterRemove` is called. | ||
| uint256 public afterRemoveCalls; | ||
|
|
||
| /// @dev The `adder` from the most recent `afterAdd` call. | ||
| address public lastAddAdder; | ||
| /// @dev The evidences from the most recent `afterAdd` call. | ||
| Evidence[] public lastAddEvidences; | ||
|
|
||
| /// @dev The `approver` from the most recent `afterApprove` call. | ||
| address public lastApproveApprover; | ||
| /// @dev The evidences from the most recent `afterApprove` call. | ||
| Evidence[] public lastApproveEvidences; | ||
|
|
||
| /// @dev The `banner` from the most recent `afterBan` call. | ||
| address public lastBanBanner; | ||
| /// @dev The evidences from the most recent `afterBan` call. | ||
| Evidence[] public lastBanEvidences; | ||
|
|
||
| /// @dev The `remover` from the most recent `afterRemove` call. | ||
| address public lastRemoveRemover; | ||
| /// @dev The evidences from the most recent `afterRemove` call. | ||
| Evidence[] public lastRemoveEvidences; | ||
|
|
||
| /// @inheritdoc IVerifyCallbackV1 | ||
| function afterAdd(address adder, Evidence[] calldata evidences) external override { | ||
| afterAddCalls++; | ||
| lastAddAdder = adder; | ||
| delete lastAddEvidences; | ||
| for (uint256 i = 0; i < evidences.length; i++) { | ||
| lastAddEvidences.push(evidences[i]); | ||
| } | ||
| } | ||
|
|
||
| /// @inheritdoc IVerifyCallbackV1 | ||
| function afterApprove(address approver, Evidence[] calldata evidences) external override { | ||
| afterApproveCalls++; | ||
| lastApproveApprover = approver; | ||
| delete lastApproveEvidences; | ||
| for (uint256 i = 0; i < evidences.length; i++) { | ||
| lastApproveEvidences.push(evidences[i]); | ||
| } | ||
| } | ||
|
|
||
| /// @inheritdoc IVerifyCallbackV1 | ||
| function afterBan(address banner, Evidence[] calldata evidences) external override { | ||
| afterBanCalls++; | ||
| lastBanBanner = banner; | ||
| delete lastBanEvidences; | ||
| for (uint256 i = 0; i < evidences.length; i++) { | ||
| lastBanEvidences.push(evidences[i]); | ||
| } | ||
| } | ||
|
|
||
| /// @inheritdoc IVerifyCallbackV1 | ||
| function afterRemove(address remover, Evidence[] calldata evidences) external override { | ||
| afterRemoveCalls++; | ||
| lastRemoveRemover = remover; | ||
| delete lastRemoveEvidences; | ||
| for (uint256 i = 0; i < evidences.length; i++) { | ||
| lastRemoveEvidences.push(evidences[i]); | ||
| } | ||
| } | ||
|
|
||
| /// @dev Returns the number of evidences stored from the last `afterAdd`. | ||
| function lastAddEvidencesLength() external view returns (uint256) { | ||
| return lastAddEvidences.length; | ||
| } | ||
|
|
||
| /// @dev Returns the number of evidences stored from the last `afterApprove`. | ||
| function lastApproveEvidencesLength() external view returns (uint256) { | ||
| return lastApproveEvidences.length; | ||
| } | ||
|
|
||
| /// @dev Returns the number of evidences stored from the last `afterBan`. | ||
| function lastBanEvidencesLength() external view returns (uint256) { | ||
| return lastBanEvidences.length; | ||
| } | ||
|
|
||
| /// @dev Returns the number of evidences stored from the last `afterRemove`. | ||
| function lastRemoveEvidencesLength() external view returns (uint256) { | ||
| return lastRemoveEvidences.length; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // SPDX-License-Identifier: LicenseRef-DCL-1.0 | ||
| // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd | ||
| pragma solidity =0.8.25; | ||
|
|
||
| import {IInterpreterStoreV3} from "rain-interpreter-interface-0.1.0/src/interface/IInterpreterStoreV3.sol"; | ||
| import { | ||
| StateNamespace, | ||
| FullyQualifiedNamespace | ||
| } from "rain-interpreter-interface-0.1.0/src/interface/deprecated/v2/IInterpreterV3.sol"; | ||
|
|
||
| /// @dev Mock store that implements all required functions of | ||
| /// `IInterpreterStoreV3` as no-ops. | ||
| contract MockInterpreterStoreV3 is IInterpreterStoreV3 { | ||
| /// @inheritdoc IInterpreterStoreV3 | ||
| function set(StateNamespace, bytes32[] calldata) external override {} | ||
|
|
||
| /// @inheritdoc IInterpreterStoreV3 | ||
| function get(FullyQualifiedNamespace, bytes32) external pure override returns (bytes32) { | ||
| return bytes32(0); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // SPDX-License-Identifier: LicenseRef-DCL-1.0 | ||
| // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd | ||
| pragma solidity =0.8.25; | ||
|
|
||
| import {StackItem, EvalV4} from "rain-interpreter-interface-0.1.0/src/interface/IInterpreterV4.sol"; | ||
|
|
||
| /// @dev Mock interpreter that returns a configurable stack value from `eval4`. | ||
| /// Does NOT inherit `IInterpreterV4` because the interface declares `calldata` | ||
| /// return types which cannot be produced from Solidity storage/memory. The ABI | ||
| /// encoding is identical so the caller (AutoApprove) can decode the response | ||
| /// through the interface pointer without issue. | ||
| contract MockInterpreterV4 { | ||
| /// @dev The stack to return from `eval4`. | ||
| StackItem[] public sStack; | ||
|
|
||
| /// @dev Set the stack that `eval4` will return. | ||
| function setStack(StackItem[] memory stack) external { | ||
| delete sStack; | ||
| for (uint256 i = 0; i < stack.length; i++) { | ||
| sStack.push(stack[i]); | ||
| } | ||
| } | ||
|
|
||
| /// @dev Convenience to set a single-element stack. | ||
| function setReturnValue(StackItem value) external { | ||
| delete sStack; | ||
| sStack.push(value); | ||
| } | ||
|
|
||
| /// @dev Matches the `eval4` selector from `IInterpreterV4`. | ||
| function eval4(EvalV4 calldata) external view returns (StackItem[] memory stack, bytes32[] memory kvs) { | ||
| stack = sStack; | ||
| kvs = new bytes32[](0); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: rainlanguage/rain.verify
Length of output: 6224
🏁 Script executed:
Repository: rainlanguage/rain.verify
Length of output: 10519
🏁 Script executed:
Repository: rainlanguage/rain.verify
Length of output: 10213
🏁 Script executed:
Repository: rainlanguage/rain.verify
Length of output: 10213
Keep pointer creation and conversion in one external call.
updateEvidenceRefreturns rawEvidencememory pointers asuint256[]. Passing that result toasEvidencesin a later call can read invalid memory, return incorrect data, or revert. Remove the standalone wrappers or keep both operations in one wrapper, as inupdateAndConvertandupdateThreeAndConvert.🤖 Prompt for AI Agents