From 2e3ad66e052ae2e3de2bff32010e65fa52206b51 Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Thu, 18 Jan 2024 22:35:14 -0300 Subject: [PATCH 1/2] accesswitness: avoid charging cost for origin and target Signed-off-by: Ignacio Hagopian --- core/state/access_witness.go | 11 +++++++++-- core/state_processor_test.go | 10 +++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/core/state/access_witness.go b/core/state/access_witness.go index 8b03cf371a60..7ad6add9fd58 100644 --- a/core/state/access_witness.go +++ b/core/state/access_witness.go @@ -145,7 +145,11 @@ func (aw *AccessWitness) TouchTxOriginAndComputeGas(originAddr []byte) uint64 { gas += aw.TouchAddressOnReadAndComputeGas(originAddr, zeroTreeIndex, utils.CodeKeccakLeafKey) gas += aw.TouchAddressOnWriteAndComputeGas(originAddr, zeroTreeIndex, utils.NonceLeafKey) gas += aw.TouchAddressOnWriteAndComputeGas(originAddr, zeroTreeIndex, utils.BalanceLeafKey) - return gas + + // Kaustinen note: we're currently experimenting with stop chargin gas for the origin address + // so simple transfer still take 21000 gas. This is to potentially avoid breaking existing tooling. + // This is the reason why we return 0 instead of `gas`. + return 0 } func (aw *AccessWitness) TouchTxExistingAndComputeGas(targetAddr []byte, sendsValue bool) uint64 { @@ -159,7 +163,10 @@ func (aw *AccessWitness) TouchTxExistingAndComputeGas(targetAddr []byte, sendsVa } else { gas += aw.TouchAddressOnReadAndComputeGas(targetAddr, zeroTreeIndex, utils.BalanceLeafKey) } - return gas + // Kaustinen note: we're currently experimenting with stop chargin gas for the origin address + // so simple transfer still take 21000 gas. This is to potentially avoid breaking existing tooling. + // This is the reason why we return 0 instead of `gas`. + return 0 } func (aw *AccessWitness) TouchAddressOnWriteAndComputeGas(addr []byte, treeIndex uint256.Int, subIndex byte) uint64 { diff --git a/core/state_processor_test.go b/core/state_processor_test.go index 8ed660a5042e..7bd63475ca9e 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -17,7 +17,6 @@ package core import ( - //"bytes" "crypto/ecdsa" //"fmt" @@ -481,10 +480,10 @@ func TestProcessVerkle(t *testing.T) { // is now independent of the blockchain database. gspec.MustCommit(gendb) - txCost1 := params.WitnessBranchWriteCost*2 + params.WitnessBranchReadCost*2 + params.WitnessChunkWriteCost*3 + params.WitnessChunkReadCost*10 + params.TxGas - txCost2 := params.WitnessBranchWriteCost + params.WitnessBranchReadCost*2 + params.WitnessChunkWriteCost*2 + params.WitnessChunkReadCost*10 + params.TxGas - contractCreationCost := intrinsicContractCreationGas + uint64(6900 /* from */ +7700 /* creation */ +2939 /* execution costs */) - codeWithExtCodeCopyGas := intrinsicCodeWithExtCodeCopyGas + uint64(6900 /* from */ +7000 /* creation */ +315944 /* execution costs */) + txCost1 := params.TxGas + txCost2 := params.TxGas + contractCreationCost := intrinsicContractCreationGas + uint64(7700 /* creation */ +2939 /* execution costs */) + codeWithExtCodeCopyGas := intrinsicCodeWithExtCodeCopyGas + uint64(7000 /* creation */ +315944 /* execution costs */) blockGasUsagesExpected := []uint64{ txCost1*2 + txCost2, txCost1*2 + txCost2 + contractCreationCost + codeWithExtCodeCopyGas, @@ -492,6 +491,7 @@ func TestProcessVerkle(t *testing.T) { // TODO utiliser GenerateChainWithGenesis pour le rendre plus pratique chain, _, proofs, keyvals := GenerateVerkleChain(gspec.Config, genesis, beacon.New(ethash.NewFaker()), gendb, 2, func(i int, gen *BlockGen) { gen.SetPoS() + // TODO need to check that the tx cost provided is the exact amount used (no remaining left-over) tx, _ := types.SignTx(types.NewTransaction(uint64(i)*3, common.Address{byte(i), 2, 3}, big.NewInt(999), txCost1, big.NewInt(875000000), nil), signer, testKey) gen.AddTx(tx) From c07ae97a2567deb6359a73a72ef91cb1d6916a34 Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Fri, 19 Jan 2024 14:02:57 -0300 Subject: [PATCH 2/2] make the linter happy Signed-off-by: Ignacio Hagopian --- core/state/access_witness.go | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/core/state/access_witness.go b/core/state/access_witness.go index 7ad6add9fd58..65d7bb25a32c 100644 --- a/core/state/access_witness.go +++ b/core/state/access_witness.go @@ -139,12 +139,12 @@ func (aw *AccessWitness) TouchAndChargeContractCreateCompleted(addr []byte) uint } func (aw *AccessWitness) TouchTxOriginAndComputeGas(originAddr []byte) uint64 { - var gas uint64 - gas += aw.TouchAddressOnReadAndComputeGas(originAddr, zeroTreeIndex, utils.VersionLeafKey) - gas += aw.TouchAddressOnReadAndComputeGas(originAddr, zeroTreeIndex, utils.CodeSizeLeafKey) - gas += aw.TouchAddressOnReadAndComputeGas(originAddr, zeroTreeIndex, utils.CodeKeccakLeafKey) - gas += aw.TouchAddressOnWriteAndComputeGas(originAddr, zeroTreeIndex, utils.NonceLeafKey) - gas += aw.TouchAddressOnWriteAndComputeGas(originAddr, zeroTreeIndex, utils.BalanceLeafKey) + // var gas uint64 + // gas += aw.TouchAddressOnReadAndComputeGas(originAddr, zeroTreeIndex, utils.VersionLeafKey) + // gas += aw.TouchAddressOnReadAndComputeGas(originAddr, zeroTreeIndex, utils.CodeSizeLeafKey) + // gas += aw.TouchAddressOnReadAndComputeGas(originAddr, zeroTreeIndex, utils.CodeKeccakLeafKey) + // gas += aw.TouchAddressOnWriteAndComputeGas(originAddr, zeroTreeIndex, utils.NonceLeafKey) + // gas += aw.TouchAddressOnWriteAndComputeGas(originAddr, zeroTreeIndex, utils.BalanceLeafKey) // Kaustinen note: we're currently experimenting with stop chargin gas for the origin address // so simple transfer still take 21000 gas. This is to potentially avoid breaking existing tooling. @@ -153,16 +153,17 @@ func (aw *AccessWitness) TouchTxOriginAndComputeGas(originAddr []byte) uint64 { } func (aw *AccessWitness) TouchTxExistingAndComputeGas(targetAddr []byte, sendsValue bool) uint64 { - var gas uint64 - gas += aw.TouchAddressOnReadAndComputeGas(targetAddr, zeroTreeIndex, utils.VersionLeafKey) - gas += aw.TouchAddressOnReadAndComputeGas(targetAddr, zeroTreeIndex, utils.CodeSizeLeafKey) - gas += aw.TouchAddressOnReadAndComputeGas(targetAddr, zeroTreeIndex, utils.CodeKeccakLeafKey) - gas += aw.TouchAddressOnReadAndComputeGas(targetAddr, zeroTreeIndex, utils.NonceLeafKey) - if sendsValue { - gas += aw.TouchAddressOnWriteAndComputeGas(targetAddr, zeroTreeIndex, utils.BalanceLeafKey) - } else { - gas += aw.TouchAddressOnReadAndComputeGas(targetAddr, zeroTreeIndex, utils.BalanceLeafKey) - } + // var gas uint64 + // gas += aw.TouchAddressOnReadAndComputeGas(targetAddr, zeroTreeIndex, utils.VersionLeafKey) + // gas += aw.TouchAddressOnReadAndComputeGas(targetAddr, zeroTreeIndex, utils.CodeSizeLeafKey) + // gas += aw.TouchAddressOnReadAndComputeGas(targetAddr, zeroTreeIndex, utils.CodeKeccakLeafKey) + // gas += aw.TouchAddressOnReadAndComputeGas(targetAddr, zeroTreeIndex, utils.NonceLeafKey) + // if sendsValue { + // gas += aw.TouchAddressOnWriteAndComputeGas(targetAddr, zeroTreeIndex, utils.BalanceLeafKey) + // } else { + // gas += aw.TouchAddressOnReadAndComputeGas(targetAddr, zeroTreeIndex, utils.BalanceLeafKey) + // } + // Kaustinen note: we're currently experimenting with stop chargin gas for the origin address // so simple transfer still take 21000 gas. This is to potentially avoid breaking existing tooling. // This is the reason why we return 0 instead of `gas`.