From 9d545150ecd9941498d5e41291c4ee5c3207e42d Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Thu, 18 Apr 2024 11:25:17 +0100 Subject: [PATCH 1/7] adding a new VIP for extension v3 --- vips/VIP-241.md | 3 +- vips/VIP-ExtensionV3.md | 145 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 vips/VIP-ExtensionV3.md diff --git a/vips/VIP-241.md b/vips/VIP-241.md index 0249a57..f9bcbd5 100644 --- a/vips/VIP-241.md +++ b/vips/VIP-241.md @@ -3,8 +3,7 @@ VIP: 241 Title: ERC Contract Adoption Description: | This Vechain Improvement Proposal (VIP) advocates for the adoption of Ethereum Request for Comment (ERC) standards, aiming to eliminate duplication and enhance interoperability by aligning Vechain contracts with their Ethereum counterparts. -Author: Darren Kelly, darren.kelly@vechain.rog -# TODO +Author: Darren Kelly, darren.kelly@vechain.org Discussions: https://vechain.discourse.group/t/add-vip-deprecate-vip-token-standards-in-favour-of-erc/93 Category: Application Status: Draft diff --git a/vips/VIP-ExtensionV3.md b/vips/VIP-ExtensionV3.md new file mode 100644 index 0000000..cde4d7f --- /dev/null +++ b/vips/VIP-ExtensionV3.md @@ -0,0 +1,145 @@ +--- +Title: EVM Clause Context +Description: This VIP proposes a an enhancement of the built-in extension contract to provide a context of the current clause being executed. +Author: @databeforedishonor and Darren Kelly (darren.kelly@vechain.org) +Discussions: https://vechain.discourse.group/t/mtt-induced-vulnerabilities-in-randomized-events/88 +Category: Core +Status: Draft +CreatedAt: 2024-04-18 + +--- + +## Overview + +The below VIP-XXX proposal outlines an upgrade to the EVM, which will expose clause information to the smart contract, via the built-in `extension` contract + +## Motivation + +Smart contracts developers may want to access information about the current clause being executed. For example, a smart contract can limit the number of clauses in case any malicious actor could exploit the contract via multiple clauses. + +## Rationale + +The design and decision to expose the clause context in the `extension` contract follows the same pattern as [VIP-191](https://github.com/vechain/VIPs/blob/master/vips/VIP-191.md). This time the `extension` contract will migrate from V2 to V3 to provide the clause context information. + +## Specification + +The `extension` contract will be extended to provide the following functions: + +```solidity +/// @title ExtensionV3 extends EVM global functions. +contract ExtensionV3 is ExtensionV2 { + + /** + * @dev Get the index of the current clause in the transaction. + */ + function txClauseIndex() public view returns (uint) { + return ExtensionV3Native(this).native_clauseIndex(); + } + + /** + * @dev Get the total number of clauses in the transaction. + */ + function txClauseCount() public view returns (uint) { + return ExtensionV3Native(this).native_clauseCount(); + } +} + +contract ExtensionV3Native is ExtensionV2Native { + function native_txClauseCount() public view returns (uint); + + function native_txClauseIndex() public view returns (uint); +} +``` + +## Test Cases + +### Test Case 1: Get the index of the current clause in the transaction + +Given that `3341b04d` is the function signature of the `txClauseIndex` function, the following curl command should return the index of the current clause in the transaction. + +#### Request 1 + +```bash +curl --request POST \ + --url 'http://localhost:8669/accounts/*' \ + --header 'Accept: application/json, text/plain' \ + --header 'Content-Type: application/json' \ + --data '{ + "clauses": [ + { + "to": "0x0000000000000000000000457874656e73696f6e", + "value": "0x0", + "data": "0xa6dfac1a" + }, + { + "to": "0x0000000000000000000000457874656e73696f6e", + "value": "0x0", + "data": "0xa6dfac1a" + } + ] +}' +``` + +#### Response 1 + +```json +[ + { + "data": "0x0000000000000000000000000000000000000000000000000000000000000001", + ...other fields + }, + { + "data": "0x0000000000000000000000000000000000000000000000000000000000000002", + ...other fields + } +] +``` + +### Test Case 2: Get the total number of clauses in the transaction + +Given that `c26ae5e1` is the function signature of the `txClauseCount` function, the following curl command should return the total number of clauses in the transaction: + +#### Request 2 + +```bash +curl --request POST \ + --url 'http://localhost:8669/accounts/*' \ + --header 'Accept: application/json, text/plain' \ + --header 'Content-Type: application/json' \ + --data '{ + "clauses": [ + { + "to": "0x0000000000000000000000457874656e73696f6e", + "value": "0x0", + "data": "0xa6dfac1a" + }, + ...clause 2, + ...clause 3 + ...clause 4 + ] +}' +``` + +#### Response 2 + +```json +[ + { + "data": "0x0000000000000000000000000000000000000000000000000000000000000004", + ...other fields + }, + ...output 2, + ...output 3 + ...output 4 +] +``` + +## Reference Implementation + +N/A + +## Security Considerations + +N/A + +Copyright and related rights waived via [CC0](./LICENSE.md). From 1113bcfe0b6f150d393a4faba92c8455cfe0fcca Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Thu, 18 Apr 2024 11:27:50 +0100 Subject: [PATCH 2/7] fix typo --- vips/VIP-ExtensionV3.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vips/VIP-ExtensionV3.md b/vips/VIP-ExtensionV3.md index cde4d7f..3b731f9 100644 --- a/vips/VIP-ExtensionV3.md +++ b/vips/VIP-ExtensionV3.md @@ -15,7 +15,7 @@ The below VIP-XXX proposal outlines an upgrade to the EVM, which will expose cla ## Motivation -Smart contracts developers may want to access information about the current clause being executed. For example, a smart contract can limit the number of clauses in case any malicious actor could exploit the contract via multiple clauses. +Smart contract developers may want to access information about the current clause being executed. For example, a smart contract can limit the number of clauses in case any malicious actor could exploit the contract via multiple clauses. ## Rationale From ee97fc3650c319f7a08653d1f0311c8f5799ca9c Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Thu, 18 Apr 2024 11:32:56 +0100 Subject: [PATCH 3/7] fix errors --- vips/VIP-ExtensionV3.md | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/vips/VIP-ExtensionV3.md b/vips/VIP-ExtensionV3.md index 3b731f9..02e9f7f 100644 --- a/vips/VIP-ExtensionV3.md +++ b/vips/VIP-ExtensionV3.md @@ -1,6 +1,6 @@ --- Title: EVM Clause Context -Description: This VIP proposes a an enhancement of the built-in extension contract to provide a context of the current clause being executed. +Description: This VIP proposes an enhancement of the built-in extension contract to provide a context of the current clause being executed. Author: @databeforedishonor and Darren Kelly (darren.kelly@vechain.org) Discussions: https://vechain.discourse.group/t/mtt-induced-vulnerabilities-in-randomized-events/88 Category: Core @@ -19,7 +19,7 @@ Smart contract developers may want to access information about the current claus ## Rationale -The design and decision to expose the clause context in the `extension` contract follows the same pattern as [VIP-191](https://github.com/vechain/VIPs/blob/master/vips/VIP-191.md). This time the `extension` contract will migrate from V2 to V3 to provide the clause context information. +The design and decision to expose the clause context in the `extension` contract follows the same pattern as [VIP-191](https://github.com/vechain/VIPs/blob/master/vips/VIP-191.md). This time, the `extension` contract will migrate from V2 to V3 to provide the clause context information. ## Specification @@ -33,14 +33,14 @@ contract ExtensionV3 is ExtensionV2 { * @dev Get the index of the current clause in the transaction. */ function txClauseIndex() public view returns (uint) { - return ExtensionV3Native(this).native_clauseIndex(); + return ExtensionV3Native(this).native_txClauseIndex(); } /** * @dev Get the total number of clauses in the transaction. */ function txClauseCount() public view returns (uint) { - return ExtensionV3Native(this).native_clauseCount(); + return ExtensionV3Native(this).native_txClauseCount(); } } @@ -134,12 +134,4 @@ curl --request POST \ ] ``` -## Reference Implementation - -N/A - -## Security Considerations - -N/A - Copyright and related rights waived via [CC0](./LICENSE.md). From ae8166b4521783f7a590878e997901e8e575df8e Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Thu, 18 Apr 2024 11:40:25 +0100 Subject: [PATCH 4/7] update description --- vips/VIP-ExtensionV3.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vips/VIP-ExtensionV3.md b/vips/VIP-ExtensionV3.md index 02e9f7f..5968254 100644 --- a/vips/VIP-ExtensionV3.md +++ b/vips/VIP-ExtensionV3.md @@ -1,6 +1,6 @@ --- Title: EVM Clause Context -Description: This VIP proposes an enhancement of the built-in extension contract to provide a context of the current clause being executed. +Description: This VIP proposes an enhancement of the built-in extension contract to provide information about the clauses in the current transaction. Author: @databeforedishonor and Darren Kelly (darren.kelly@vechain.org) Discussions: https://vechain.discourse.group/t/mtt-induced-vulnerabilities-in-randomized-events/88 Category: Core From 258c83b3aa13968bd09c0d9e1e7dc1571018c8a8 Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Thu, 18 Apr 2024 14:32:23 +0100 Subject: [PATCH 5/7] add example of coinflip --- vips/VIP-241.md | 2 +- vips/VIP-ExtensionV3.md | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/vips/VIP-241.md b/vips/VIP-241.md index f9bcbd5..c3a1392 100644 --- a/vips/VIP-241.md +++ b/vips/VIP-241.md @@ -3,7 +3,7 @@ VIP: 241 Title: ERC Contract Adoption Description: | This Vechain Improvement Proposal (VIP) advocates for the adoption of Ethereum Request for Comment (ERC) standards, aiming to eliminate duplication and enhance interoperability by aligning Vechain contracts with their Ethereum counterparts. -Author: Darren Kelly, darren.kelly@vechain.org +Author: Darren Kelly (darren.kelly@vechain.org) Discussions: https://vechain.discourse.group/t/add-vip-deprecate-vip-token-standards-in-favour-of-erc/93 Category: Application Status: Draft diff --git a/vips/VIP-ExtensionV3.md b/vips/VIP-ExtensionV3.md index 5968254..b017f24 100644 --- a/vips/VIP-ExtensionV3.md +++ b/vips/VIP-ExtensionV3.md @@ -1,5 +1,5 @@ --- -Title: EVM Clause Context +Title: Extend EVM's context to expose clause information Description: This VIP proposes an enhancement of the built-in extension contract to provide information about the clauses in the current transaction. Author: @databeforedishonor and Darren Kelly (darren.kelly@vechain.org) Discussions: https://vechain.discourse.group/t/mtt-induced-vulnerabilities-in-randomized-events/88 @@ -15,7 +15,33 @@ The below VIP-XXX proposal outlines an upgrade to the EVM, which will expose cla ## Motivation -Smart contract developers may want to access information about the current clause being executed. For example, a smart contract can limit the number of clauses in case any malicious actor could exploit the contract via multiple clauses. +Smart contract developers may want to access information about the current clause being executed. For example, a smart contract can limit the number of clauses in case any malicious actor could exploit the contract via multiple clauses. The example given for the motivation of this VIP is: + +```gherkin +Feature: Accessing Information about Current Clause in Smart Contracts + + Scenario: Limiting the number of clauses in a smart contract + Given a Coin flip contract where heads reward 10 ERC20 tokens and tails result in loss + When I attempt to flip the coin with an empty wallet + Then on Attempt 1: + And Clause 1: flip the coin, resulting in Tails + And Clause 2: attempt to transfer 10 tokens to wallet B + And the transaction reverts due to insufficient balance (balanceOf(token) = 0) + And on Attempt 2: + And Clause 1: flip the coin, resulting in Heads + And Clause 2: transfer 10 tokens to wallet B + And the transaction succeeds (balanceOf(token) = 10) + + Scenario: Implementing a possible solution + Given the need for developers to access information about the current clause being executed + When two built-in view functions are added for developers: + | Function | Description | + | txClauseCount() | Returns the count of clauses at the beginning of the tx | + | txClauseIndex() | Returns the index of the current clause being executed | + Then developers can use these functions to implement modifiers preventing clauses from coming after certain events, such as: + | Modifier | Description | + | onlyLastClause(ext.txClauseCount() == ext.txClauseIndex()) | Ensures that the clause is the last one executed in the transaction +``` ## Rationale From ce7c4f3348f7dae85b15616e34717ba490014c21 Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Thu, 18 Apr 2024 15:52:34 +0100 Subject: [PATCH 6/7] update to resolve pr comments --- vips/VIP-ExtensionV3.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vips/VIP-ExtensionV3.md b/vips/VIP-ExtensionV3.md index b017f24..d3f7e7e 100644 --- a/vips/VIP-ExtensionV3.md +++ b/vips/VIP-ExtensionV3.md @@ -45,7 +45,7 @@ Feature: Accessing Information about Current Clause in Smart Contracts ## Rationale -The design and decision to expose the clause context in the `extension` contract follows the same pattern as [VIP-191](https://github.com/vechain/VIPs/blob/master/vips/VIP-191.md). This time, the `extension` contract will migrate from V2 to V3 to provide the clause context information. +The `extension` contract should migrate from V2 to V3 to provide the clause context information. ## Specification From 42eb83ec71b53250508ed13ee413d21fe24c9a54 Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Tue, 14 May 2024 08:40:17 +0100 Subject: [PATCH 7/7] fix: remove example --- vips/VIP-ExtensionV3.md | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/vips/VIP-ExtensionV3.md b/vips/VIP-ExtensionV3.md index d3f7e7e..34f17ae 100644 --- a/vips/VIP-ExtensionV3.md +++ b/vips/VIP-ExtensionV3.md @@ -15,33 +15,7 @@ The below VIP-XXX proposal outlines an upgrade to the EVM, which will expose cla ## Motivation -Smart contract developers may want to access information about the current clause being executed. For example, a smart contract can limit the number of clauses in case any malicious actor could exploit the contract via multiple clauses. The example given for the motivation of this VIP is: - -```gherkin -Feature: Accessing Information about Current Clause in Smart Contracts - - Scenario: Limiting the number of clauses in a smart contract - Given a Coin flip contract where heads reward 10 ERC20 tokens and tails result in loss - When I attempt to flip the coin with an empty wallet - Then on Attempt 1: - And Clause 1: flip the coin, resulting in Tails - And Clause 2: attempt to transfer 10 tokens to wallet B - And the transaction reverts due to insufficient balance (balanceOf(token) = 0) - And on Attempt 2: - And Clause 1: flip the coin, resulting in Heads - And Clause 2: transfer 10 tokens to wallet B - And the transaction succeeds (balanceOf(token) = 10) - - Scenario: Implementing a possible solution - Given the need for developers to access information about the current clause being executed - When two built-in view functions are added for developers: - | Function | Description | - | txClauseCount() | Returns the count of clauses at the beginning of the tx | - | txClauseIndex() | Returns the index of the current clause being executed | - Then developers can use these functions to implement modifiers preventing clauses from coming after certain events, such as: - | Modifier | Description | - | onlyLastClause(ext.txClauseCount() == ext.txClauseIndex()) | Ensures that the clause is the last one executed in the transaction -``` +Smart contract developers may want to access information about the current clause being executed. ## Rationale