From 1c9f267c15c2937bab8d987d338fc3958e2bb87c Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sat, 6 May 2023 12:41:23 -0700 Subject: [PATCH 01/16] reduce transient pricing --- EIPS/transient-pricing.md | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 EIPS/transient-pricing.md diff --git a/EIPS/transient-pricing.md b/EIPS/transient-pricing.md new file mode 100644 index 0000000000000..e3cc3d2240f3c --- /dev/null +++ b/EIPS/transient-pricing.md @@ -0,0 +1,55 @@ +--- +title: Decrease TLOAD/TSTORE pricing for common cases +description: Improve the efficiency of TLOAD/TSTORE by introducing a quadratic(?) pricing model. +author: tbd +discussions-to: none yet +status: Draft +type: Standards Track +category: Core +created: tbd +requires: 1153 +--- + +## Abstract + +Increase the efficiency of TLOAD/TSTORE for common use cases, while providing a quadratic pricing model to prevent DoS vectors. + +## Motivation + +EIP-1153 introduces a new storage region, termed "transient storage", which behaves like storage in the sense that it is word-addressed and persists between call frames, but unlike storage in the sense that it is wiped at the end of each transaction. During development of the 1153 specification, it was decided to match the pricing to be the same as warm storage loads and stores. This was for two reasons: conceptual simplicity of the EIP, and it also addressed concerns about two related DoS vectors: being able to allocate too much transient storage, and the cost of rolling back state in the case of reverts. + +One of the most important use cases that EIP-1153 enables is cheap reentrancy protection. In fact, if transient storage is cheap enough for the first few slots, reentrancy protection can be enabled by default at the language level without too much burden to users, while simultaneously preventing the largest - and most expensive! - class of smart contract vulnerabilities. + +Furthermore, it seems that transient storage is fundamentally overpriced. Its pricing does not interact with refunds, it only requires a new allocation on contract load (as opposed to memory, which requires a fresh allocation on every call), and has no interaction with database journaling. + +This EIP proposes a quadratic pricing model, which is cheaper for common cases (fewer than 33 slots are written per contract), while making DoS using transient storage prohibitively expensive. + + +## Specification +The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174. + +The gas cost for TLOAD is proposed to be 3 gas. The gas cost for TSTORE is proposed to be 3 gas + `expansion_cost`, where expansion cost is calculated as 3x the number of transient slots allocated for this contract. + +The maximum number of transient slots which can be allocated on a single contract given 30m gas is approximately 4,471 (solution to `x(x-1)/2*3 + 3*x = 30_000_000`), which totals 143KB. + +The maximum number of transient slots which can be allocated in a transaction if you use the strategy of calling a new contract (also designed to maximize transient storage allocation) once the cost of TSTORE is more than the cost of calling a cold contract (2600 gas) is roughly 23,068, which totals 722KB. + +## Rationale + +TBD + +## Backwards Compatibility + +No backward compatibility issues found. + +## Test Cases + +## Reference Implementation + +## Security Considerations + +Needs discussion. + +## Copyright + +Copyright and related rights waived via [CC0](../LICENSE.md). From ff162442a5b8840a7698d47049615160112fa409 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Fri, 2 Jun 2023 12:39:09 -0400 Subject: [PATCH 02/16] add authors --- EIPS/transient-pricing.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/EIPS/transient-pricing.md b/EIPS/transient-pricing.md index e3cc3d2240f3c..4086a86cd29c0 100644 --- a/EIPS/transient-pricing.md +++ b/EIPS/transient-pricing.md @@ -1,7 +1,7 @@ --- title: Decrease TLOAD/TSTORE pricing for common cases description: Improve the efficiency of TLOAD/TSTORE by introducing a quadratic(?) pricing model. -author: tbd +author: @charles-cooper, @prestwich, ...(?) discussions-to: none yet status: Draft type: Standards Track @@ -24,6 +24,9 @@ Furthermore, it seems that transient storage is fundamentally overpriced. Its pr This EIP proposes a quadratic pricing model, which is cheaper for common cases (fewer than 33 slots are written per contract), while making DoS using transient storage prohibitively expensive. +XXX: probably go with 9 gas per tload and 15 gas per tstore. +Does that make transient storage easier to memory dos than warm storage? + ## Specification The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174. From cbfbbd26d29c8e781f4fe3d2159d2dbdf873e19a Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Fri, 2 Jun 2023 12:42:49 -0400 Subject: [PATCH 03/16] add brockelmore --- EIPS/transient-pricing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/transient-pricing.md b/EIPS/transient-pricing.md index 4086a86cd29c0..10119ad567e28 100644 --- a/EIPS/transient-pricing.md +++ b/EIPS/transient-pricing.md @@ -1,7 +1,7 @@ --- title: Decrease TLOAD/TSTORE pricing for common cases description: Improve the efficiency of TLOAD/TSTORE by introducing a quadratic(?) pricing model. -author: @charles-cooper, @prestwich, ...(?) +author: @charles-cooper, @prestwich, @brockelmore, ...(?) discussions-to: none yet status: Draft type: Standards Track From e55bd03219c0debeddc08dd075e132fd8fd5aa9f Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 1 Feb 2024 08:26:43 -0500 Subject: [PATCH 04/16] updates --- EIPS/transient-pricing.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/EIPS/transient-pricing.md b/EIPS/transient-pricing.md index 10119ad567e28..47a434fbbcb35 100644 --- a/EIPS/transient-pricing.md +++ b/EIPS/transient-pricing.md @@ -1,7 +1,7 @@ --- title: Decrease TLOAD/TSTORE pricing for common cases description: Improve the efficiency of TLOAD/TSTORE by introducing a quadratic(?) pricing model. -author: @charles-cooper, @prestwich, @brockelmore, ...(?) +author: @charles-cooper, @prestwich, @brockelmore discussions-to: none yet status: Draft type: Standards Track @@ -12,7 +12,7 @@ requires: 1153 ## Abstract -Increase the efficiency of TLOAD/TSTORE for common use cases, while providing a quadratic pricing model to prevent DoS vectors. +Increase the efficiency of TLOAD/TSTORE for common use cases, while providing a pricing model to prevent DoS vectors. ## Motivation @@ -20,18 +20,15 @@ EIP-1153 introduces a new storage region, termed "transient storage", which beha One of the most important use cases that EIP-1153 enables is cheap reentrancy protection. In fact, if transient storage is cheap enough for the first few slots, reentrancy protection can be enabled by default at the language level without too much burden to users, while simultaneously preventing the largest - and most expensive! - class of smart contract vulnerabilities. -Furthermore, it seems that transient storage is fundamentally overpriced. Its pricing does not interact with refunds, it only requires a new allocation on contract load (as opposed to memory, which requires a fresh allocation on every call), and has no interaction with database journaling. +Furthermore, it seems that transient storage is fundamentally overpriced. Its pricing does not interact with refunds, it only requires a new allocation on contract load (as opposed to memory, which requires a fresh allocation on every call), and has no interaction with the journaling of the physical storage database. This EIP proposes a quadratic pricing model, which is cheaper for common cases (fewer than 33 slots are written per contract), while making DoS using transient storage prohibitively expensive. -XXX: probably go with 9 gas per tload and 15 gas per tstore. -Does that make transient storage easier to memory dos than warm storage? - ## Specification The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174. -The gas cost for TLOAD is proposed to be 3 gas. The gas cost for TSTORE is proposed to be 3 gas + `expansion_cost`, where expansion cost is calculated as 3x the number of transient slots allocated for this contract. +The gas cost for TLOAD is proposed to be 9 gas. The gas cost for TSTORE is proposed to be 15 gas + `expansion_cost`, where expansion cost is calculated as 3 gas * the number of transient slots already allocated for this contract. The maximum number of transient slots which can be allocated on a single contract given 30m gas is approximately 4,471 (solution to `x(x-1)/2*3 + 3*x = 30_000_000`), which totals 143KB. From 7f4559ca7466f3d160f8ad037686679f1343de2e Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 1 Feb 2024 08:27:18 -0500 Subject: [PATCH 05/16] update wording --- EIPS/transient-pricing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/transient-pricing.md b/EIPS/transient-pricing.md index 47a434fbbcb35..55cf037410c51 100644 --- a/EIPS/transient-pricing.md +++ b/EIPS/transient-pricing.md @@ -20,7 +20,7 @@ EIP-1153 introduces a new storage region, termed "transient storage", which beha One of the most important use cases that EIP-1153 enables is cheap reentrancy protection. In fact, if transient storage is cheap enough for the first few slots, reentrancy protection can be enabled by default at the language level without too much burden to users, while simultaneously preventing the largest - and most expensive! - class of smart contract vulnerabilities. -Furthermore, it seems that transient storage is fundamentally overpriced. Its pricing does not interact with refunds, it only requires a new allocation on contract load (as opposed to memory, which requires a fresh allocation on every call), and has no interaction with the journaling of the physical storage database. +Furthermore, it seems that transient storage is fundamentally overpriced. Its pricing does not interact with refunds, it only requires a new allocation on contract load (as opposed to memory, which requires a fresh allocation on every call), and has no interaction with the physical database. This EIP proposes a quadratic pricing model, which is cheaper for common cases (fewer than 33 slots are written per contract), while making DoS using transient storage prohibitively expensive. From c67a73205fd6a307910d8e2879c09382b9b42d52 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 1 Feb 2024 08:39:39 -0500 Subject: [PATCH 06/16] add discussions-to --- EIPS/transient-pricing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/transient-pricing.md b/EIPS/transient-pricing.md index 55cf037410c51..4c64d7addf400 100644 --- a/EIPS/transient-pricing.md +++ b/EIPS/transient-pricing.md @@ -2,7 +2,7 @@ title: Decrease TLOAD/TSTORE pricing for common cases description: Improve the efficiency of TLOAD/TSTORE by introducing a quadratic(?) pricing model. author: @charles-cooper, @prestwich, @brockelmore -discussions-to: none yet +discussions-to: https://ethereum-magicians.org/t/eip-8158-reduce-transient-storage-pricing/18435 status: Draft type: Standards Track category: Core From f6d05af425455f40a327a1adf3f9e1eb901bafb9 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 1 Feb 2024 17:53:13 -0500 Subject: [PATCH 07/16] update pricing based on benchmarks --- EIPS/transient-pricing.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/EIPS/transient-pricing.md b/EIPS/transient-pricing.md index 4c64d7addf400..6eaf43dd5d811 100644 --- a/EIPS/transient-pricing.md +++ b/EIPS/transient-pricing.md @@ -22,21 +22,22 @@ One of the most important use cases that EIP-1153 enables is cheap reentrancy pr Furthermore, it seems that transient storage is fundamentally overpriced. Its pricing does not interact with refunds, it only requires a new allocation on contract load (as opposed to memory, which requires a fresh allocation on every call), and has no interaction with the physical database. -This EIP proposes a quadratic pricing model, which is cheaper for common cases (fewer than 33 slots are written per contract), while making DoS using transient storage prohibitively expensive. - +This EIP proposes a pricing model which charges additional per allocation, which is cheaper for common cases (fewer than 33 slots are written per contract), while making DoS using transient storage prohibitively expensive. ## Specification The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174. -The gas cost for TLOAD is proposed to be 9 gas. The gas cost for TSTORE is proposed to be 15 gas + `expansion_cost`, where expansion cost is calculated as 3 gas * the number of transient slots already allocated for this contract. +The gas cost for TLOAD is proposed to be 5 gas. The gas cost for TSTORE is proposed to be 8 gas + `expansion_cost`, where expansion cost is calculated as 3 gas * `len(transient storage mapping)` if the key is not yet in the transient storage mapping, and otherwise 0 gas. -The maximum number of transient slots which can be allocated on a single contract given 30m gas is approximately 4,471 (solution to `x(x-1)/2*3 + 3*x = 30_000_000`), which totals 143KB. +The maximum number of transient slots which can be allocated on a single contract given 30m gas is approximately 4,470 (solution to `x(x-1)/2*3 + 8*x = 30_000_000`), which totals 143KB. The maximum number of transient slots which can be allocated in a transaction if you use the strategy of calling a new contract (also designed to maximize transient storage allocation) once the cost of TSTORE is more than the cost of calling a cold contract (2600 gas) is roughly 23,068, which totals 722KB. ## Rationale -TBD +### Gas + +In benchmarking, `TLOAD` was found to cost a similar amount of CPU time as `MUL`, while `TSTORE` was found to cost about 1.5x that. The values `G_low` and `G_mid` were therefore chosen for `TLOAD` and `TSTORE`, respectively. ## Backwards Compatibility From beaebca8398be86850a99bb81f4e6793d8e8760c Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 1 Feb 2024 22:49:45 -0500 Subject: [PATCH 08/16] add eip number --- EIPS/{transient-pricing.md => eip-7609.md} | 1 + 1 file changed, 1 insertion(+) rename EIPS/{transient-pricing.md => eip-7609.md} (99%) diff --git a/EIPS/transient-pricing.md b/EIPS/eip-7609.md similarity index 99% rename from EIPS/transient-pricing.md rename to EIPS/eip-7609.md index 6eaf43dd5d811..5f65aa44a9228 100644 --- a/EIPS/transient-pricing.md +++ b/EIPS/eip-7609.md @@ -1,4 +1,5 @@ --- +eip: 7609 title: Decrease TLOAD/TSTORE pricing for common cases description: Improve the efficiency of TLOAD/TSTORE by introducing a quadratic(?) pricing model. author: @charles-cooper, @prestwich, @brockelmore From 2aa81459eb9a365ca23fffc83a0b07400f561a7d Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 15 Feb 2024 06:19:38 -0800 Subject: [PATCH 09/16] Apply suggestions from code review Co-authored-by: Andrew B Coathup <28278242+abcoathup@users.noreply.github.com> Co-authored-by: Nikki Gaudreau <87712502+gaudren@users.noreply.github.com> --- EIPS/eip-7609.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/EIPS/eip-7609.md b/EIPS/eip-7609.md index 5f65aa44a9228..1a3b4442bef6f 100644 --- a/EIPS/eip-7609.md +++ b/EIPS/eip-7609.md @@ -2,8 +2,8 @@ eip: 7609 title: Decrease TLOAD/TSTORE pricing for common cases description: Improve the efficiency of TLOAD/TSTORE by introducing a quadratic(?) pricing model. -author: @charles-cooper, @prestwich, @brockelmore -discussions-to: https://ethereum-magicians.org/t/eip-8158-reduce-transient-storage-pricing/18435 +author: Charles Cooper (@charles-cooper), James Prestwich (@prestwich), brockelmore (@brockelmore) +discussions-to: https://ethereum-magicians.org/t/eip-7609-reduce-transient-storage-pricing/18435 status: Draft type: Standards Track category: Core @@ -17,22 +17,22 @@ Increase the efficiency of TLOAD/TSTORE for common use cases, while providing a ## Motivation -EIP-1153 introduces a new storage region, termed "transient storage", which behaves like storage in the sense that it is word-addressed and persists between call frames, but unlike storage in the sense that it is wiped at the end of each transaction. During development of the 1153 specification, it was decided to match the pricing to be the same as warm storage loads and stores. This was for two reasons: conceptual simplicity of the EIP, and it also addressed concerns about two related DoS vectors: being able to allocate too much transient storage, and the cost of rolling back state in the case of reverts. +[EIP-1153](./eip-1153.md) introduces a new storage region, termed "transient storage". It behaves like storage (word-addressed and persists between call frames), but unlike storage it is wiped at the end of each transaction. During development of EIP-1153, the pricing was set to be the same as warm storage loads and stores. This was for two reasons: conceptual simplicity of the EIP, and it also addressed concerns about two related DoS vectors: being able to allocate too much transient storage, and the cost of rolling back state in the case of reverts. -One of the most important use cases that EIP-1153 enables is cheap reentrancy protection. In fact, if transient storage is cheap enough for the first few slots, reentrancy protection can be enabled by default at the language level without too much burden to users, while simultaneously preventing the largest - and most expensive! - class of smart contract vulnerabilities. +One of the most important use cases that EIP-1153 enables is cheap reentrancy protection. In fact, if transient storage is cheap enough for the first few slots, reentrancy protection can be enabled by default at the language level without too much burden to users, while simultaneously preventing the largest—and most expensive—class of smart contract vulnerabilities. Furthermore, it seems that transient storage is fundamentally overpriced. Its pricing does not interact with refunds, it only requires a new allocation on contract load (as opposed to memory, which requires a fresh allocation on every call), and has no interaction with the physical database. -This EIP proposes a pricing model which charges additional per allocation, which is cheaper for common cases (fewer than 33 slots are written per contract), while making DoS using transient storage prohibitively expensive. +This EIP proposes a pricing model which charges additional gas per allocation, which is cheaper for common cases (fewer than 33 slots are written per contract), while making DoS using transient storage prohibitively expensive. ## Specification The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174. -The gas cost for TLOAD is proposed to be 5 gas. The gas cost for TSTORE is proposed to be 8 gas + `expansion_cost`, where expansion cost is calculated as 3 gas * `len(transient storage mapping)` if the key is not yet in the transient storage mapping, and otherwise 0 gas. +The gas cost for `TLOAD` is proposed to be 5 gas. The gas cost for `TSTORE` is proposed to be 8 gas + `expansion_cost`, where `expansion_cost` is calculated as `3 gas * len(transient storage mapping)` if the key is not yet in the transient storage mapping, and otherwise 0 gas. The maximum number of transient slots which can be allocated on a single contract given 30m gas is approximately 4,470 (solution to `x(x-1)/2*3 + 8*x = 30_000_000`), which totals 143KB. -The maximum number of transient slots which can be allocated in a transaction if you use the strategy of calling a new contract (also designed to maximize transient storage allocation) once the cost of TSTORE is more than the cost of calling a cold contract (2600 gas) is roughly 23,068, which totals 722KB. +The maximum number of transient slots which can be allocated in a transaction if you use the strategy of calling a new contract (also designed to maximize transient storage allocation) once the cost of `TSTORE` is more than the cost of calling a cold contract (2600 gas) is roughly 23,068, which totals 722KB. ## Rationale @@ -50,7 +50,7 @@ No backward compatibility issues found. ## Security Considerations -Needs discussion. +Needs discussion. ## Copyright From 43a0e996134b56277b3a54cac17a217455f9f3f7 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 15 Feb 2024 09:20:31 -0500 Subject: [PATCH 10/16] update title --- EIPS/eip-7609.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7609.md b/EIPS/eip-7609.md index 1a3b4442bef6f..dc8e933d033d3 100644 --- a/EIPS/eip-7609.md +++ b/EIPS/eip-7609.md @@ -1,7 +1,7 @@ --- eip: 7609 title: Decrease TLOAD/TSTORE pricing for common cases -description: Improve the efficiency of TLOAD/TSTORE by introducing a quadratic(?) pricing model. +description: Improve the efficiency of TLOAD/TSTORE by introducing a superlinear pricing model. author: Charles Cooper (@charles-cooper), James Prestwich (@prestwich), brockelmore (@brockelmore) discussions-to: https://ethereum-magicians.org/t/eip-7609-reduce-transient-storage-pricing/18435 status: Draft From 1d912d5c3372f75b6bcb650b6fe1b687de2bfc79 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 15 Feb 2024 09:22:34 -0500 Subject: [PATCH 11/16] update abstract --- EIPS/eip-7609.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7609.md b/EIPS/eip-7609.md index dc8e933d033d3..c7b9fd44dfaa3 100644 --- a/EIPS/eip-7609.md +++ b/EIPS/eip-7609.md @@ -13,7 +13,7 @@ requires: 1153 ## Abstract -Increase the efficiency of TLOAD/TSTORE for common use cases, while providing a pricing model to prevent DoS vectors. +Decrease the base cost of TLOAD/TSTORE while introducing a superlinear pricing model. This increases the efficiency of TLOAD/TSTORE for common use cases, while providing a pricing model to prevent DoS vectors. ## Motivation From c1bab8768172ac5974d0377a11ef12903353d9d5 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 15 Feb 2024 09:25:18 -0500 Subject: [PATCH 12/16] move some text from specification to security considerations --- EIPS/eip-7609.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/EIPS/eip-7609.md b/EIPS/eip-7609.md index c7b9fd44dfaa3..603ea13e99505 100644 --- a/EIPS/eip-7609.md +++ b/EIPS/eip-7609.md @@ -30,10 +30,6 @@ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "S The gas cost for `TLOAD` is proposed to be 5 gas. The gas cost for `TSTORE` is proposed to be 8 gas + `expansion_cost`, where `expansion_cost` is calculated as `3 gas * len(transient storage mapping)` if the key is not yet in the transient storage mapping, and otherwise 0 gas. -The maximum number of transient slots which can be allocated on a single contract given 30m gas is approximately 4,470 (solution to `x(x-1)/2*3 + 8*x = 30_000_000`), which totals 143KB. - -The maximum number of transient slots which can be allocated in a transaction if you use the strategy of calling a new contract (also designed to maximize transient storage allocation) once the cost of `TSTORE` is more than the cost of calling a cold contract (2600 gas) is roughly 23,068, which totals 722KB. - ## Rationale ### Gas @@ -44,13 +40,11 @@ In benchmarking, `TLOAD` was found to cost a similar amount of CPU time as `MUL` No backward compatibility issues found. -## Test Cases - -## Reference Implementation - ## Security Considerations -Needs discussion. +The maximum number of transient slots which can be allocated on a single contract given 30m gas is approximately 4,470 (solution to `x(x-1)/2*3 + 8*x = 30_000_000`), which totals 143KB. + +The maximum number of transient slots which can be allocated in a transaction if you use the strategy of calling a new contract (also designed to maximize transient storage allocation) once the cost of `TSTORE` is more than the cost of calling a cold contract (2600 gas) is roughly 23,068, which totals 722KB. ## Copyright From 62bceffe863b3fd42eb8697eda120a0492ed8e2f Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 15 Feb 2024 09:31:55 -0500 Subject: [PATCH 13/16] add pseudocode --- EIPS/eip-7609.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/EIPS/eip-7609.md b/EIPS/eip-7609.md index 603ea13e99505..c6052eb0113f7 100644 --- a/EIPS/eip-7609.md +++ b/EIPS/eip-7609.md @@ -30,6 +30,24 @@ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "S The gas cost for `TLOAD` is proposed to be 5 gas. The gas cost for `TSTORE` is proposed to be 8 gas + `expansion_cost`, where `expansion_cost` is calculated as `3 gas * len(transient storage mapping)` if the key is not yet in the transient storage mapping, and otherwise 0 gas. +In pseudo-code: + +```python +G_LOW = 5 +G_MID = 8 + +SLOPE = 3 + +def gas_tload(_key): + return G_LOW + +def gas_tstore(key, transient_mapping): + cost = G_MID + if key not in transient_mapping: + cost += SLOPE * transient_mapping.size() + return cost +``` + ## Rationale ### Gas From 504f14bc5c3a96e65ab36d0e6b93c04a0d4e682c Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 15 Feb 2024 09:37:44 -0500 Subject: [PATCH 14/16] add creation date --- EIPS/eip-7609.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7609.md b/EIPS/eip-7609.md index c6052eb0113f7..b5c184e8437be 100644 --- a/EIPS/eip-7609.md +++ b/EIPS/eip-7609.md @@ -7,7 +7,7 @@ discussions-to: https://ethereum-magicians.org/t/eip-7609-reduce-transient-stora status: Draft type: Standards Track category: Core -created: tbd +created: 2024-02-01 requires: 1153 --- From 482b65ae23fbc54303ce206016ee94e528a7de2a Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 15 Feb 2024 09:38:13 -0500 Subject: [PATCH 15/16] fix lint --- EIPS/eip-7609.md | 1 + 1 file changed, 1 insertion(+) diff --git a/EIPS/eip-7609.md b/EIPS/eip-7609.md index b5c184e8437be..9d39329ac9707 100644 --- a/EIPS/eip-7609.md +++ b/EIPS/eip-7609.md @@ -26,6 +26,7 @@ Furthermore, it seems that transient storage is fundamentally overpriced. Its pr This EIP proposes a pricing model which charges additional gas per allocation, which is cheaper for common cases (fewer than 33 slots are written per contract), while making DoS using transient storage prohibitively expensive. ## Specification + The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174. The gas cost for `TLOAD` is proposed to be 5 gas. The gas cost for `TSTORE` is proposed to be 8 gas + `expansion_cost`, where `expansion_cost` is calculated as `3 gas * len(transient storage mapping)` if the key is not yet in the transient storage mapping, and otherwise 0 gas. From ac904626dd466a085a74fa681faa11280db92e2e Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 15 Feb 2024 09:39:48 -0500 Subject: [PATCH 16/16] eip walidator requires shorter title --- EIPS/eip-7609.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-7609.md b/EIPS/eip-7609.md index 9d39329ac9707..b3d93e3f58805 100644 --- a/EIPS/eip-7609.md +++ b/EIPS/eip-7609.md @@ -1,7 +1,7 @@ --- eip: 7609 -title: Decrease TLOAD/TSTORE pricing for common cases -description: Improve the efficiency of TLOAD/TSTORE by introducing a superlinear pricing model. +title: Decrease base cost of TLOAD/TSTORE +description: Improve the efficiency of TLOAD/TSTORE by decreasing the base cost and introducing a superlinear pricing model. author: Charles Cooper (@charles-cooper), James Prestwich (@prestwich), brockelmore (@brockelmore) discussions-to: https://ethereum-magicians.org/t/eip-7609-reduce-transient-storage-pricing/18435 status: Draft