Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
eca126c5
Commit
eca126c5
authored
Sep 22, 2020
by
ben-chain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test passing, snapshot logic worked
parent
4fc1a473
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
6 deletions
+74
-6
OVM_ExecutionManager.sol
...ptimistic-ethereum/OVM/execution/OVM_ExecutionManager.sol
+9
-0
nuisance-gas.spec.ts
...s/OVM/execution/OVM_ExecutionManager/nuisance-gas.spec.ts
+59
-3
constants.ts
packages/contracts/test/helpers/constants.ts
+1
-1
test-runner.ts
packages/contracts/test/helpers/test-utils/test-runner.ts
+5
-2
No files found.
packages/contracts/contracts/optimistic-ethereum/OVM/execution/OVM_ExecutionManager.sol
View file @
eca126c5
...
...
@@ -834,6 +834,8 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager {
bytes memory _returndata
)
{
console.log("_callContract with nuisance gas:");
console.log(messageRecord.nuisanceGasLeft);
return _handleExternalInteraction(
_nextMessageContext,
_gasLimit,
...
...
@@ -1126,6 +1128,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager {
)
internal
{
console.log("checking account load");
// See `_checkContractStorageLoad` for more information.
if (gasleft() < MIN_GAS_FOR_INVALID_STATE_ACCESS) {
_revertWithFlag(RevertFlag.OUT_OF_GAS);
...
...
@@ -1145,10 +1148,14 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager {
// If we hadn't already loaded the account, then we'll need to charge "nuisance gas" based
// on the size of the contract code.
if (_wasAccountAlreadyLoaded == false) {
console.log("was not already loaded");
_useNuisanceGas(
Lib_EthUtils.getCodeSize(_getAccountEthAddress(_address)) * NUISANCE_GAS_PER_CONTRACT_BYTE
);
console.log("got code size:");
console.log(Lib_EthUtils.getCodeSize(_getAccountEthAddress(_address)));
}
console.log("was already loaded");
}
/**
...
...
@@ -1414,6 +1421,8 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager {
)
internal
{
console.log("using nuisance gas of amount:");
console.log(_amount);
// Essentially the same as a standard OUT_OF_GAS, except we also retain a record of the gas
// refund to be given at the end of the transaction.
if (messageRecord.nuisanceGasLeft < _amount) {
...
...
packages/contracts/test/contracts/OVM/execution/OVM_ExecutionManager/nuisance-gas.spec.ts
View file @
eca126c5
...
...
@@ -12,6 +12,8 @@ import {
const
DUMMY_REVERT_DATA
=
'
0xdeadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420
'
console
.
log
(
'
cost multiplied:
'
,
Helper_TestRunner_BYTELEN
*
NUISANCE_GAS_COSTS
.
NUISANCE_GAS_PER_CONTRACT_BYTE
,
'
bytelenL:
'
,
Helper_TestRunner_BYTELEN
)
const
test_nuisanceGas
:
TestDefinition
=
{
name
:
'
Basic tests for nuisance gas
'
,
...
...
@@ -47,7 +49,7 @@ import {
postState
:
{
ExecutionManager
:
{
messageRecord
:
{
nuisanceGasLeft
:
OVM_TX_GAS_LIMIT
/
2
nuisanceGasLeft
:
OVM_TX_GAS_LIMIT
-
Helper_TestRunner_BYTELEN
*
NUISANCE_GAS_COSTS
.
NUISANCE_GAS_PER_CONTRACT_BYTE
}
}
},
...
...
@@ -56,10 +58,64 @@ import {
name
:
'
single ovmCALL
'
,
focus
:
true
,
steps
:
[
// do a non-nuisance
gas consuming opcode (test
auto-wraps in ovmCALL)
// do a non-nuisance
-gas-consuming opcode (test runner
auto-wraps in ovmCALL)
{
functionName
:
'
ovmADDRESS
'
,
expectedReturnValue
:
"
$DUMMY_OVM_ADDRESS_1
"
expectedReturnValue
:
"
$DUMMY_OVM_ADDRESS_1
"
,
},
],
}
]
},
{
name
:
'
ovmCALL only consumes nuisance gas of CODESIZE * NUISANCE_GAS_PER_CONTRACT_BYTE for same contract called twice
'
,
postState
:
{
ExecutionManager
:
{
messageRecord
:
{
nuisanceGasLeft
:
OVM_TX_GAS_LIMIT
-
Helper_TestRunner_BYTELEN
*
NUISANCE_GAS_COSTS
.
NUISANCE_GAS_PER_CONTRACT_BYTE
}
}
},
parameters
:
[
{
name
:
'
nested ovmCALL
'
,
focus
:
true
,
steps
:
[
{
functionName
:
'
ovmCALL
'
,
functionParams
:
{
gasLimit
:
OVM_TX_GAS_LIMIT
,
target
:
"
$DUMMY_OVM_ADDRESS_1
"
,
subSteps
:
[]
},
expectedReturnStatus
:
true
},
],
}
]
},
{
name
:
'
ovmCALL only consumes nuisance gas of CODESIZE * NUISANCE_GAS_PER_CONTRACT_BYTE twice for two separate ovmCALLS
'
,
postState
:
{
ExecutionManager
:
{
messageRecord
:
{
nuisanceGasLeft
:
OVM_TX_GAS_LIMIT
-
2
*
(
Helper_TestRunner_BYTELEN
*
NUISANCE_GAS_COSTS
.
NUISANCE_GAS_PER_CONTRACT_BYTE
)
}
}
},
parameters
:
[
{
name
:
'
nested ovmCALL
'
,
// focus: true,
steps
:
[
{
functionName
:
'
ovmCALL
'
,
functionParams
:
{
gasLimit
:
OVM_TX_GAS_LIMIT
,
target
:
"
$DUMMY_OVM_ADDRESS_2
"
,
subSteps
:
[]
},
expectedReturnStatus
:
true
},
],
}
...
...
packages/contracts/test/helpers/constants.ts
View file @
eca126c5
...
...
@@ -32,4 +32,4 @@ export const NUISANCE_GAS_COSTS = {
}
// TODO: get this exported/imported somehow in a way that we can do math on it. unfortunately using require('.....artifacts/contract.json') is erroring...
export
const
Helper_TestRunner_BYTELEN
=
3686
\ No newline at end of file
export
const
Helper_TestRunner_BYTELEN
=
3654
\ No newline at end of file
packages/contracts/test/helpers/test-utils/test-runner.ts
View file @
eca126c5
...
...
@@ -123,10 +123,13 @@ export class ExecutionManagerTestRunner {
}
private
async
initContracts
()
{
console
.
log
(
'
initcontracts
'
)
if
(
this
.
snapshot
)
{
await
ethers
.
provider
.
send
(
'
evm_revert
'
,
[
this
.
snapshot
])
this
.
snapshot
=
await
ethers
.
provider
.
send
(
'
evm_snapshot
'
,
[])
return
}
console
.
log
(
'
no snapshot
'
)
this
.
contracts
.
OVM_SafetyChecker
=
await
(
await
ethers
.
getContractFactory
(
'
OVM_SafetyChecker
'
)
...
...
@@ -201,7 +204,7 @@ export class ExecutionManagerTestRunner {
functionName
:
'
ovmCALL
'
,
functionParams
:
{
gasLimit
:
OVM_TX_GAS_LIMIT
,
target
:
this
.
contracts
.
Helper_TestRunner
.
address
,
target
:
ExecutionManagerTestRunner
.
getDummyAddress
(
"
$DUMMY_OVM_ADDRESS_1
"
)
,
subSteps
:
step
.
functionParams
.
subSteps
,
},
expectedReturnStatus
:
true
,
...
...
@@ -226,7 +229,7 @@ export class ExecutionManagerTestRunner {
}
else
{
await
this
.
contracts
.
OVM_ExecutionManager
.
ovmCALL
(
OVM_TX_GAS_LIMIT
,
this
.
contracts
.
Helper_TestRunner
.
address
,
ExecutionManagerTestRunner
.
getDummyAddress
(
"
$DUMMY_OVM_ADDRESS_1
"
)
,
this
.
contracts
.
Helper_TestRunner
.
interface
.
encodeFunctionData
(
'
runSingleTestStep
'
,
[
this
.
parseTestStep
(
step
)]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment