Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions run_contests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cd "$root_dir"

bash ./contest.sh test/examples/dispatch/basic.json
bash ./contest.sh test/examples/dispatch/neg.json
bash ./contest.sh test/examples/dispatch/context.json
bash ./contest.sh test/examples/dispatch/miniERC20.json
bash ./contest.sh test/examples/dispatch/Revert.json
bash ./contest.sh test/examples/dispatch/ownable.json
Expand Down
1 change: 1 addition & 0 deletions src/Solcore/Primitives/Primitives.hs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ yulPrimOps =
(Name "log4", monotype (funtype (words 6) unit)),
(Name "chainid", monotype word),
(Name "basefee", monotype word),
(Name "blobbasefee", monotype word),
(Name "origin", monotype word),
(Name "gasprice", monotype word),
(Name "blockhash", monotype (word :-> word)),
Expand Down
153 changes: 153 additions & 0 deletions std/std.solc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export {
bytes32(*),
bandWord,
borWord,
block,
bxorWord,
bnotWord,
bshlWord,
Expand Down Expand Up @@ -84,6 +85,7 @@ export {
maxVal,
memberAccessBase,
memory(*),
msg,
memory_ref,
mload,
mstore,
Expand Down Expand Up @@ -119,6 +121,7 @@ export {
toWord,
to_bytes,
tobool,
tx,
uint256(*),
unimplemented,
zeroize_memory
Expand Down Expand Up @@ -788,6 +791,156 @@ forall t . instance calldata(t) : Typedef(word) {
}
}

forall t . class t:msg {
// Currently copies calldata into memory.
// Will change once calldata(bytes) is operational.
function calldata() -> memory(bytes);
Comment thread
DanielVF marked this conversation as resolved.
function sender() -> address;
function sig() -> bytes4;
function value() -> uint256;
}

forall t . default instance t:msg {
function calldata() -> memory(bytes) {
let size: word;
assembly {
size := calldatasize()
}
let rounded = round_up_to_mul_of_32(size);
let ptr = allocate_memory(32 + rounded);
mstore(ptr, size);
assembly {
Comment thread
DanielVF marked this conversation as resolved.
calldatacopy(add(ptr, 32), 0, size)
}
zeroize_memory(ptr + 32 + size, rounded - size);
return memory(ptr);
}

function sender() -> address {
let res: word;
assembly {
res := caller()
}
return address(res);
}

function sig() -> bytes4 {
let res: word;
assembly {
res := shr(224, calldataload(0))
}
return bytes4(res);
}

function value() -> uint256 {
let res: word;
assembly {
res := callvalue()
}
return uint256(res);
}
}

forall t . class t:block {
function basefee() -> uint256;
function blobbasefee() -> uint256;
function chainid() -> uint256;
function coinbase() -> address;
function gaslimit() -> uint256;
function number() -> uint256;
function prevrandao() -> uint256;
function timestamp() -> uint256;
}

forall t . default instance t:block {
function basefee() -> uint256 {
let res: word;
assembly {
res := basefee()
}
return uint256(res);
}

function blobbasefee() -> uint256 {
let res: word;
assembly {
res := blobbasefee()
}
return uint256(res);
}

function chainid() -> uint256 {
let res: word;
assembly {
res := chainid()
}
return uint256(res);
}

function coinbase() -> address {
let res: word;
assembly {
res := coinbase()
}
return address(res);
}

function gaslimit() -> uint256 {
let res: word;
assembly {
res := gaslimit()
}
return uint256(res);
}

function number() -> uint256 {
let res: word;
assembly {
res := number()
}
return uint256(res);
}

function prevrandao() -> uint256 {
let res: word;
assembly {
res := prevrandao()
}
return uint256(res);
}

function timestamp() -> uint256 {
let res: word;
assembly {
res := timestamp()
}
return uint256(res);
}
}

forall t . class t:tx {
function gasprice() -> uint256;
function origin() -> address;
}

forall t . default instance t:tx {
function gasprice() -> uint256 {
let res: word;
assembly {
res := gasprice()
}
return uint256(res);
}

function origin() -> address {
let res: word;
assembly {
res := origin()
}
return address(res);
}
}

data returndata(t) = returndata(word);
forall t . instance returndata(t) : Typedef(word) {
function abs(x: word) -> returndata(t) {
Expand Down
4 changes: 4 additions & 0 deletions test/Cases.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ dispatches =
"Files for dispatch cases"
[ runDispatchTest "basic.solc",
runDispatchTest "stringid.solc",
runDispatchTest "context.solc",
runDispatchTest "miniERC20.solc",
runDispatchTest "Revert.solc",
runDispatchTest "hashes.solc",
Expand Down Expand Up @@ -205,6 +206,9 @@ imports =
runImportSuccess "external_lib_main.solc",
runImportSuccess "external_lib_alias_main.solc",
runImportSuccess "import_std_minimal.solc",
runImportSuccess "std_context_select.solc",
runImportSuccess "std_context_wildcard.solc",
runImportFailure "std_context_data_fail.solc",
runImportSuccess "select_alias_item_ok.solc",
runImportSuccess "select_alias_multi_ok.solc",
runImportFailure "select_alias_tail_fail.solc",
Expand Down
14 changes: 3 additions & 11 deletions test/examples/cases/monomorphic-require.solc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This should trigger a warning and an error in the specialiser
// due to unability to resolve result type of require
import std.{uint256,lt,not,Eq,ne,Proxy,bytes4,string};
import std.{uint256,lt,not,Eq,ne,Proxy,address,bytes,bytes4,memory,string,msg};
import std.dispatch.{*};

forall a.
Expand All @@ -16,21 +16,13 @@ function require(cond: bool) -> () {
}
}

function callvalue() -> uint256 {
let res : word;
assembly {
res := callvalue()
}
return uint256(res);
}

contract Deposit {
public function deposit() -> () {
require(callvalue() != uint256(0));
require(msg.value() != uint256(0));
return ();
}

public function main() -> () {
deposit();
}
}
}
14 changes: 3 additions & 11 deletions test/examples/cases/polymorphic-require.solc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This should trigger a warning and an error in the specialiser
// due to unability to resolve result type of require
import std.{uint256,lt,not,Eq,ne,Proxy,bytes4,string};
import std.{uint256,lt,not,Eq,ne,Proxy,address,bytes,bytes4,memory,string,msg};
import std.dispatch.{*};

forall a.
Expand All @@ -12,21 +12,13 @@ function require(cond: bool) -> a {
}
}

function callvalue() -> uint256 {
let res : word;
assembly {
res := callvalue()
}
return uint256(res);
}

contract Deposit {
public function deposit() -> () {
require(callvalue() != uint256(0));
require(msg.value() != uint256(0));
return ();
}

public function main() -> () {
deposit();
}
}
}
5 changes: 1 addition & 4 deletions test/examples/cases/yul-deposit-example.solc
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import std.{*};

function deposit(pubkey: memory(string), withdrawal_credentials: memory(string), signature: memory(string), deposit_data_root: uint256) -> () {
let msg_value : uint256 = uint256(0);
assembly {
msg_value := callvalue()
}
let msg_value : uint256 = msg.value();
}

contract Foo {
Expand Down
Loading