Skip to content
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

Lock states #110

Merged
merged 14 commits into from
Dec 17, 2024
Merged

Lock states #110

merged 14 commits into from
Dec 17, 2024

Conversation

jimthematrix
Copy link
Contributor

@jimthematrix jimthematrix commented Dec 12, 2024

Replace lockProof() with lockStates(), because lockProof() is keyed off of the proof bytes which doesn't guarantee uniqueness of the individual states to be spent. As such it can't prevent the owner from spending the state(s) that are supposed to be used in a multi-step flow such as DvP.

For example, consider the following scenario:

  • Alice and Bob are in a trade, where Alice sends Bob an asset token assetUTXO-1, and Bob sends Alice payment two tokens paymentUTXO-1 and paymentUTXO-2
  • Alice generates the proof, p1, for transferring assetUTXO-1 to assetUTXO-2 with Bob as the owner
  • Alice locks the proof p1 and sets the DvP contract as the delegate (who is allowed to submit the proof to complete the transfer)
  • Bob generates the proof, p2, for spending both paymentUTXO-1 and paymentUTXO-2 in order to pay Alice
  • Bob locks the proof p2 and sets the DvP contract as the delegate
  • Bob then constructs another transaction that spends paymentUTXO-1 to pay Charlie for another trade, that transaction will be successful because it uses a different proof
  • when the DvP contract settles the final trade, the payment leg will fail because one of the UTXOs, paymentUTXO-1, in the input is already spent

Using lockStates() on the other hand, can guarantee that the individual input states are locked and delegated to an orchestration contract, which is the only account that can unlock or spend the states.

  • support tokens that do not use nullifiers
  • support tokens that use nullifiers

Copy link
Contributor

@Chengxuan Chengxuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jimthematrix I couldn't figure out how we protect locked UTXOs not to be withdrawn.

Can we add a test for that?

for (uint256 i = 0; i < utxos.length; ++i) {
utxosArray[i] = utxos[i];
}
for (uint256 i = utxos.length; i < 10; ++i) {
Copy link
Contributor

@Chengxuan Chengxuan Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hard coded batch size of 10 in the condition, could this be replaced with MAX_BATCH?

Comment on lines 61 to 62
address _lockVerifier,
address _batchLockVerifier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these not using the interface types rather than address?

@@ -382,6 +383,52 @@ describe("Zeto based fungible token with anonymity without encryption or nullifi
});
});

describe("lockStates() tests", function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add a test for withdraw()

// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pragma circom 2.1.9;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should consider 2.2.1 for new circuits

// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pragma circom 2.1.9;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment here for the version

@jimthematrix
Copy link
Contributor Author

thanks @Chengxuan for catching the missing checks in the withdraw() function. will add to the next commit along with addressing your other comments

@Chengxuan Chengxuan merged commit 5b7a9dd into main Dec 17, 2024
6 checks passed
@Chengxuan Chengxuan deleted the lock-states branch December 17, 2024 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants