Skip to content

Commit

Permalink
Merge branch 'ethereum:master' into TCTC
Browse files Browse the repository at this point in the history
  • Loading branch information
kofujimura authored Jul 13, 2023
2 parents 19c4e27 + d73953e commit 8b2cc3f
Show file tree
Hide file tree
Showing 21 changed files with 426 additions and 267 deletions.
2 changes: 1 addition & 1 deletion EIPS/eip-3643.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: T-REX - Token for Regulated EXchanges
description: An institutional grade security token contract that provides interfaces for the management and compliant transfer of security tokens.
author: Joachim Lebrun (@Joachim-Lebrun), Tony Malghem (@TonyMalghem), Kevin Thizy (@Nakasar), Luc Falempin (@lfalempin), Adam Boudjemaa (@Aboudjem)
discussions-to: https://ethereum-magicians.org/t/eip-3643-proposition-of-the-t-rex-token-standard-for-securities/6844
status: Draft
status: Review
type: Standards Track
category: ERC
created: 2021-07-09
Expand Down
100 changes: 3 additions & 97 deletions EIPS/eip-4200.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ The main benefit of these instruction is reduced gas cost (both at deploy and ex

We introduce three new instructions on the same block number [EIP-3540](./eip-3540.md) is activated on:

1. `RJUMP` (0x5c) - relative jump
2. `RJUMPI` (0x5d) - conditional relative jump
3. `RJUMPV` (0x5e) - relative jump via jump table
1. `RJUMP` (0xe0) - relative jump
2. `RJUMPI` (0xe1) - conditional relative jump
3. `RJUMPV` (0xe2) - relative jump via jump table

If the code is legacy bytecode, all of these instructions result in an *exceptional halt*. (*Note: This means no change to behaviour.*)

Expand Down Expand Up @@ -154,100 +154,6 @@ This change poses no risk to backwards compatibility, as it is introduced at the
- `case` outside of table bounds (`case > max_index`, fallback case)
- `case` > 255

## Reference Implementation

```python
# The ranges below are as specified in the Yellow Paper.
# Note: range(s, e) excludes e, hence the +1
valid_opcodes = [
*range(0x00, 0x0b + 1),
*range(0x10, 0x1d + 1),
0x20,
*range(0x30, 0x3f + 1),
*range(0x40, 0x48 + 1),
*range(0x50, 0x5e + 1),
*range(0x60, 0x6f + 1),
*range(0x70, 0x7f + 1),
*range(0x80, 0x8f + 1),
*range(0x90, 0x9f + 1),
*range(0xa0, 0xa4 + 1),
# Note: 0xfe is considered assigned.
*range(0xf0, 0xf5 + 1), 0xfa, 0xfd, 0xfe, 0xff
]

# STOP, RETURN, REVERT, INVALID, SELFDESTRUCT
terminating_opcodes = [ 0x00, 0xf3, 0xfd, 0xfe, 0xff ]

immediate_sizes = 256 * [0]
immediate_sizes[0x5c] = 2 # RJUMP
immediate_sizes[0x5d] = 2 # RJUMPI
for opcode in range(0x60, 0x7f + 1): # PUSH1..PUSH32
immediate_sizes[opcode] = opcode - 0x60 + 1

# Raises ValidationException on invalid code
def validate_code(code: bytes):
# Note that EOF1 already asserts this with the code section requirements
assert len(code) > 0

opcode = 0
pos = 0
rjumpdests = set()
immediates = set()
while pos < len(code):
# Ensure the opcode is valid
opcode = code[pos]
pos += 1
if not opcode in valid_opcodes:
raise ValidationException("undefined instruction")

pc_post_instruction = pos + immediate_sizes[opcode]

if opcode == 0x5c or opcode == 0x5d:
if pos + 2 > len(code):
raise ValidationException("truncated relative jump offset")
offset = int.from_bytes(code[pos:pos+2], byteorder = "big", signed = True)

rjumpdest = pc_post_instruction + offset
if rjumpdest < 0 or rjumpdest >= len(code):
raise ValidationException("relative jump destination out of bounds")

rjumpdests.add(rjumpdest)
elif opcode == 0x5e:
if pos + 1 > len(code):
raise ValidationException("truncated jump table")
jump_table_size = code[pos] + 1

pc_post_instruction = pos + 1 + 2 * jump_table_size
if pc_post_instruction > len(code):
raise ValidationException("truncated jump table")

for offset_pos in range(pos + 1, pc_post_instruction, 2):
offset = int.from_bytes(code[offset_pos:offset_pos+2], byteorder = "big", signed = True)

rjumpdest = pc_post_instruction + offset
if rjumpdest < 0 or rjumpdest >= len(code):
raise ValidationException("relative jump destination out of bounds")
rjumpdests.add(rjumpdest)


# Save immediate value positions
immediates.update(range(pos, pc_post_instruction))
# Skip immediates
pos = pc_post_instruction

# Ensure last opcode's immediate doesn't go over code end
if pos != len(code):
raise ValidationException("truncated immediate")

# opcode is the *last opcode*
if not opcode in terminating_opcodes:
raise ValidationException("no terminating instruction")

# Ensure relative jump destinations don't target immediates
if not rjumpdests.isdisjoint(immediates):
raise ValidationException("relative jump destination targets immediate")
```

## Security Considerations

TBA
Expand Down
48 changes: 24 additions & 24 deletions EIPS/eip-4844.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,30 @@ def calc_excess_data_gas(parent: Header) -> int:

For the first post-fork block, both `parent.data_gas_used` and `parent.excess_data_gas` are evaluated as `0`.

### Gas accounting

We introduce data gas as a new type of gas. It is independent of normal gas and follows its own targeting rule, similar to EIP-1559.
We use the `excess_data_gas` header field to store persistent data needed to compute the data gas price. For now, only blobs are priced in data gas.

```python
def calc_data_fee(header: Header, tx: SignedBlobTransaction) -> int:
return get_total_data_gas(tx) * get_data_gasprice(header)

def get_total_data_gas(tx: SignedBlobTransaction) -> int:
return DATA_GAS_PER_BLOB * len(tx.blob_versioned_hashes)

def get_data_gasprice(header: Header) -> int:
return fake_exponential(
MIN_DATA_GASPRICE,
header.excess_data_gas,
DATA_GASPRICE_UPDATE_FRACTION
)
```

The block validity conditions are modified to include data gas checks (see the [Execution layer validation](#execution-layer-validation) section below).

The actual `data_fee` as calculated via `calc_data_fee` is deducted from the sender balance before transaction execution and burned, and is not refunded in case of transaction failure.

### Opcode to get versioned hashes

We add an instruction `BLOBHASH` (with opcode `HASH_OPCODE_BYTE`) which reads `index` from the top of the stack
Expand Down Expand Up @@ -206,30 +230,6 @@ def point_evaluation_precompile(input: Bytes) -> Bytes:

The precompile MUST reject non-canonical field elements (i.e. provided field elements MUST be strictly less than `BLS_MODULUS`).

### Gas accounting

We introduce data gas as a new type of gas. It is independent of normal gas and follows its own targeting rule, similar to EIP-1559.
We use the `excess_data_gas` header field to store persistent data needed to compute the data gas price. For now, only blobs are priced in data gas.

```python
def calc_data_fee(header: Header, tx: SignedBlobTransaction) -> int:
return get_total_data_gas(tx) * get_data_gasprice(header)

def get_total_data_gas(tx: SignedBlobTransaction) -> int:
return DATA_GAS_PER_BLOB * len(tx.blob_versioned_hashes)

def get_data_gasprice(header: Header) -> int:
return fake_exponential(
MIN_DATA_GASPRICE,
header.excess_data_gas,
DATA_GASPRICE_UPDATE_FRACTION
)
```

The block validity conditions are modified to include data gas checks (see the [Execution layer validation](#execution-layer-validation) section below).

The actual `data_fee` as calculated via `calc_data_fee` is deducted from the sender balance before transaction execution and burned, and is not refunded in case of transaction failure.

### Consensus layer validation

On the consensus layer the blobs are referenced, but not fully encoded, in the beacon block body.
Expand Down
Loading

0 comments on commit 8b2cc3f

Please sign in to comment.