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

Extend EVM's context to expose clause information #73

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions vips/VIP-241.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, [email protected]
# TODO
Author: Darren Kelly, [email protected]
darrenvechain marked this conversation as resolved.
Show resolved Hide resolved
Discussions: https://vechain.discourse.group/t/add-vip-deprecate-vip-token-standards-in-favour-of-erc/93
Category: Application
Status: Draft
Expand Down
137 changes: 137 additions & 0 deletions vips/VIP-ExtensionV3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---
Title: EVM Clause Context
darrenvechain marked this conversation as resolved.
Show resolved Hide resolved
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 ([email protected])
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 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.
libotony marked this conversation as resolved.
Show resolved Hide resolved

## 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.
darrenvechain marked this conversation as resolved.
Show resolved Hide resolved

## 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_txClauseIndex();
}

/**
* @dev Get the total number of clauses in the transaction.
*/
function txClauseCount() public view returns (uint) {
return ExtensionV3Native(this).native_txClauseCount();
}
}

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
]
```

Copyright and related rights waived via [CC0](./LICENSE.md).