Skip to content

Commit

Permalink
simple structure types (#364)
Browse files Browse the repository at this point in the history
* adding simple setter-getter example for testing implementation of new

* using java -jar instead of sbt for running obsidian in the testing loop for ganache tests; trying to get travis to run tests in parallel

* second shot at travis parallel jobs

* third shot at travis parallel jobs

* small changes, another travis round

* debugging travis

* refining travis job

* refining travis job 3

* updating checks, travis job fussing 4

* removing SBT hack

* sbt hack seems to no longer be needed, so removing the commented out version

* trying jdk13 for laughs

* jdk 13 does not work and i do not want to fix it right now

* horsing around with changing what gets built when in each testing path

* taking a quick stab at moving the protobuf install out of the ganache tests to save a little more time

* updating travis yaml

* updating travis yaml

* updating travis yaml

* updating travis yaml

* updating travis

* working on travis build

* travis updates; removing npm audit that wasnt doing anything, taking a pass at conditional jobs

* fixing travis yaml syntax

* updating travis yaml and test scripts per comments on #346

* adding the optimize flag to the travis test script.

cleaning up directory tree. this was a test that i thought would fail but
doesnt, so it might as well get added to the suite to show that it doesnt.

* adding a json file for a test that uses multiple lines inside each block of an if. previously this failed because we allocted more than 16 stack variables; with the optimizer in the pipeline it now compiles all the way through and passes.

* adding code so that simple structure emits code that allocates some space; this is not testable right now until i also recursively generate code for sub objects and put it in the right place

* typo in test case

* typo in test case again

* scraps

* squelching an sbt warning about timestamps

* collect up the subobject representations and emit them too

* using fold to avoid needless state

* Adding restricted constant version of setter/getter

* adding a new restricted test, renaming some tests, adding json descriptor files

* renaming test

* updating structure names to reflect the file name

* scraps

* adding a new more restricted test case without even a constructor

* maybe the simplest test case for set/get that i can think of

* first cut at pulling something out of storage for get()

* removing this todo; it is stale since we decided that we would include the optimizer in the pipeline instead of doing little optimimzations everywhere

* adding a first cut at setting a value in storage. also updating to hash the contract name as well as the field name, which is marginally less brittle, and adding todos to remember to change that to compute offsets

* removing a print statement

* scraps, whitespace

* cut at Invocation, with comments for where to pick up

* fixing constructor implementation to assign to the retvar; removing a dead line there; adding a comment to note that the constructor arguments are ignored

* adding and updating utility functions

* removing placeholders from call to , computing function selectors

* actually want to check the code size at the address not the address

* updating utils

* adding mstore for the function selector hash

* adding a little bit to the boiler plate in mustache; updating the args to call in Invocation because i need to actually store the result in order for get() to work

* fixing small errors in  the output for main

* bumping java version for IDE to 15

* renaming one of the variables for clarity, adding debugging output

* debugging output, variable renaming

* removing code that seems to be equivalent to unit

* fixing some scala formatting via IDE

* commenting out fold and possibly unused field of mustache file to verify that tests run on travis

* commenting out fold and possibly unused field of mustache file to verify that tests run on travis

* i believe this fixes #355; i need to do a clean up pass of comments, but i also want to see the output from Travis

* removing extraneous prints

* removing code for debugging, some redundant variables

* renaming, more tidying up

* removing json for test cases that i know dont work right now

* whitespace

* missing an addition to compute the new bound in construction

* updating mload argument; as the comment surmised, it was indeed wrong

* refactoring obs type to abi helper to also return the size of the type; this will need to be more robust in the future, but it works for now

* Adding a comment explaining why this look up won\'t work and what i think i need to do about it

* adding an extremely hacky hack to make the test cases work, pending being able to talk to michael and find a better solution

* resolving PR comments: adding comments, changing names, applying scala style fixes

* removing code that isn't the right way to proceed, cleaning up a few comments before merging
  • Loading branch information
ivoysey committed Aug 18, 2021
1 parent e4820b1 commit f508808
Show file tree
Hide file tree
Showing 17 changed files with 397 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions Obsidian_Runtime/src/main/yul_templates/object.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object "{{creationObject}}" {
{{codeCopy}}
{{defaultReturn}}
}
object "{{runtimeObject}}" {
object "{{runtimeObjectName}}" {
code {
{{! init free memory pointer, see chatper "Layout in Memory" of the Solidity doc}}
{{memoryInitRuntime}}
Expand All @@ -50,6 +50,11 @@ object "{{creationObject}}" {
function abi_decode_tuple(headStart, dataEnd) {
if slt(sub(dataEnd, headStart), 0) { revert(0, 0) }
}
function abi_decode_t_uint256_fromMemory(offset, end) -> value {
value := mload(offset)
}
{{abiEncodeTupleFuncs}}
function allocate_memory(size) -> memPtr {
Expand Down Expand Up @@ -82,16 +87,24 @@ object "{{creationObject}}" {
mstore(pos, cleanup_t_uint256(value))
}
{{! revert, but also include the return data from the most recent call }}
function revert_forward_1() {
let pos := allocate_unbounded()
returndatacopy(pos, 0, returndatasize())
revert(pos, returndatasize())
}
{{! the "cleanup" functions enforce the invariants on the types from the abi wrt how they're encoded;
with uint256, there are none, so it just returns. }}
function cleanup_t_uint256(value) -> cleaned {
cleaned := value
}

{{#runtimeFunctions}}
{{code}}
{{/runtimeFunctions}}
}
{{runtimeSubObjects}}

{{childContracts}}
}
{{subObjects}}
}
3 changes: 3 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ assembly / assemblyMergeStrategy := {
oldStrategy(x)
}

// adding this to squelch a warning per https://github.com/sbt/sbt/pull/6237

ThisBuild / packageTimestamp := Package.keepTimestamps
8 changes: 8 additions & 0 deletions resources/tests/GanacheTests/MultiLineIfRet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"gas" : 30000000,
"gasprice" : "0x9184e72a000",
"startingeth" : 5000000,
"numaccts" : 1,
"testexp" : "main()",
"expected" : "15"
}
8 changes: 8 additions & 0 deletions resources/tests/GanacheTests/ReturnAdd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"gas" : 30000000,
"gasprice" : "0x9184e72a000",
"startingeth" : 5000000,
"numaccts" : 1,
"testexp" : "main()",
"expected" : "16"
}
9 changes: 9 additions & 0 deletions resources/tests/GanacheTests/ReturnAdd.obs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
main contract ReturnAdd {
transaction f() returns int{
return (4+4);
}

transaction main() returns int{
return f() + f();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract IntContainer{
}
}

main contract SimpleStructure{
main contract SetGet{
transaction main() returns int{
IntContainer ic = new IntContainer();
ic.set(5);
Expand Down
22 changes: 22 additions & 0 deletions resources/tests/GanacheTests/SetGetNoArgs.obs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
contract IntContainer{
int x;

IntContainer@Owned() {
x = 0;
}

transaction set() { // take no parameters
x = 5;
}
transaction get() returns int{
return x;
}
}

main contract SetGetNoArgs{
transaction main() returns int{
IntContainer ic = new IntContainer();
ic.set();
return (ic.get());
}
}
8 changes: 8 additions & 0 deletions resources/tests/GanacheTests/SetGetNoArgsNoConstruct.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"gas" : 30000000000,
"gasprice" : "0x9184e72a000",
"startingeth" : 500000000,
"numaccts" : 1,
"testexp" : "main()",
"expected" : "10"
}
24 changes: 24 additions & 0 deletions resources/tests/GanacheTests/SetGetNoArgsNoConstruct.obs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
contract IntContainer{
int x;

transaction set1() {
x = 5;
}

transaction set2() {
x = 10;
}

transaction get() returns int{
return x;
}
}

main contract SetGetNoArgsNoConstruct{
transaction main() returns int{
IntContainer ic = new IntContainer();
ic.set1();
ic.set2();
return (ic.get());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"gas" : 30000000000,
"gasprice" : "0x9184e72a000",
"startingeth" : 500000000,
"numaccts" : 1,
"testexp" : "main()",
"expected" : "5"
}
19 changes: 19 additions & 0 deletions resources/tests/GanacheTests/SetGetNoArgsNoConstructNoInit.obs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
contract IntContainer{
int x;

transaction set() {
x = 5;
}

transaction get() returns int{
return x;
}
}

main contract SetGetNoArgsNoConstructNoInit{
transaction main() returns int{
IntContainer ic = new IntContainer();
ic.set();
return ic.get();
}
}

0 comments on commit f508808

Please sign in to comment.